Skip to content

Commit 0094afa

Browse files
authored
Support for optional parameters (#297)
* encode optional parameter in payload * test optional parameter payload
1 parent 2ec211c commit 0094afa

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

oda_api/api.py

+4
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,8 @@ def parameters_dict_payload(self):
615615
for k, v in p.items():
616616
if isinstance(v, (list, dict, set)) and (k not in ['catalog_selected_objects', 'selected_catalog', 'scw_list']):
617617
p[k] = json.dumps(v)
618+
if v is None and k != 'token':
619+
p[k] = '\x00'
618620

619621
if self.is_submitted:
620622
return {
@@ -922,7 +924,9 @@ def _decode_res_json(self, res):
922924
else:
923925
res = ast.literal_eval(str(res).replace('null', 'None'))
924926

927+
# what is it for?
925928
self.dig_list(res)
929+
926930
return res
927931
except Exception as e:
928932

tests/test_basic.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -763,4 +763,14 @@ def test_structured_param_encoding():
763763
assert payload['str_par'] == 'foo'
764764
assert payload['num_par'] == 4.5
765765
assert payload['dic_par'] == '{"a": 4.6, "b": 3.4}'
766-
assert payload['lst_par'] == '["spam", "ham"]'
766+
assert payload['lst_par'] == '["spam", "ham"]'
767+
768+
def test_none_payload():
769+
disp = oda_api.api.DispatcherAPI(url='http://example.org/dispatcher')
770+
disp.parameters_dict = {
771+
'optional_par': None,
772+
}
773+
774+
payload = disp.parameters_dict_payload
775+
assert payload['optional_par'] == '\x00'
776+

0 commit comments

Comments
 (0)