"""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( 5, longitude=-0.1, latitude=51.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 def test_get_many_returns_entry_for_every_requested_uprn(db_engine: Engine) -> None: """get_many reads many UPRNs in one query: stored UPRNs return their insights, unstored ones map to None, and every requested UPRN is present.""" # Arrange insights_10: dict[str, Any] = {"name": "buildings/A"} insights_20: dict[str, Any] = {"name": "buildings/B"} with Session(db_engine) as session: repo = SolarPostgresRepository(session) repo.save(10, longitude=-0.1, latitude=51.5, insights=insights_10) repo.save(20, longitude=-0.2, latitude=52.0, insights=insights_20) session.commit() # Act — 30 has no stored row with Session(db_engine) as session: loaded = SolarPostgresRepository(session).get_many([10, 20, 30]) # Assert assert loaded == {10: insights_10, 20: insights_20, 30: None}