mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
GoogleSolarApiClient fetches building insights from the Solar API 🟥
This commit is contained in:
parent
d5ac70947d
commit
fe463f7eea
4 changed files with 55 additions and 0 deletions
0
infrastructure/solar/__init__.py
Normal file
0
infrastructure/solar/__init__.py
Normal file
22
infrastructure/solar/google_solar_api_client.py
Normal file
22
infrastructure/solar/google_solar_api_client.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
from typing import Any, Literal
|
||||
|
||||
|
||||
class BuildingInsightsNotFoundError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class GoogleSolarApiClient:
|
||||
base_url: str = "https://solar.googleapis.com/v1"
|
||||
MAX_RETRIES: int = 5
|
||||
ENTITY_NOT_FOUND_ERROR: str = "Requested entity was not found."
|
||||
|
||||
def __init__(self, api_key: str) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
def get_building_insights(
|
||||
self,
|
||||
longitude: float,
|
||||
latitude: float,
|
||||
required_quality: Literal["HIGH", "MEDIUM", "LOW"] = "MEDIUM",
|
||||
) -> dict[str, Any]:
|
||||
raise NotImplementedError
|
||||
0
tests/infrastructure/solar/__init__.py
Normal file
0
tests/infrastructure/solar/__init__.py
Normal file
33
tests/infrastructure/solar/test_google_solar_api_client.py
Normal file
33
tests/infrastructure/solar/test_google_solar_api_client.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
from typing import Any
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
from infrastructure.solar.google_solar_api_client import (
|
||||
BuildingInsightsNotFoundError,
|
||||
GoogleSolarApiClient,
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Slice 1: Successful response returns parsed JSON
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_get_building_insights_returns_parsed_json() -> None:
|
||||
# Arrange
|
||||
client = GoogleSolarApiClient(api_key="test-key")
|
||||
payload: dict[str, Any] = {"solarPotential": {"maxArrayPanelsCount": 20}}
|
||||
mock_response = MagicMock()
|
||||
mock_response.json.return_value = payload
|
||||
|
||||
with patch("requests.get", return_value=mock_response) as mock_get:
|
||||
mock_response.raise_for_status.return_value = None
|
||||
|
||||
# Act
|
||||
result = client.get_building_insights(longitude=-0.1278, latitude=51.5074)
|
||||
|
||||
# Assert
|
||||
assert result == payload
|
||||
mock_get.assert_called_once()
|
||||
Loading…
Add table
Reference in a new issue