Skip to content

Commit

Permalink
Correct handling of include values, updating tests
Browse files Browse the repository at this point in the history
This is according to the discussion in issue
Materials-Consortia/OPTIMADE#259
  • Loading branch information
CasperWA committed Mar 4, 2020
1 parent e80daf5 commit 7ad0c7b
Showing 1 changed file with 14 additions and 54 deletions.
68 changes: 14 additions & 54 deletions tests/server/test_query_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,9 @@ def test_default_value(self):
expected_reference_ids = ["dijkstra1968", "maddox1988", "dummy/2019"]
self.check_response(request, expected_types, expected_reference_ids)

request = "/structures?include="
self.check_response(request, expected_types, expected_reference_ids)

# Single entry
request = "/structures/mpf_1"
expected_types = ["references"]
expected_reference_ids = ["dijkstra1968"]
self.check_response(request, expected_types, expected_reference_ids)

request = "/structures/mpf_1?include="
self.check_response(request, expected_types, expected_reference_ids)

def test_empty_value(self):
"""An empty value should resolve in no relationships being returned under `included`"""
request = '/structures?include=""'
request = "/structures?include="
expected_types = []
expected_reference_ids = []
expected_data_relationship_types = ["references"]
Expand All @@ -140,31 +128,6 @@ def test_empty_value(self):
expected_data_relationship_types,
)

request = "/structures?include=''"
self.check_response(
request,
expected_types,
expected_reference_ids,
expected_data_relationship_types,
)

# Single entry
request = "/structures/mpf_1?include=''"
self.check_response(
request,
expected_types,
expected_reference_ids,
expected_data_relationship_types,
)

request = "/structures/mpf_1?include=''"
self.check_response(
request,
expected_types,
expected_reference_ids,
expected_data_relationship_types,
)

def test_default_value_single_entry(self):
"""For single entry. Default value for `include` is 'references'"""
request = "/structures/mpf_1"
Expand All @@ -174,7 +137,7 @@ def test_default_value_single_entry(self):

def test_empty_value_single_entry(self):
"""For single entry. An empty value should resolve in no relationships being returned under `included`"""
request = '/structures/mpf_1?include=""'
request = "/structures/mpf_1?include="
expected_types = []
expected_reference_ids = []
expected_data_relationship_types = ["references"]
Expand All @@ -185,25 +148,22 @@ def test_empty_value_single_entry(self):
expected_data_relationship_types,
)

request = "/structures/mpf_1?include=''"
self.check_response(
request,
expected_types,
expected_reference_ids,
expected_data_relationship_types,
)

def test_wrong_relationship_type(self):
"""A wrong type should result in a `400 Bad Request` response"""
from optimade.server.routers import ENTRY_COLLECTIONS

wrong_type = "test"
request = f"/structures?include={wrong_type}"
error_detail = (
f"'{wrong_type}' cannot be identified as a valid relationship type. "
f"Known relationship types: {sorted(ENTRY_COLLECTIONS.keys())}"
)
self.check_error_response(request, expected_detail=error_detail)
for wrong_type in ("test", '""', "''"):
request = f"/structures?include={wrong_type}"
error_detail = (
f"'{wrong_type}' cannot be identified as a valid relationship type. "
f"Known relationship types: {sorted(ENTRY_COLLECTIONS.keys())}"
)
self.check_error_response(request, expected_detail=error_detail)

def test_wrong_html_form(self):
"""Using the parameter without equality sign `=` or values should result in a `400 Bad Request` response"""
request = "/structure?include"
self.check_error_response(request)


class ResponseFieldTests(SetClient, unittest.TestCase):
Expand Down

0 comments on commit 7ad0c7b

Please sign in to comment.