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 3 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 @@
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'

Check warning on line 619 in oda_api/api.py

View check run for this annotation

Codecov / codecov/patch

oda_api/api.py#L618-L619

Added lines #L618 - L619 were not covered by tests

if self.is_submitted:
return {
Expand Down Expand Up @@ -922,7 +924,9 @@
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 @@
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"]'

Check warning on line 766 in tests/test_basic.py

View check run for this annotation

Codecov / codecov/patch

tests/test_basic.py#L766

Added line #L766 was not covered by tests

def test_none_payload():
disp = oda_api.api.DispatcherAPI(url='http://example.org/dispatcher')
disp.parameters_dict = {

Check warning on line 770 in tests/test_basic.py

View check run for this annotation

Codecov / codecov/patch

tests/test_basic.py#L769-L770

Added lines #L769 - L770 were not covered by tests
'optional_par': None,
}

payload = disp.parameters_dict_payload
assert payload['optional_par'] == '\x00'

Check warning on line 775 in tests/test_basic.py

View check run for this annotation

Codecov / codecov/patch

tests/test_basic.py#L774-L775

Added lines #L774 - L775 were not covered by tests

Loading