mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
GoogleSolarApiClient retries on transient HTTP errors 🟥
This commit is contained in:
parent
9e22a4237c
commit
7bc00fdac8
1 changed files with 27 additions and 0 deletions
|
|
@ -31,3 +31,30 @@ def test_get_building_insights_returns_parsed_json() -> None:
|
|||
# Assert
|
||||
assert result == payload
|
||||
mock_get.assert_called_once()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Slice 2: Transient HTTP errors trigger retries
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_get_building_insights_retries_on_transient_error() -> None:
|
||||
# Arrange
|
||||
client = GoogleSolarApiClient(api_key="test-key")
|
||||
payload: dict[str, Any] = {"solarPotential": {"maxArrayPanelsCount": 20}}
|
||||
|
||||
transient_error = requests.exceptions.ConnectionError("timeout")
|
||||
transient_error.response = None # type: ignore[attr-defined]
|
||||
|
||||
success_response = MagicMock()
|
||||
success_response.json.return_value = payload
|
||||
success_response.raise_for_status.return_value = None
|
||||
|
||||
with patch("requests.get", side_effect=[transient_error, success_response]) as mock_get:
|
||||
with patch("time.sleep"):
|
||||
# Act
|
||||
result = client.get_building_insights(longitude=-0.1278, latitude=51.5074)
|
||||
|
||||
# Assert
|
||||
assert result == payload
|
||||
assert mock_get.call_count == 2
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue