From 14763638e20d74f48e49239ef687aa3e8e409b67 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Mon, 13 Jul 2026 23:27:39 +0000 Subject: [PATCH] =?UTF-8?q?Lock=20model-A=20scoping:=20exclude=20propertie?= =?UTF-8?q?s=20without=20a=20default=20plan=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) --- ...est_scenario_export_postgres_repository.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/repositories/scenario_export/test_scenario_export_postgres_repository.py b/tests/repositories/scenario_export/test_scenario_export_postgres_repository.py index 993e3dd42..68e3dfa8f 100644 --- a/tests/repositories/scenario_export/test_scenario_export_postgres_repository.py +++ b/tests/repositories/scenario_export/test_scenario_export_postgres_repository.py @@ -59,3 +59,35 @@ def test_returns_a_row_for_a_property_with_a_default_plan_under_the_scenario( assert row.uprn == "100023" assert row.post_sap_points == 78.0 assert row.cost_of_works == 4200.0 + + +def test_excludes_requested_properties_without_a_default_plan_under_the_scenario( + db_engine: Engine, +) -> None: + # arrange — four requested Properties: only #1 has a default Plan under + # scenario 5. #2 has a non-default Plan there, #3 a default Plan under a + # different scenario, #4 no Plan at all. + with Session(db_engine) as session: + for pid in (1, 2, 3, 4): + session.add( + PropertyRow(id=pid, portfolio_id=100, landlord_property_id=f"LP{pid}") + ) + session.add( + PlanModel(portfolio_id=100, property_id=1, scenario_id=5, is_default=True) + ) + session.add( + PlanModel(portfolio_id=100, property_id=2, scenario_id=5, is_default=False) + ) + session.add( + PlanModel(portfolio_id=100, property_id=3, scenario_id=9, is_default=True) + ) + session.commit() + + # act — request all four. + with Session(db_engine) as session: + rows = ScenarioExportPostgresRepository(session).rows_for( + portfolio_id=100, scenario_id=5, property_ids=[1, 2, 3, 4] + ) + + # assert — only #1 (a default Plan under scenario 5) survives (model A). + assert [r.property_id for r in rows] == [1]