[tests] fix tests so the data is sent in json

This commit is contained in:
Maxime Alves LIRMM 2023-02-21 19:23:23 +01:00
parent dd83a337e9
commit b7c5704c95
3 changed files with 12 additions and 7 deletions

View File

@ -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))

View File

@ -47,7 +47,8 @@ ACLS = {
'foo', 'baz'
},
'optional': {
'truebidoo'
'truebidoo',
'z'
}
}
},

View File

@ -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}