From 22bd0eadbe1bc8cf47c5a06d734eed0ca63fe520 Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Wed, 15 Jul 2026 09:33:28 +0000 Subject: [PATCH] =?UTF-8?q?Use=20the=20fetched=20gov=20cert=20when=20it=20?= =?UTF-8?q?is=20the=20newer=20assessment=20=F0=9F=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- tests/applications/modelling_e2e/test_handler.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/applications/modelling_e2e/test_handler.py b/tests/applications/modelling_e2e/test_handler.py index e2396e0c9..18a887864 100644 --- a/tests/applications/modelling_e2e/test_handler.py +++ b/tests/applications/modelling_e2e/test_handler.py @@ -1442,6 +1442,22 @@ def test_stored_survey_newer_than_gov_cert_wins_the_tie_break() -> None: assert chosen_is_fetched is False +def test_gov_cert_newer_than_stored_survey_wins_and_is_flagged_for_saving() -> None: + """A genuinely fresher gov cert still wins, and is flagged new so it persists.""" + # Arrange + from applications.modelling_e2e.handler import _newer_lodged + + stored = _lodged_epc("2023-12-01") + fetched = _lodged_epc("2026-05-01") + + # Act + chosen, chosen_is_fetched = _newer_lodged(stored, fetched) + + # Assert + assert chosen is fetched + assert chosen_is_fetched is True + + 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."""