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

Testing branch #19

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions test_Census21_CACD_Wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,49 @@
"""

from Census21_CACD_Wrapper import APIWrapper
import pytest


api = APIWrapper()

# Test checks that the test can accurately complete a simple request
def test_can_retrieve_usual_residents_sex_EW():
api = APIWrapper(logger=False)
res = api.query_api('UR',f'sex',f'nat').iloc[0]['count']
assert res == 30420202 # The number of female respondents in England & Wales
res = api.query_api('UR','sex','nat').iloc[0]['count']
assert res == 30420202 # The number of female respondents in England & Wales

#Testing a batch of possible https response codes.
#This should ensure that the API wrapper only processes sucessful responses (200-299)
class Response:
def __init__(self, status_code):
self.status_code = status_code

test_response1 = Response(120)
test_response2 = Response(200)
test_response3 = Response(298)
test_response4 = Response(301)
test_response5 = Response(445)
test_response6 = Response(586)

response_value_test_cases = [
(test_response1, False),
(test_response2, True),
(test_response3, True),
(test_response4, False),
(test_response5, False),
(test_response6, False)
]

@pytest.mark.parametrize("response_value, expected_outcome", response_value_test_cases)
def test_valid_status_code(response_value, expected_outcome):
assert api._valid_status_code(response_value) == expected_outcome

# Trying to ensure that no errors are sneaking into the pop codes list undetected.

def test_no_errors_in_pop_codes():
api.set_population_types_available()
assert 'errors' not in api._valid_pop_types

def test_get_responds_to_error_correctly():
api.get('https://api.beta.ons.gov.uk/')
assert api._current_data != None