From 04f72e2d320dfc3fa1bb8e4258e743264dcb1b85 Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Wed, 15 Jul 2026 09:36:21 +0000 Subject: [PATCH] =?UTF-8?q?Keep=20the=20stored=20survey=20when=20the=20reg?= =?UTF-8?q?ister=20has=20no=20cert=20or=20ties=20on=20date=20=F0=9F=9F=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- .../modelling_e2e/test_handler.py | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/applications/modelling_e2e/test_handler.py b/tests/applications/modelling_e2e/test_handler.py index eb3e943c6..88374a5d9 100644 --- a/tests/applications/modelling_e2e/test_handler.py +++ b/tests/applications/modelling_e2e/test_handler.py @@ -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."""