mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
Add the Ara modelling aggregate root (ADR-0002): domain/property/ with PropertyIdentity, SiteNotes, Property, Properties. Property.source_path implements the two disjoint source paths + Recency Tie-Break (ADR-0001; survey wins on an equal date); effective_epc resolves to the surveyed data (Site Notes path) or the public EPC (epc_with_overlay path — Landlord Overrides overlay is a later slice). Pure dataclasses, no infrastructure imports. PropertyRepository port + PropertyPostgresRepository hydrate the aggregate whole from a defensive view of the FE-owned 'property' table (identity columns) plus the EPC slice via EpcRepository.get_for_property. Reads only from repos (ADR-0003). 8 domain + 1 hydration test; pyright strict clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
"""PropertyRepository hydrates the aggregate whole from the property row + EPC slice."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
from sqlalchemy import Engine
|
|
from sqlmodel import Session
|
|
|
|
from datatypes.epc.domain.mapper import EpcPropertyDataMapper
|
|
from infrastructure.postgres.property_table import PropertyRow
|
|
from repositories.epc.epc_postgres_repository import EpcPostgresRepository
|
|
from repositories.property.property_postgres_repository import (
|
|
PropertyPostgresRepository,
|
|
)
|
|
|
|
_JSON_SAMPLES = Path(__file__).resolve().parents[3] / "backend/epc_api/json_samples"
|
|
|
|
|
|
def test_get_hydrates_identity_and_epc_slice(db_engine: Engine) -> None:
|
|
# Arrange
|
|
raw: dict[str, Any] = json.loads(
|
|
(_JSON_SAMPLES / "RdSAP-Schema-21.0.0" / "epc.json").read_text()
|
|
)
|
|
epc = EpcPropertyDataMapper.from_api_response(raw)
|
|
with Session(db_engine) as session:
|
|
row = PropertyRow(
|
|
portfolio_id=7, postcode="A0 0AA", address="1 Some Street", uprn=12345
|
|
)
|
|
session.add(row)
|
|
session.commit()
|
|
property_id = row.id
|
|
assert property_id is not None
|
|
EpcPostgresRepository(session).save(epc, property_id=property_id)
|
|
session.commit()
|
|
|
|
# Act
|
|
with Session(db_engine) as session:
|
|
repo = PropertyPostgresRepository(session, EpcPostgresRepository(session))
|
|
prop = repo.get(property_id)
|
|
|
|
# Assert
|
|
assert prop.identity.portfolio_id == 7
|
|
assert prop.identity.uprn == 12345
|
|
assert prop.epc == epc
|
|
assert prop.source_path == "epc_with_overlay"
|
|
assert prop.effective_epc == epc
|