mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
from typing import Any
|
|
from unittest.mock import patch
|
|
|
|
from backend.apis.GoogleSolarApi import GoogleSolarApi
|
|
from infrastructure.solar.google_solar_api_client import (
|
|
BuildingInsightsNotFoundError,
|
|
GoogleSolarApiClient,
|
|
)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Slice 1: get_building_insights delegates to _solar_client
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
def test_get_building_insights_delegates_to_solar_client() -> None:
|
|
# Arrange
|
|
payload: dict[str, Any] = {"solarPotential": {"maxArrayPanelsCount": 20}}
|
|
with patch.object(GoogleSolarApiClient, "get_building_insights", return_value=payload):
|
|
api = GoogleSolarApi(api_key="test-key", solar_materials=[])
|
|
|
|
# Act
|
|
result = api.get_building_insights(longitude=-0.1278, latitude=51.5074)
|
|
|
|
# Assert
|
|
assert result == payload
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Slice 2: BuildingInsightsNotFoundError translates to sentinel dict
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
def test_get_building_insights_returns_sentinel_on_not_found() -> None:
|
|
# Arrange
|
|
with patch.object(
|
|
GoogleSolarApiClient,
|
|
"get_building_insights",
|
|
side_effect=BuildingInsightsNotFoundError,
|
|
):
|
|
api = GoogleSolarApi(api_key="test-key", solar_materials=[])
|
|
|
|
# Act
|
|
result = api.get_building_insights(longitude=-0.1278, latitude=51.5074)
|
|
|
|
# Assert
|
|
assert result == {"error": GoogleSolarApiClient.ENTITY_NOT_FOUND_ERROR}
|