mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +00:00
An expired-source EPC occupies the predicted slot without stranding rows 🟥
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
d2d696a1c5
commit
592f924761
1 changed files with 44 additions and 0 deletions
|
|
@ -80,3 +80,47 @@ def test_a_lodged_only_property_has_no_predicted_epc(db_engine: Engine) -> None:
|
|||
repo = EpcPostgresRepository(session)
|
||||
assert repo.get_predicted_for_property(9) is None
|
||||
assert repo.get_for_property(9) == epc
|
||||
|
||||
|
||||
def test_an_expired_source_epc_lives_in_the_predicted_slot(db_engine: Engine) -> None:
|
||||
# Arrange — an Expired-Enhanced Prediction is persisted with source="expired"
|
||||
# (ADR-0054): enhanced by an expired historic observation, not totally
|
||||
# predicted — but it occupies the same predicted slot.
|
||||
epc = _epc()
|
||||
with Session(db_engine) as session:
|
||||
repo = EpcPostgresRepository(session)
|
||||
repo.save(epc, property_id=11, source="expired")
|
||||
session.commit()
|
||||
|
||||
# Act / Assert — readable through the predicted slot; the lodged slot is empty.
|
||||
with Session(db_engine) as session:
|
||||
repo = EpcPostgresRepository(session)
|
||||
assert repo.get_predicted_for_property(11) == epc
|
||||
assert repo.get_predicted_for_properties([11]) == {11: epc}
|
||||
assert repo.get_for_property(11) is None
|
||||
|
||||
|
||||
def test_saving_predicted_over_expired_replaces_the_slot_without_stranding(
|
||||
db_engine: Engine,
|
||||
) -> None:
|
||||
# Arrange — a re-ingestion can flip the slot's flavour (expired -> predicted
|
||||
# or back); the slot holds ONE row, never a stranded stale sibling.
|
||||
from sqlmodel import select
|
||||
|
||||
from infrastructure.postgres.epc_property_table import EpcPropertyModel
|
||||
|
||||
epc = _epc()
|
||||
with Session(db_engine) as session:
|
||||
repo = EpcPostgresRepository(session)
|
||||
repo.save(epc, property_id=13, source="expired")
|
||||
repo.save(epc, property_id=13, source="predicted")
|
||||
session.commit()
|
||||
|
||||
# Act
|
||||
with Session(db_engine) as session:
|
||||
rows = session.exec(
|
||||
select(EpcPropertyModel).where(EpcPropertyModel.property_id == 13)
|
||||
).all()
|
||||
|
||||
# Assert — exactly one slot row remains, the latest flavour.
|
||||
assert [r.source for r in rows] == ["predicted"]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue