A new default plan demotes the prior default across scenarios 🟥

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Khalim Conn-Kowlessar 2026-07-07 16:41:48 +00:00
parent 0eaf6fa99c
commit aa94e76d3d

View file

@ -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