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]