def test_it_warns_when_cant_load_database(self, mocker, mock_logger): MockReader = mocker.patch('normandy.recipes.geolocation.Reader') MockReader.side_effect = IOError() load_geoip_database() mock_logger.warning.assert_called_with( Whatever(), extra={'code': WARNING_CANNOT_LOAD_DATABASE})
def geolocation(): """Fixture to load geolocation data.""" geolocation_module.load_geoip_database() if geolocation_module.geoip_reader is None: skip_except_in_ci() else: return geolocation_module
def geolocation(): """Fixture to load geolocation data.""" geolocation_module.load_geoip_database() if geolocation_module.geoip_reader is None: pytest.skip() else: return geolocation_module
def test_it_warns_when_cant_load_database(self, mocker, mock_logger): MockReader = mocker.patch("normandy.recipes.geolocation.Reader") MockReader.side_effect = IOError() load_geoip_database() mock_logger.warning.assert_called_with( Whatever(), extra={"code": WARNING_CANNOT_LOAD_DATABASE} )
def geoip_db_is_available(app_configs, **kwargs): errors = [] if geolocation.geoip_reader is None: # try loading it geolocation.load_geoip_database() if geolocation.geoip_reader is None: errors.append(Error("GeoIP DB not available", id=ERROR_GEOIP_DB_NOT_AVAILABLE)) if not errors: # DB seems to be available, test a known value expected = "US" actual = geolocation.get_country_code("1.2.3.4") if actual != expected: errors.append( Error( f"GeoIP DB returned unexpected result. Expected {expected} got {actual}", id=ERROR_GEOIP_DB_UNEXPECTED_RESULT, ) ) return errors
def geoip_db_is_available(app_configs, **kwargs): errors = [] if geolocation.geoip_reader is None: # try loading it geolocation.load_geoip_database() if geolocation.geoip_reader is None: errors.append( Error("GeoIP DB not available", id=ERROR_GEOIP_DB_NOT_AVAILABLE)) if not errors: # DB seems to be available, try and do a lookup that should resolve to # some country. The specific country isn't important. ip = "1.2.3.4" country = geolocation.get_country_code(ip) if country is None: errors.append( Error(f"GeoIP DB returned no country for {ip!r}", id=ERROR_GEOIP_DB_UNEXPECTED_RESULT)) return errors
def ready(self): checks.register() load_geoip_database()
def ready(self): checks.register() RemoteSettings().check_config() load_geoip_database()