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