Exemplo n.º 1
0
    def test_fgip_raise(self, mock_get):
        """Test FedoraGeoIPProvider handling of exceptions"""
        task = GeolocationTask()

        mock_get.side_effect = RequestException
        with self.assertLogs(level="DEBUG") as logs:
            result = task._locate(GEOLOC_URL_FEDORA_GEOIP)
        assert isinstance(result, GeolocationData)

        assert result.is_empty()
        mock_get.assert_called_once()
        assert "RequestException" in "\n".join(logs.output)

        mock_get.reset_mock()

        # This is technically cheating, ValueError is expected to be raised elsewhere than the
        # request itself. But it's all wrapped in a single try....except block so it is a good
        # enough approximation.
        mock_get.side_effect = ValueError
        with self.assertLogs(level="DEBUG") as logs:
            result = task._locate(GEOLOC_URL_FEDORA_GEOIP)

        assert isinstance(result, GeolocationData)
        assert result.is_empty()
        mock_get.assert_called_once()
        assert "Unable to decode" in "\n".join(logs.output)
Exemplo n.º 2
0
    def test_fgip_emptydata(self, mock_get):
        """Test FedoraGeoIPProvider with empty data"""
        task = GeolocationTask()
        result = task._locate(GEOLOC_URL_FEDORA_GEOIP)

        assert isinstance(result, GeolocationData)
        assert result.is_empty()
        mock_get.assert_called_once()
Exemplo n.º 3
0
    def test_fgip_failure(self, mock_get):
        """Test FedoraGeoIPProvider with HTTP failure"""
        task = GeolocationTask()
        with self.assertLogs(level="DEBUG") as logs:
            result = task._locate(GEOLOC_URL_FEDORA_GEOIP)

        assert isinstance(result, GeolocationData)
        assert result.is_empty()
        mock_get.assert_called_once()
        assert "failed with status code: 503" in "\n".join(logs.output)
Exemplo n.º 4
0
    def test_fgip_bad_timezone(self, mock_get):
        """Test FedoraGeoIPProvider with bad time zone data"""
        task = GeolocationTask()
        result = task._locate(GEOLOC_URL_FEDORA_GEOIP)

        assert isinstance(result, GeolocationData)
        assert result.territory == "GB"
        assert result.timezone == "Europe/London"
        assert not result.is_empty()
        mock_get.assert_called_once()
Exemplo n.º 5
0
    def test_hip_success(self, mock_get):
        """Test HostipGeoIPProvider success"""
        task = GeolocationTask()
        result = task._locate(GEOLOC_URL_HOSTIP)

        assert isinstance(result, GeolocationData)
        assert result.territory == "GB"
        assert result.timezone == "Europe/London"
        assert not result.is_empty()
        mock_get.assert_called_once()