コード例 #1
0
    def test_it_logs_when_geoip_fails(self, geolocation, mocker, mock_logger):
        mock_reader = mocker.patch('normandy.recipes.geolocation.geoip_reader')
        mock_reader.country.side_effect = GeoIP2Error()

        assert geolocation.get_country_code('207.126.102.129') is None
        mock_logger.warning.assert_called_with(
            Whatever(), extra={'code': WARNING_UNKNOWN_GEOIP_ERROR})
コード例 #2
0
 def _handle_success(body: str, uri: str) -> Any:
     try:
         return json.loads(body)
     except ValueError as ex:
         raise GeoIP2Error(
             f"Received a 200 response for {uri}"
             " but could not decode the response as "
             "JSON: " + ", ".join(ex.args),
             200,
             uri,
         ) from ex