diff --git a/halfapi/lib/acl.py b/halfapi/lib/acl.py index 98194c3..660df02 100644 --- a/halfapi/lib/acl.py +++ b/halfapi/lib/acl.py @@ -51,14 +51,16 @@ def args_check(fct): # Check query param should not read the "args" return await fct(req, *args, **kwargs) + data_ = {} if req.method == 'GET': data_ = req.query_params - if req.method == 'POST': + if req.method in ['POST', 'PATCH', 'PUT', 'DELETE']: try: data_ = await req.json() except JSONDecodeError as exc: - data_ = {} + logger.debug('Posted data was not JSON') + pass def plural(array: list) -> str: return 's' if len(array) > 1 else '' diff --git a/tests/dummy_domain/routers/abc/alphabet/TEST_uuid/__init__.py b/tests/dummy_domain/routers/abc/alphabet/TEST_uuid/__init__.py index 64c08da..ece1fd2 100644 --- a/tests/dummy_domain/routers/abc/alphabet/TEST_uuid/__init__.py +++ b/tests/dummy_domain/routers/abc/alphabet/TEST_uuid/__init__.py @@ -3,7 +3,8 @@ ACLS = { 'GET': [{'acl':acl.public}], 'POST': [{'acl':acl.public}], 'PATCH': [{'acl':acl.public}], - 'PUT': [{'acl':acl.public}] + 'PUT': [{'acl':acl.public}], + 'DELETE': [{'acl':acl.public}] } def get(test): @@ -17,3 +18,6 @@ def patch(test): def put(test): return str(test) + +def delete(test): + return str(test) diff --git a/tests/test_dummy_project_router.py b/tests/test_dummy_project_router.py index ac77729..7dcb0eb 100644 --- a/tests/test_dummy_project_router.py +++ b/tests/test_dummy_project_router.py @@ -39,3 +39,12 @@ def test_get_route(dummy_project, application_domain, routers): if not path: raise Exception('No route generated') + + +def test_delete_route(dummy_project, application_domain, routers): + c = TestClient(application_domain) + from uuid import uuid4 + arg = str(uuid4()) + r = c.delete(f'/dummy_domain/abc/alphabet/{arg}') + assert r.status_code == 200 + assert r.json() == arg