mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
67 lines
1.9 KiB
Python
67 lines
1.9 KiB
Python
# tests/test_address_to_uprn_csv.py
|
|
|
|
import csv
|
|
import json
|
|
import pytest
|
|
from datetime import date
|
|
from pathlib import Path
|
|
from backend.address2UPRN.main import get_uprn
|
|
|
|
FIXTURE_PATH = Path(__file__).parent / "test_data.csv"
|
|
SIDECAR_PATH = Path(__file__).parent / "test_lodgement_dates.json"
|
|
NEW_API_CUTOFF = date(2012, 1, 1)
|
|
|
|
|
|
def _load_sidecar() -> dict:
|
|
if SIDECAR_PATH.exists():
|
|
return json.loads(SIDECAR_PATH.read_text())
|
|
return {}
|
|
|
|
|
|
def load_test_cases():
|
|
sidecar = _load_sidecar()
|
|
with open(FIXTURE_PATH, newline="", encoding="utf-8") as f:
|
|
reader = csv.DictReader(f)
|
|
cases = []
|
|
for row in reader:
|
|
key = f"{row['User Input']}|{row['Postcode']}"
|
|
entry = sidecar.get(key, {})
|
|
lodgement_date = entry.get("lodgement_date")
|
|
|
|
marks = []
|
|
if lodgement_date:
|
|
parsed = date.fromisoformat(lodgement_date[:10])
|
|
if parsed < NEW_API_CUTOFF:
|
|
marks.append(
|
|
pytest.mark.xfail(
|
|
reason=f"EPC lodged {lodgement_date} — predates new API coverage (Jan 2012)",
|
|
strict=False,
|
|
)
|
|
)
|
|
|
|
cases.append(
|
|
pytest.param(
|
|
row["User Input"],
|
|
row["Postcode"],
|
|
row["Manual UPRN Code"],
|
|
id=f'{row["User Input"]} [{row["Postcode"]}]',
|
|
marks=marks,
|
|
)
|
|
)
|
|
return cases
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"user_input,postcode,expected_uprn",
|
|
load_test_cases(),
|
|
)
|
|
def test_uprn_resolution_matches_manual(
|
|
user_input: str,
|
|
postcode: str,
|
|
expected_uprn: str,
|
|
):
|
|
uprn = get_uprn(user_input, postcode)
|
|
if uprn:
|
|
assert uprn == expected_uprn
|
|
else:
|
|
assert str(uprn) == expected_uprn
|