mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-30 13:10:47 +00:00
GoogleSolarApi translates BuildingInsightsNotFoundError to sentinel dict 🟩
This commit is contained in:
parent
855581c189
commit
b09ef8248e
2 changed files with 24 additions and 5 deletions
|
|
@ -1,8 +1,6 @@
|
||||||
import time
|
|
||||||
import requests
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from typing import List
|
from typing import Any, List
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from sklearn.preprocessing import MinMaxScaler
|
from sklearn.preprocessing import MinMaxScaler
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
|
@ -84,7 +82,7 @@ class GoogleSolarApi:
|
||||||
|
|
||||||
self.allowed_segment_indices = None
|
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:
|
try:
|
||||||
return self._solar_client.get_building_insights(longitude, latitude, required_quality) # type: ignore[arg-type]
|
return self._solar_client.get_building_insights(longitude, latitude, required_quality) # type: ignore[arg-type]
|
||||||
except BuildingInsightsNotFoundError:
|
except BuildingInsightsNotFoundError:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from backend.apis.GoogleSolarApi import GoogleSolarApi
|
from backend.apis.GoogleSolarApi import GoogleSolarApi
|
||||||
from infrastructure.solar.google_solar_api_client import (
|
from infrastructure.solar.google_solar_api_client import (
|
||||||
|
|
@ -24,3 +24,24 @@ def test_get_building_insights_delegates_to_solar_client() -> None:
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
assert result == payload
|
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}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue