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

Encode structured param #238

Merged
merged 4 commits into from
Feb 7, 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 @@ -612,6 +612,10 @@
'oda_api_version': __version__,
}

for k, v in p.items():
if isinstance(v, (list, dict, set)) and (k not in ['catalog_selected_objects', 'selected_catalog']):
p[k] = json.dumps(v)

Check warning on line 617 in oda_api/api.py

View check run for this annotation

Codecov / codecov/patch

oda_api/api.py#L615-L617

Added lines #L615 - L617 were not covered by tests

if self.is_submitted:
return {
**p,
Expand Down
17 changes: 16 additions & 1 deletion tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,4 +748,19 @@
encoded_token = jwt.encode(token_payload, secret_key, algorithm='HS256')
disp.token = encoded_token
with pytest.raises(oda_api.api.UnexpectedDispatcherStatusCode):
disp.get_product_description('empty', 'dummy')
disp.get_product_description('empty', 'dummy')

Check warning on line 751 in tests/test_basic.py

View check run for this annotation

Codecov / codecov/patch

tests/test_basic.py#L751

Added line #L751 was not covered by tests

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

Check warning on line 755 in tests/test_basic.py

View check run for this annotation

Codecov / codecov/patch

tests/test_basic.py#L754-L755

Added lines #L754 - L755 were not covered by tests
'str_par': 'foo',
'num_par': 4.5,
'dic_par': {'a': 4.6, 'b': 3.4},
'lst_par': ['spam', 'ham']
}

payload = disp.parameters_dict_payload
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"]'

Check warning on line 766 in tests/test_basic.py

View check run for this annotation

Codecov / codecov/patch

tests/test_basic.py#L762-L766

Added lines #L762 - L766 were not covered by tests
Loading