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

Adjusted check_response so it can also handle single entries. #1130

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions tests/server/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ def inner(
server: Union[str, OptimadeTestClient] = "regular",
):
response = get_good_response(request, server)

response_ids = [struct["id"] for struct in response["data"]]
if isinstance(response["data"], dict):
response_ids = [response["data"]["id"]]
else:
response_ids = [struct["id"] for struct in response["data"]]

if expected_return is None:
expected_return = len(expected_ids)
Expand Down
9 changes: 9 additions & 0 deletions tests/server/routers/test_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ def test_structures_endpoint_data(self):
assert "_exmpl_chemsys" in self.json_response["data"]["attributes"]


def test_check_response_single_structure(check_response):
"""Tests whether check_response also handles single endpoint queries correctly."""

test_id = "mpf_1"
expected_ids = ["mpf_1"]
request = f"/structures/{test_id}?response_fields=chemical_formula_reduced"
check_response(request, expected_ids=expected_ids)


class TestMissingSingleStructureEndpoint(RegularEndpointTests):
"""Tests for /structures/<entry_id> for unknown <entry_id>"""

Expand Down