Skip to content

Commit

Permalink
Merge pull request #60 from datasciencecampus/58-verification-example…
Browse files Browse the repository at this point in the history
…-test

Update example test following change to blocked pairs
  • Loading branch information
EdCussONS authored Feb 16, 2024
2 parents 1a425d0 + 7c3337e commit 4c4a150
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/census21api/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class CensusAPI:
"""A wrapper for the 2021 England and Wales Census API.
Parameters
----------
verify : bool
Expand All @@ -26,7 +26,6 @@ class CensusAPI:
def __init__(self, verify: bool = True) -> None:
self.verify: bool = verify


def _process_response(self, response: Response) -> JSONLike:
"""
Validate and extract data from a response.
Expand Down
35 changes: 33 additions & 2 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,46 @@


def test_issue_39_blocked_pairs():
"""https://github.com/datasciencecampus/census21api/issues/39"""
"""
https://github.com/datasciencecampus/census21api/issues/39
This test no longer works as is. See
`test_issue_39_blocked_pairs_gets_400_error` for an update to this
case. However, we keep this test for posterity, and test that it
**doesn't** work.
"""

population_type = "UR_HH"
area_type = "nat"
dimensions = ("economic_activity_status_12a", "industry_current_88a")

api = CensusAPI()

with pytest.warns(UserWarning) as w:
assert "blocked pair" not in w
table = api.query_table(population_type, area_type, dimensions)

assert table is None


def test_issue_39_blocked_pairs_gets_400_error():
"""
Originally, this was about catching blocked pairs.
See https://github.com/datasciencecampus/census21api/issues/39 for
details on the original issue.
As of 2024-02-16, it seems that blocked pairs now give a 400 error.
This test now checks for that.
"""

population_type = "UR_HH"
area_type = "nat"
dimensions = ("economic_activity_status_12a", "industry_current_88a")

api = CensusAPI()

with pytest.warns(UserWarning, match="blocked pair"):
with pytest.warns(UserWarning, match="Status code: 400"):
table = api.query_table(population_type, area_type, dimensions)

assert table is None
2 changes: 1 addition & 1 deletion tests/test_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

MOCK_URL = "mock://test.com/"


@given(st.booleans())
def test_init(verify: bool):
"""Test that the `CensusAPI` class can be instantiated correctly."""
Expand All @@ -34,7 +35,6 @@ def test_init(verify: bool):

assert isinstance(api, CensusAPI)
assert vars(api) == {"verify": verify}



@given(st.dictionaries(st.text(), st.text()))
Expand Down

0 comments on commit 4c4a150

Please sign in to comment.