63 lines
2.3 KiB
Python
63 lines
2.3 KiB
Python
|
|
"""Unit tests for rec/districts.py and services/district_service.py."""
|
||
|
|
from rec.districts import get_districts, get_district_by_name
|
||
|
|
from services.district_service import get_all_districts, get_district_names, validate_districts
|
||
|
|
|
||
|
|
|
||
|
|
class TestGetDistricts:
|
||
|
|
def test_returns_non_empty_dict(self) -> None:
|
||
|
|
districts = get_districts()
|
||
|
|
assert isinstance(districts, dict)
|
||
|
|
assert len(districts) > 0
|
||
|
|
|
||
|
|
def test_values_start_with_region_prefix(self) -> None:
|
||
|
|
for name, region_id in get_districts().items():
|
||
|
|
assert region_id.startswith("REGION^"), (
|
||
|
|
f"District '{name}' has value '{region_id}' that doesn't start with REGION^"
|
||
|
|
)
|
||
|
|
|
||
|
|
def test_contains_expected_london_boroughs(self) -> None:
|
||
|
|
districts = get_districts()
|
||
|
|
for borough in ("Camden", "Westminster", "Hackney"):
|
||
|
|
assert borough in districts, f"Expected borough '{borough}' not found"
|
||
|
|
|
||
|
|
|
||
|
|
class TestGetDistrictByName:
|
||
|
|
def test_valid_name_returns_region_id(self) -> None:
|
||
|
|
result = get_district_by_name("Camden")
|
||
|
|
assert result == "REGION^93941"
|
||
|
|
|
||
|
|
def test_invalid_name_returns_none(self) -> None:
|
||
|
|
result = get_district_by_name("Nonexistent District")
|
||
|
|
assert result is None
|
||
|
|
|
||
|
|
|
||
|
|
class TestGetDistrictNames:
|
||
|
|
def test_returns_list_matching_dict_keys(self) -> None:
|
||
|
|
names = get_district_names()
|
||
|
|
assert isinstance(names, list)
|
||
|
|
assert names == list(get_districts().keys())
|
||
|
|
|
||
|
|
|
||
|
|
class TestGetAllDistricts:
|
||
|
|
def test_returns_same_as_get_districts(self) -> None:
|
||
|
|
assert get_all_districts() == get_districts()
|
||
|
|
|
||
|
|
|
||
|
|
class TestValidateDistricts:
|
||
|
|
def test_all_valid_returns_empty_list(self) -> None:
|
||
|
|
result = validate_districts(["Camden", "Westminster", "Hackney"])
|
||
|
|
assert result == []
|
||
|
|
|
||
|
|
def test_some_invalid_returns_invalid_ones(self) -> None:
|
||
|
|
result = validate_districts(["Camden", "Faketown", "Westminster", "Nowhere"])
|
||
|
|
assert result == ["Faketown", "Nowhere"]
|
||
|
|
|
||
|
|
def test_all_invalid_returns_all(self) -> None:
|
||
|
|
invalid = ["Faketown", "Nowhere", "Neverland"]
|
||
|
|
result = validate_districts(invalid)
|
||
|
|
assert result == invalid
|
||
|
|
|
||
|
|
def test_empty_list_returns_empty_list(self) -> None:
|
||
|
|
result = validate_districts([])
|
||
|
|
assert result == []
|