mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-27 23:35:01 +00:00
49 lines
1.9 KiB
Python
49 lines
1.9 KiB
Python
"""ScenarioExportTasks property-id resolution (ADR-0065): an explicit
|
|
property_ids list overrides the filters; otherwise the shared Modelling Run
|
|
filter resolver (ADR-0056) resolves the portfolio's filtered set."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from sqlalchemy import Engine
|
|
from sqlmodel import Session
|
|
|
|
from backend.app.exports.export_tasks import ScenarioExportTasks
|
|
from backend.app.modelling.property_filters import PropertyGroupFilters
|
|
from infrastructure.postgres.property_table import PropertyRow # registers `property`
|
|
|
|
|
|
def test_explicit_property_ids_override_the_filters(db_engine: Engine) -> None:
|
|
# arrange — filters that match nothing, but an explicit hand-picked list.
|
|
with Session(db_engine) as session:
|
|
# act
|
|
result = ScenarioExportTasks(session).resolve_property_ids(
|
|
portfolio_id=100,
|
|
filters=PropertyGroupFilters(postcodes=["ZZ1 1ZZ"]),
|
|
property_ids=[3, 1, 2, 1],
|
|
)
|
|
|
|
# assert — the hand-picked ids win (deduplicated, sorted); filters ignored.
|
|
assert result == [1, 2, 3]
|
|
|
|
|
|
def test_resolves_from_filters_when_no_explicit_ids(db_engine: Engine) -> None:
|
|
# arrange — two properties in the portfolio, one matching the postcode filter.
|
|
with Session(db_engine) as session:
|
|
session.add(
|
|
PropertyRow(id=1, portfolio_id=100, postcode="AB1 2CD", landlord_property_id="LP1")
|
|
)
|
|
session.add(
|
|
PropertyRow(id=2, portfolio_id=100, postcode="XY9 9ZZ", landlord_property_id="LP2")
|
|
)
|
|
session.commit()
|
|
|
|
# act
|
|
with Session(db_engine) as session:
|
|
result = ScenarioExportTasks(session).resolve_property_ids(
|
|
portfolio_id=100,
|
|
filters=PropertyGroupFilters(postcodes=["AB1 2CD"]),
|
|
property_ids=[],
|
|
)
|
|
|
|
# assert — only the property matching the filter is resolved.
|
|
assert result == [1]
|