diff --git a/halfapi/lib/domain_middleware.py b/halfapi/lib/domain_middleware.py index 7da8bb7..dcc63ba 100644 --- a/halfapi/lib/domain_middleware.py +++ b/halfapi/lib/domain_middleware.py @@ -49,10 +49,10 @@ class DomainMiddleware(BaseHTTPMiddleware): if 'args' in request.scope: # Set the http headers "x-args-required" and "x-args-optional" - if 'required' in request.scope['args']: + if len(request.scope['args'].get('required', set())): response.headers['x-args-required'] = \ ','.join(request.scope['args']['required']) - if 'optional' in request.scope['args']: + if len(request.scope['args'].get('optional', set())): response.headers['x-args-optional'] = \ ','.join(request.scope['args']['optional']) diff --git a/tests/dummy_domain/__init__.py b/tests/dummy_domain/__init__.py index e69de29..7d55830 100644 --- a/tests/dummy_domain/__init__.py +++ b/tests/dummy_domain/__init__.py @@ -0,0 +1,5 @@ +ROUTES = { + '': { + 'SUBROUTES': ['async'] + } +} diff --git a/tests/dummy_domain/acl.py b/tests/dummy_domain/acl.py index 70fea86..b4826c9 100644 --- a/tests/dummy_domain/acl.py +++ b/tests/dummy_domain/acl.py @@ -1,8 +1,11 @@ +from halfapi.lib import acl +from halfapi.lib.acl import public from random import randint -public = lambda *args: True -random = lambda *args: randint(0,1) == 1 +def random(): + return randint(0,1) == 1 -denied = lambda *args: False +def denied(): + return False diff --git a/tests/dummy_domain/routers/arguments/__init__.py b/tests/dummy_domain/routers/arguments/__init__.py new file mode 100644 index 0000000..5ea8f53 --- /dev/null +++ b/tests/dummy_domain/routers/arguments/__init__.py @@ -0,0 +1,38 @@ +from ... import acl +from halfapi.logging import logger + +ACLS = { + 'GET' : [ + { + 'acl':acl.public, + 'args': { + 'required': { + 'foo', 'bar' + }, + 'optional': { + 'x' + } + } + + }, + { + 'acl':acl.random, + 'args': { + 'required': { + 'foo', 'baz' + }, + 'optional': { + 'truebidoo' + } + } + }, + ] +} + +def get(halfapi, data): + """ + description: + returns the configuration of the domain + """ + logger.error('%s', data['foo']) + return {'foo': data['foo'], 'bar': data['bar']} diff --git a/tests/dummy_domain/routers/async/__init__.py b/tests/dummy_domain/routers/async/__init__.py new file mode 100644 index 0000000..7313776 --- /dev/null +++ b/tests/dummy_domain/routers/async/__init__.py @@ -0,0 +1,51 @@ +from halfapi.lib.responses import ORJSONResponse +from ... import acl + +ROUTES = { + 'abc/alphabet/{test:uuid}': { + 'GET': [{'acl': acl.public}] + }, + 'abc/pinnochio': { + 'GET': [{'acl': acl.public}] + }, + 'config': { + 'GET': [{'acl': acl.public}] + }, + 'arguments': { + 'GET': [{ + 'acl': acl.public, + 'args': { + 'required': {'foo', 'bar'}, + 'optional': {} + } + }] + }, +} + +async def get_abc_alphabet_TEST(request, *args, **kwargs): + """ + description: Not implemented + """ + raise NotImplementedError + +async def get_abc_pinnochio(request, *args, **kwargs): + """ + description: Not implemented + """ + raise NotImplementedError + +async def get_config(request, *args, **kwargs): + """ + description: Not implemented + """ + raise NotImplementedError + +async def get_arguments(request, *args, **kwargs): + """ + description: Liste des datatypes. + """ + + return ORJSONResponse({ + 'foo': kwargs.get('foo'), + 'bar': kwargs.get('bar') + })