Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for optional parameters #297

Merged
merged 5 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions oda_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)

dsavchenko marked this conversation as resolved.
Show resolved Hide resolved
return res
except Exception as e:

Expand Down
12 changes: 11 additions & 1 deletion tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]'
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'

Loading