From 8a11de265f82192056ffbd462533452d72d479d8 Mon Sep 17 00:00:00 2001 From: Denys SAVCHENKO Date: Fri, 15 Nov 2024 17:03:33 +0100 Subject: [PATCH 1/2] encode optional parameter in payload --- oda_api/api.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/oda_api/api.py b/oda_api/api.py index 1c2b6f10..19dc8106 100644 --- a/oda_api/api.py +++ b/oda_api/api.py @@ -615,6 +615,8 @@ def parameters_dict_payload(self): for k, v in p.items(): if isinstance(v, (list, dict, set)) and (k not in ['catalog_selected_objects', 'selected_catalog', 'scw_list']): p[k] = json.dumps(v) + if v is None and k != 'token': + p[k] = '\x00' if self.is_submitted: return { @@ -922,7 +924,9 @@ def _decode_res_json(self, res): else: res = ast.literal_eval(str(res).replace('null', 'None')) + # what is it for? self.dig_list(res) + return res except Exception as e: From 44aa4198cdbcc63ed576cea0749ab2280c26a837 Mon Sep 17 00:00:00 2001 From: Denys SAVCHENKO Date: Wed, 4 Dec 2024 16:56:33 +0100 Subject: [PATCH 2/2] test optional parameter payload --- tests/test_basic.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/test_basic.py b/tests/test_basic.py index 06777b2f..051f621e 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -763,4 +763,14 @@ def test_structured_param_encoding(): assert payload['str_par'] == 'foo' assert payload['num_par'] == 4.5 assert payload['dic_par'] == '{"a": 4.6, "b": 3.4}' - assert payload['lst_par'] == '["spam", "ham"]' \ No newline at end of file + assert payload['lst_par'] == '["spam", "ham"]' + +def test_none_payload(): + disp = oda_api.api.DispatcherAPI(url='http://example.org/dispatcher') + disp.parameters_dict = { + 'optional_par': None, + } + + payload = disp.parameters_dict_payload + assert payload['optional_par'] == '\x00' + \ No newline at end of file