From b7c5704c95fa24fb44fd542eb8001101a9ea55c5 Mon Sep 17 00:00:00 2001 From: Maxime Alves LIRMM Date: Tue, 21 Feb 2023 19:23:23 +0100 Subject: [PATCH] [tests] fix tests so the data is sent in json --- halfapi/lib/domain.py | 1 + tests/dummy_domain/routers/arguments/__init__.py | 3 ++- tests/test_domain.py | 15 +++++++++------ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/halfapi/lib/domain.py b/halfapi/lib/domain.py index 6f8a7f5..ff1ad46 100644 --- a/halfapi/lib/domain.py +++ b/halfapi/lib/domain.py @@ -99,6 +99,7 @@ def route_decorator(fct: FunctionType) -> Coroutine: logger.debug('Return type {} (defaults: {})'.format(ret_type, fct_args_defaults_dict)) try: + logger.debug('FCT_ARGS***** %s', fct_args) if ret_type == 'json': return ORJSONResponse(fct(**fct_args)) diff --git a/tests/dummy_domain/routers/arguments/__init__.py b/tests/dummy_domain/routers/arguments/__init__.py index 1a999f2..a512a48 100644 --- a/tests/dummy_domain/routers/arguments/__init__.py +++ b/tests/dummy_domain/routers/arguments/__init__.py @@ -47,7 +47,8 @@ ACLS = { 'foo', 'baz' }, 'optional': { - 'truebidoo' + 'truebidoo', + 'z' } } }, diff --git a/tests/test_domain.py b/tests/test_domain.py index 08bb637..00b18ce 100644 --- a/tests/test_domain.py +++ b/tests/test_domain.py @@ -32,7 +32,7 @@ class TestDummyDomain(TestDomain): assert isinstance(res.content.decode(), str) assert res.headers['content-type'].split(';')[0] == 'text/html' - res = self.client.request('post', '/ret_type/h24/config', data={ + res = self.client.request('post', '/ret_type/h24/config', json={ 'trou': 'glet' }) assert res.status_code == 200 @@ -53,24 +53,27 @@ class TestDummyDomain(TestDomain): def test_arguments_post_routes(self): arg_dict = {} - res = self.client.request('post', '/arguments', data=arg_dict) + res = self.client.request('post', '/arguments', json=arg_dict) assert res.status_code == 400 arg_dict = {'foo': '1', 'bar': '3'} - res = self.client.request('post', '/arguments', data=arg_dict) + res = self.client.request('post', '/arguments', json=arg_dict) assert res.status_code == 400 arg_dict = {'foo': '1', 'baz': '3'} - res = self.client.request('post', '/arguments', data=arg_dict) + res = self.client.request('post', '/arguments', json=arg_dict) assert res.json() == arg_dict arg_dict = {'foo': '1', 'baz': '3', 'truebidoo': '4'} - res = self.client.request('post', '/arguments', data=arg_dict) + res = self.client.request('post', '/arguments', json=arg_dict) assert res.json() == arg_dict - res = self.client.request('post', '/arguments', data={ **arg_dict, 'y': '4'}) + res = self.client.request('post', '/arguments', json={ **arg_dict, 'y': '4'}) assert res.json() == arg_dict + + res = self.client.request('post', '/arguments', json={ **arg_dict, 'z': True}) + assert res.json() == {**arg_dict, 'z': True}