Skip to content

Commit

Permalink
Rename test classes to be discoverable
Browse files Browse the repository at this point in the history
Fix some structures tests.
  • Loading branch information
CasperWA committed Jun 2, 2020
1 parent 67131b9 commit ee6f895
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
2 changes: 1 addition & 1 deletion tests/server/routers/test_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions tests/server/routers/test_references.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
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/<entry_id>"""

test_id = "dijkstra1968"
request_str = f"/references/{test_id}"
response_cls = ReferenceResponseOne


class SingleReferenceEndpointTestsDifficult(EndpointTests):
class TestSingleReferenceEndpointDifficult(EndpointTests):
"""Tests for /references/<entry_id>,
where <entry_id> contains difficult characters"""

Expand All @@ -31,7 +31,7 @@ class SingleReferenceEndpointTestsDifficult(EndpointTests):
response_cls = ReferenceResponseOne


class MissingSingleReferenceEndpointTests(EndpointTests):
class TestMissingSingleReferenceEndpoint(EndpointTests):
"""Tests for /references/<entry_id> for unknown <entry_id>"""

test_id = "random_string_that_is_not_in_test_data"
Expand Down
37 changes: 22 additions & 15 deletions tests/server/routers/test_structures.py
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"]
Expand Down Expand Up @@ -53,10 +53,10 @@ def test_get_next_responses(self, client):
assert len(cursor) == id_


class SingleStructureEndpointTests(EndpointTests):
class TestSingleStructureEndpoint(EndpointTests):
"""Tests for /structures/<entry_id>"""

test_id = "mpf_1"
test_id = "1"
request_str = f"/structures/{test_id}"
response_cls = StructureResponseOne

Expand All @@ -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/<entry_id> for unknown <entry_id>"""

test_id = "mpf_random_string_that_is_not_in_test_data"
test_id = "0"
request_str = f"/structures/{test_id}"
response_cls = StructureResponseOne

Expand All @@ -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/<entry_id>, where <entry_id> has relationships"""

test_id = "mpf_1"
test_id = "1"
request_str = f"/structures/{test_id}"
response_cls = StructureResponseOne

Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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,
Expand Down

0 comments on commit ee6f895

Please sign in to comment.