Exemple #1
0
    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})
Exemple #2
0
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
Exemple #3
0
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
Exemple #4
0
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}
        )
Exemple #6
0
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
Exemple #7
0
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
Exemple #8
0
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
Exemple #9
0
 def ready(self):
     checks.register()
     load_geoip_database()
Exemple #10
0
 def ready(self):
     checks.register()
     RemoteSettings().check_config()
     load_geoip_database()