diff --git a/backend/apis/GoogleSolarApi.py b/backend/apis/GoogleSolarApi.py index 589d3a04..7c90307c 100644 --- a/backend/apis/GoogleSolarApi.py +++ b/backend/apis/GoogleSolarApi.py @@ -1,8 +1,6 @@ -import time -import requests import pandas as pd import numpy as np -from typing import List +from typing import Any, List from functools import lru_cache from sklearn.preprocessing import MinMaxScaler from tqdm import tqdm @@ -84,7 +82,7 @@ class GoogleSolarApi: self.allowed_segment_indices = None - def get_building_insights(self, longitude: float, latitude: float, required_quality: str = "MEDIUM") -> dict: + def get_building_insights(self, longitude: float, latitude: float, required_quality: str = "MEDIUM") -> dict[str, Any]: try: return self._solar_client.get_building_insights(longitude, latitude, required_quality) # type: ignore[arg-type] except BuildingInsightsNotFoundError: diff --git a/tests/infrastructure/solar/test_google_solar_api_wiring.py b/tests/infrastructure/solar/test_google_solar_api_wiring.py index 52618f9d..77988645 100644 --- a/tests/infrastructure/solar/test_google_solar_api_wiring.py +++ b/tests/infrastructure/solar/test_google_solar_api_wiring.py @@ -1,5 +1,5 @@ from typing import Any -from unittest.mock import MagicMock, patch +from unittest.mock import patch from backend.apis.GoogleSolarApi import GoogleSolarApi from infrastructure.solar.google_solar_api_client import ( @@ -24,3 +24,24 @@ def test_get_building_insights_delegates_to_solar_client() -> None: # 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}