mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-19 17:03:02 +00:00
43 lines
1.2 KiB
Python
43 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(
|
|
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
|