-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Write a test for creating an instance * Create a file for the constants to live in * Remove mention of constant data from API * Add a workflow to check the constants every week * Format wrapper module * Format constants checker * Add documentation for logger parameter
- Loading branch information
1 parent
a7d79ab
commit 7fc4583
Showing
7 changed files
with
584 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: CI | ||
|
||
on: | ||
schedule: | ||
- cron: '0 0 * * 1' | ||
|
||
jobs: | ||
constants: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Python 3.11 | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.11" | ||
cache: "pip" | ||
|
||
- name: Update pip and install test dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install . | ||
- name: Run API constants checker | ||
run: | | ||
python check_api_constants.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
"""Script to check whether our constants for the API are up to date.""" | ||
|
||
import requests | ||
from centhesus import ( | ||
API_ROOT, | ||
AREA_TYPES_BY_POPULATION_TYPE, | ||
DIMENSIONS_BY_POPULATION_TYPE, | ||
POPULATION_TYPES, | ||
) | ||
|
||
|
||
def _check_population_types(): | ||
"""Check that we have all the population types.""" | ||
|
||
url = f"{API_ROOT}?limit=100" | ||
response = requests.get(url, verify=True) | ||
data = response.json() | ||
|
||
available_pop_types = set( | ||
item["name"] for item in data["items"] if item["type"] == "microdata" | ||
) | ||
|
||
assert available_pop_types == set(POPULATION_TYPES), "\n".join( | ||
( | ||
"Population types do not match.", | ||
f"Available: {', '.join(available_pop_types)}", | ||
f"Recorded: {', '.join(POPULATION_TYPES)}", | ||
) | ||
) | ||
|
||
print("✅ Population types up to date.") | ||
|
||
|
||
def _check_area_types_by_population_type(): | ||
"""Check that we have the area types for each population type.""" | ||
|
||
for pop_type in POPULATION_TYPES: | ||
url = "/".join((API_ROOT, pop_type, "area-types?limit=100")) | ||
response = requests.get(url, verify=True) | ||
data = response.json() | ||
|
||
available_area_types = set(item["id"] for item in data["items"]) | ||
recorded_area_types = AREA_TYPES_BY_POPULATION_TYPE[pop_type] | ||
|
||
assert available_area_types == set(recorded_area_types), "\n".join( | ||
( | ||
f"Area types for population type {pop_type} do not match.", | ||
f"Available: {', '.join(available_area_types)}", | ||
f"Recorded: {', '.join(recorded_area_types)}", | ||
) | ||
) | ||
|
||
print("✅ Area types by population type up to date.") | ||
|
||
|
||
def _check_dimensions_by_population_type(): | ||
"""Check that we have the dimensions for each population type.""" | ||
|
||
for pop_type in POPULATION_TYPES: | ||
url = "/".join((API_ROOT, pop_type, "dimensions?limit=500")) | ||
response = requests.get(url, verify=True) | ||
data = response.json() | ||
|
||
available_dimensions = set(item["id"] for item in data["items"]) | ||
recorded_dimensions = DIMENSIONS_BY_POPULATION_TYPE[pop_type] | ||
|
||
assert available_dimensions == set(recorded_dimensions), "\n".join( | ||
( | ||
f"Dimensions for population type {pop_type} do not match.", | ||
f"Available: {', '.join(available_dimensions)}", | ||
f"Recorded: {', '.join(recorded_dimensions)}", | ||
) | ||
) | ||
|
||
print("✅ Dimensions by population type up to date.") | ||
|
||
|
||
def main(): | ||
"""Check all the API constants.""" | ||
|
||
_check_population_types() | ||
_check_area_types_by_population_type() | ||
_check_dimensions_by_population_type() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
"""A Python wrapper for the England and Wales Census 2021 API.""" | ||
|
||
from . import constants | ||
from .interface import Interface | ||
from .wrapper import APIWrapper | ||
from .wrapper import CensusAPI | ||
|
||
__all__ = ["APIWrapper", "Interface"] | ||
__all__ = ["CensusAPI", "Interface", "constants"] |
Oops, something went wrong.