mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
Add epc_renewable_heat_incentive table (space_heating_kwh, water_heating_kwh + the three insulation-impact kWh fields), wired into EpcPostgresRepository save/get. This is the P0 gap: RenewableHeatIncentive carries the baseline space-heating/hot-water kWh that EPC Energy Derivation consumes. The round-trip test now asserts full deep-equality (dropped the renewable_heat_incentive exclusion) and passes for RdSAP 21.0.0 + 21.0.1. DB migration for the new table documented in docs/migrations/epc-property-round-trip-fidelity.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
"""Persistence round-trip fidelity for EPC Property Data (Slice 1, #1129).
|
|
|
|
The load-bearing risk of the ara_first_run rebuild: an EpcPropertyData mapped to
|
|
the epc_property tables, saved, reloaded and mapped back must reconstruct the
|
|
original object exactly. A failure here is either a missing column (a migration
|
|
the FE repo must make) or a mapper gap — either way we want it to fail loudly,
|
|
inside First Run, rather than be deferred to a later Refresh.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
import pytest
|
|
from sqlalchemy import Engine
|
|
from sqlmodel import Session
|
|
|
|
from datatypes.epc.domain.epc_property_data import EpcPropertyData
|
|
from datatypes.epc.domain.mapper import EpcPropertyDataMapper
|
|
from repositories.epc.epc_postgres_repository import EpcPostgresRepository
|
|
|
|
_JSON_SAMPLES = Path(__file__).resolve().parents[3] / "backend/epc_api/json_samples"
|
|
|
|
|
|
def _load_epc(schema_dir: str) -> EpcPropertyData:
|
|
raw: dict[str, Any] = json.loads(
|
|
(_JSON_SAMPLES / schema_dir / "epc.json").read_text()
|
|
)
|
|
return EpcPropertyDataMapper.from_api_response(raw)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"schema_dir",
|
|
["RdSAP-Schema-21.0.0", "RdSAP-Schema-21.0.1"],
|
|
)
|
|
def test_epc_property_data_round_trips(schema_dir: str, db_engine: Engine) -> None:
|
|
# Arrange
|
|
original = _load_epc(schema_dir)
|
|
|
|
# Act
|
|
with Session(db_engine) as session:
|
|
epc_property_id = EpcPostgresRepository(session).save(original)
|
|
session.commit()
|
|
with Session(db_engine) as session:
|
|
reloaded = EpcPostgresRepository(session).get(epc_property_id)
|
|
|
|
# Assert
|
|
assert reloaded == original
|