From 89e9c962cbd61ba309c05c9033cd1e656553e02b Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Thu, 21 May 2026 15:52:21 +0000 Subject: [PATCH] =?UTF-8?q?GoogleSolarApiClient=20raises=20BuildingInsight?= =?UTF-8?q?sNotFoundError=20on=20404=20entity-not-found=20=F0=9F=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../solar/test_google_solar_api_client.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/infrastructure/solar/test_google_solar_api_client.py b/tests/infrastructure/solar/test_google_solar_api_client.py index 9a38e836..450113a7 100644 --- a/tests/infrastructure/solar/test_google_solar_api_client.py +++ b/tests/infrastructure/solar/test_google_solar_api_client.py @@ -58,3 +58,32 @@ def test_get_building_insights_retries_on_transient_error() -> None: # Assert assert result == payload assert mock_get.call_count == 2 + + +# --------------------------------------------------------------------------- +# Slice 3: 404 + entity-not-found raises BuildingInsightsNotFoundError +# --------------------------------------------------------------------------- + + +def test_get_building_insights_raises_on_entity_not_found() -> None: + # Arrange + client = GoogleSolarApiClient(api_key="test-key") + + not_found_response = MagicMock() + not_found_response.status_code = 404 + not_found_response.json.return_value = { + "error": {"message": GoogleSolarApiClient.ENTITY_NOT_FOUND_ERROR} + } + + http_error = requests.exceptions.HTTPError("404") + http_error.response = not_found_response + + with patch("requests.get") as mock_get: + mock_get.return_value.raise_for_status.side_effect = http_error + mock_get.return_value.response = not_found_response + + # Act / Assert + with pytest.raises(BuildingInsightsNotFoundError): + client.get_building_insights(longitude=-0.1278, latitude=51.5074) + + assert mock_get.call_count == 1