From ee6f895fec9b26f17bbfbfa81ae8f9b57de74061 Mon Sep 17 00:00:00 2001 From: Casper Welzel Andersen Date: Mon, 4 May 2020 20:58:12 +0200 Subject: [PATCH] Rename test classes to be discoverable Fix some structures tests. --- tests/server/routers/test_links.py | 2 +- tests/server/routers/test_references.py | 8 +++--- tests/server/routers/test_structures.py | 37 +++++++++++++++---------- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/tests/server/routers/test_links.py b/tests/server/routers/test_links.py index 7a3895c5..3db73962 100644 --- a/tests/server/routers/test_links.py +++ b/tests/server/routers/test_links.py @@ -6,7 +6,7 @@ @pytest.mark.skip("Links has not yet been implemented") -class LinksEndpointTests(EndpointTests): +class TestLinksEndpoint(EndpointTests): """Tests for /links""" request_str = "/links" diff --git a/tests/server/routers/test_references.py b/tests/server/routers/test_references.py index 2584bd81..c1d8601b 100644 --- a/tests/server/routers/test_references.py +++ b/tests/server/routers/test_references.py @@ -7,14 +7,14 @@ pytestmark = pytest.mark.skip("References has not yet been implemented") -class ReferencesEndpointTests(EndpointTests): +class TestReferencesEndpoint(EndpointTests): """Tests for /references""" request_str = "/references" response_cls = ReferenceResponseMany -class SingleReferenceEndpointTests(EndpointTests): +class TestSingleReferenceEndpoint(EndpointTests): """Tests for /references/""" test_id = "dijkstra1968" @@ -22,7 +22,7 @@ class SingleReferenceEndpointTests(EndpointTests): response_cls = ReferenceResponseOne -class SingleReferenceEndpointTestsDifficult(EndpointTests): +class TestSingleReferenceEndpointDifficult(EndpointTests): """Tests for /references/, where contains difficult characters""" @@ -31,7 +31,7 @@ class SingleReferenceEndpointTestsDifficult(EndpointTests): response_cls = ReferenceResponseOne -class MissingSingleReferenceEndpointTests(EndpointTests): +class TestMissingSingleReferenceEndpoint(EndpointTests): """Tests for /references/ for unknown """ test_id = "random_string_that_is_not_in_test_data" diff --git a/tests/server/routers/test_structures.py b/tests/server/routers/test_structures.py index 01c670f5..a5d6efcf 100644 --- a/tests/server/routers/test_structures.py +++ b/tests/server/routers/test_structures.py @@ -1,13 +1,16 @@ +import pytest + from optimade.models import ( StructureResponseMany, StructureResponseOne, ReferenceResource, ) +from optimade.server.config import CONFIG from ..utils import EndpointTests -class StructuresEndpointTests(EndpointTests): +class TestStructuresEndpoint(EndpointTests): """Tests for /structures""" request_str = "/structures" @@ -16,10 +19,7 @@ class StructuresEndpointTests(EndpointTests): def test_structures_endpoint_data(self): """Check known properties/attributes for successful response""" assert "data" in self.json_response - - # Should match page_limit in test_config.json - assert len(self.json_response["data"]) == 15 - + assert len(self.json_response["data"]) == CONFIG.page_limit assert "meta" in self.json_response assert self.json_response["meta"]["data_available"] == 1089 assert self.json_response["meta"]["more_data_available"] @@ -53,10 +53,10 @@ def test_get_next_responses(self, client): assert len(cursor) == id_ -class SingleStructureEndpointTests(EndpointTests): +class TestSingleStructureEndpoint(EndpointTests): """Tests for /structures/""" - test_id = "mpf_1" + test_id = "1" request_str = f"/structures/{test_id}" response_cls = StructureResponseOne @@ -66,13 +66,16 @@ def test_structures_endpoint_data(self): assert self.json_response["data"]["id"] == self.test_id assert self.json_response["data"]["type"] == "structures" assert "attributes" in self.json_response["data"] - assert "_exmpl_chemsys" in self.json_response["data"]["attributes"] + assert ( + f"_{CONFIG.provider.prefix}_{CONFIG.provider_fields['structures'][0]}" + in self.json_response["data"]["attributes"] + ) -class MissingSingleStructureEndpointTests(EndpointTests): +class TestMissingSingleStructureEndpoint(EndpointTests): """Tests for /structures/ for unknown """ - test_id = "mpf_random_string_that_is_not_in_test_data" + test_id = "0" request_str = f"/structures/{test_id}" response_cls = StructureResponseOne @@ -85,10 +88,11 @@ def test_structures_endpoint_data(self): assert not self.json_response["meta"]["more_data_available"] -class SingleStructureWithRelationshipsTests(EndpointTests): +@pytest.mark.skip("Relationships have not yet been implemented") +class TestSingleStructureWithRelationships(EndpointTests): """Tests for /structures/, where has relationships""" - test_id = "mpf_1" + test_id = "1" request_str = f"/structures/{test_id}" response_cls = StructureResponseOne @@ -110,7 +114,8 @@ def test_structures_endpoint_data(self): ReferenceResource(**self.json_response["included"][0]) -class MultiStructureWithSharedRelationshipsTests(EndpointTests): +@pytest.mark.skip("Relationships have not yet been implemented") +class TestMultiStructureWithSharedRelationships(EndpointTests): """Tests for /structures for entries with shared relationships""" request_str = "/structures?filter=id=mpf_1 OR id=mpf_2" @@ -126,7 +131,8 @@ def test_structures_endpoint_data(self): assert len(self.json_response["included"]) == 1 -class MultiStructureWithRelationshipsTests(EndpointTests): +@pytest.mark.skip("Relationships have not yet been implemented") +class TestMultiStructureWithRelationships(EndpointTests): """Tests for /structures for mixed entries with and without relationships""" request_str = "/structures?filter=id=mpf_1 OR id=mpf_23" @@ -141,7 +147,8 @@ def test_structures_endpoint_data(self): assert len(self.json_response["included"]) == 1 -class MultiStructureWithOverlappingRelationshipsTests(EndpointTests): +@pytest.mark.skip("Relationships have not yet been implemented") +class TestMultiStructureWithOverlappingRelationships(EndpointTests): """Tests for /structures with entries with overlapping relationships One entry has multiple relationships, another entry has other relationships,