Keep the stored survey when the register has no cert or ties on date 🟩

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Daniel Roth 2026-07-15 09:36:21 +00:00
parent aeae322a4e
commit 04f72e2d32

View file

@ -1473,6 +1473,52 @@ def test_gov_cert_is_used_when_nothing_is_stored() -> None:
assert chosen_is_fetched is True
def test_stored_survey_survives_a_gov_register_with_no_cert() -> None:
"""The second failure shape in #1589: recently-surveyed homes have no public
cert, and a None from the register must not wipe out the stored survey."""
# Arrange
from applications.modelling_e2e.handler import _newer_lodged
stored = _lodged_epc("2026-05-01")
# Act
chosen, chosen_is_fetched = _newer_lodged(stored, None)
# Assert
assert chosen is stored
assert chosen_is_fetched is False
def test_no_lodged_epc_from_either_source_defers_to_prediction() -> None:
"""Neither source has an assessment: the caller gets None and predicts."""
# Arrange
from applications.modelling_e2e.handler import _newer_lodged
# Act
chosen, chosen_is_fetched = _newer_lodged(None, None)
# Assert
assert chosen is None
assert chosen_is_fetched is False
def test_same_day_assessments_prefer_the_stored_survey() -> None:
"""Exact inspection_date tie: ADR-0001's "if we surveyed it, trust the
survey" breaks it for the stored side."""
# Arrange
from applications.modelling_e2e.handler import _newer_lodged
stored = _lodged_epc("2026-05-01")
fetched = _lodged_epc("2026-05-01")
# Act
chosen, chosen_is_fetched = _newer_lodged(stored, fetched)
# Assert
assert chosen is stored
assert chosen_is_fetched is False
def test_refetch_epc_false_with_stored_epc_skips_api_call() -> None:
"""refetch_epc=False + stored lodged EPC present: EpcClientService.get_by_uprn
is never called; the stored EPC is used and reaches run_modelling."""