Resolve a UPRN to its historic EPC record by exact match 🟥

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Khalim Conn-Kowlessar 2026-07-06 08:17:07 +00:00
parent 2788849e16
commit 4bbcdb6a61
2 changed files with 34 additions and 1 deletions

View file

@ -34,6 +34,10 @@ class HistoricEpcResolver:
matches=matches,
)
def record_for_uprn(self, uprn: str, postcode: str) -> Optional[HistoricEpc]:
"""The postcode shard's certificate for ``uprn``, or None."""
return None
def resolve_uprn(
self, user_address: str, postcode: str
) -> Optional[tuple[str, str, float]]:

View file

@ -16,10 +16,11 @@ from repositories.historic_epc.historic_epc_repository import HistoricEpcReposit
from repositories.historic_epc.historic_epc_resolver import HistoricEpcResolver
def _hist(address: str, uprn: str) -> HistoricEpc:
def _hist(address: str, uprn: str, lodgement_date: str = "") -> HistoricEpc:
fields = {f.name: "" for f in dataclasses.fields(HistoricEpc)}
fields["address"] = address
fields["uprn"] = uprn
fields["lodgement_date"] = lodgement_date
return HistoricEpc(**fields)
@ -101,6 +102,34 @@ def test_resolve_uprn_is_none_on_ambiguous_tie():
assert HistoricEpcResolver(repo).resolve_uprn("47 Gordon Road", "AB33 8AL") is None
def test_record_for_uprn_returns_the_exact_uprn_match():
# Arrange — the prediction path knows the target's UPRN; the lookup must be
# exact equality, never the fuzzy address matcher (ADR-0054).
repo = _FakeRepo(
{
"AB338AL": [
_hist("47 GORDON ROAD", "100"),
_hist("48 GORDON ROAD", "200"),
]
}
)
# Act
record = HistoricEpcResolver(repo).record_for_uprn("200", "AB33 8AL")
# Assert
assert record is not None
assert record.address == "48 GORDON ROAD"
def test_record_for_uprn_is_none_when_uprn_not_in_shard():
# Arrange
repo = _FakeRepo({"AB338AL": [_hist("47 GORDON ROAD", "100")]})
# Act / Assert — a miss is the normal outcome of a best-effort lookup.
assert HistoricEpcResolver(repo).record_for_uprn("999", "AB33 8AL") is None
def test_resolve_uprn_is_none_when_all_scores_zero():
# Arrange — no candidate shares the user's building number => all hard-zero.
repo = _FakeRepo(