Model/tests/domain/scenario_export/test_scenario_sheet.py
Khalim Conn-Kowlessar 1a0e87e593 Pivot a Property's measure cost onto its scenario-sheet column 🟥
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-13 23:08:26 +00:00

67 lines
2.1 KiB
Python

"""The Scenario Export sheet shape (ADR-0065) — pure layout of one scenario
sheet: measure costs pivoted onto a frozen column contract, savings summed per
Property, and the Plan's post-works figures."""
from typing import Optional, Sequence
from domain.scenario_export.scenario_sheet import (
ExportMeasure,
PropertyScenarioData,
shape_scenario_sheet,
)
def _measure(
*,
measure_type: str = "loft_insulation",
estimated_cost: Optional[float] = 1000.0,
sap_points: Optional[float] = None,
co2_equivalent_savings: Optional[float] = None,
kwh_savings: Optional[float] = None,
energy_cost_savings: Optional[float] = None,
includes_battery: bool = False,
) -> ExportMeasure:
return ExportMeasure(
measure_type=measure_type,
estimated_cost=estimated_cost,
sap_points=sap_points,
co2_equivalent_savings=co2_equivalent_savings,
kwh_savings=kwh_savings,
energy_cost_savings=energy_cost_savings,
includes_battery=includes_battery,
)
def _property(
*,
property_id: int = 1,
landlord_property_id: Optional[str] = "LP1",
measures: Sequence[ExportMeasure] = (),
**fields: object,
) -> PropertyScenarioData:
return PropertyScenarioData(
property_id=property_id,
landlord_property_id=landlord_property_id,
measures=measures,
**fields, # pyright: ignore[reportArgumentType]
)
def test_a_measures_cost_lands_in_its_own_column_with_the_property_identity() -> None:
# arrange — one Property with one loft-insulation measure priced at £1200.
prop = _property(
property_id=42,
landlord_property_id="LP42",
measures=[_measure(measure_type="loft_insulation", estimated_cost=1200.0)],
)
# act
sheet = shape_scenario_sheet([prop])
# assert — one row carrying the Property identity and the cost in the
# loft_insulation column.
assert len(sheet.rows) == 1
row = sheet.rows[0]
assert row["property_id"] == 42
assert row["landlord_property_id"] == "LP42"
assert row["loft_insulation"] == 1200.0