Model/tests/repositories/solar/test_solar_repository.py
Khalim Conn-Kowlessar caee4de2f4 feat(ingestion): relocate EpcClientService to infrastructure + SolarRepo (#1133)
Move the EpcClientService package (client + _retry + exceptions + tests) from
the dying backend/ tree to infrastructure/epc_client/ as the New-EPC-API Fetcher;
update the two callers (address2UPRN, a script). All 14 client tests pass.

Add SolarRepository port + SolarPostgresRepository persisting Google Solar
building insights as JSONB (solar_building_insights table), one row per Property.
The EPC repo half of this slice already landed in #1129. pyright strict clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-05-30 19:45:26 +00:00

41 lines
1.2 KiB
Python

"""SolarRepo round-trips Google Solar building insights for a Property."""
from __future__ import annotations
from typing import Any
from sqlalchemy import Engine
from sqlmodel import Session
from repositories.solar.solar_postgres_repository import SolarPostgresRepository
def test_building_insights_round_trip(db_engine: Engine) -> None:
# Arrange
insights: dict[str, Any] = {
"name": "buildings/ChIJ",
"solarPotential": {
"maxArrayPanelsCount": 42,
"panelCapacityWatts": 250.0,
"roofSegmentStats": [{"pitchDegrees": 30.0, "azimuthDegrees": 180.0}],
},
}
# Act
with Session(db_engine) as session:
SolarPostgresRepository(session).save(property_id=5, insights=insights)
session.commit()
with Session(db_engine) as session:
reloaded = SolarPostgresRepository(session).get(5)
# Assert
assert reloaded == insights
def test_get_returns_none_when_no_insights_stored(db_engine: Engine) -> None:
# Arrange / Act
with Session(db_engine) as session:
reloaded = SolarPostgresRepository(session).get(999)
# Assert
assert reloaded is None