From aa94e76d3d27d4ea62e0ef42af72828b7efe90f0 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Tue, 7 Jul 2026 16:41:48 +0000 Subject: [PATCH] =?UTF-8?q?A=20new=20default=20plan=20demotes=20the=20prio?= =?UTF-8?q?r=20default=20across=20scenarios=20=F0=9F=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5 --- .../plan/test_plan_postgres_repository.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/repositories/plan/test_plan_postgres_repository.py b/tests/repositories/plan/test_plan_postgres_repository.py index 2d3fb7473..7198a6926 100644 --- a/tests/repositories/plan/test_plan_postgres_repository.py +++ b/tests/repositories/plan/test_plan_postgres_repository.py @@ -227,3 +227,35 @@ def test_reports_which_properties_already_have_a_default_plan( # Assert — only the property with a default Plan is reported assert have_default == {20} + + +def test_a_new_default_demotes_the_prior_default_across_scenarios( + db_engine: Engine, +) -> None: + """One default Plan per property: a promoted first Plan (non-default + scenario) must lose the default when the default scenario's Plan lands — + readers filter portfolio + is_default only, never scenario (#1490).""" + # Arrange — the property's first Plan, promoted under non-default scenario 7 + with Session(db_engine) as session: + first_id = PlanPostgresRepository(session).save( + _plan(), property_id=30, scenario_id=7, portfolio_id=1, is_default=True + ) + session.commit() + + # Act — the default scenario (8) models the same property + with Session(db_engine) as session: + second_id = PlanPostgresRepository(session).save( + _plan(), property_id=30, scenario_id=8, portfolio_id=1, is_default=True + ) + session.commit() + + # Assert — exactly one default for the property, the newest plan + with Session(db_engine) as session: + plan_rows = session.exec( + select(PlanModel).where(col(PlanModel.property_id) == 30) + ).all() + by_id = {p.id: p for p in plan_rows} + + assert by_id[first_id].is_default is False # demoted across scenarios + assert by_id[second_id].is_default is True + assert sum(1 for p in plan_rows if p.is_default) == 1