Ejemplo n.º 1
0
    def test_iplookup_malformed(self, mock_urlopen):
        from app.geo.lookup import iplookup, GEO_IP_SERVICE

        mock_urlopen().read.return_value = """<!DOCTYPE html><html></html>"""

        self.assertEqual(iplookup(TEST_IP), {})

        mock_urlopen.assert_called_with(GEO_IP_SERVICE.format(ip=TEST_IP))
Ejemplo n.º 2
0
    def test_iplookup_valid(self, mock_urlopen):
        from app.geo.lookup import iplookup, GEO_IP_SERVICE

        mock_urlopen().read.return_value = json.dumps(TEST_IP_RESPONSE)

        self.assertEqual(iplookup(TEST_IP)['city'], TEST_IP_RESPONSE['city'])

        mock_urlopen.assert_called_with(GEO_IP_SERVICE.format(ip=TEST_IP))
Ejemplo n.º 3
0
    def test_iplookup_malformed(self, mock_urlopen):
        from app.geo.lookup import iplookup, GEO_IP_SERVICE

        mock_urlopen().read.return_value = """<!DOCTYPE html><html></html>"""

        self.assertEqual(iplookup(TEST_IP), {})

        mock_urlopen.assert_called_with(GEO_IP_SERVICE.format(ip=TEST_IP))
Ejemplo n.º 4
0
    def test_iplookup_valid(self, mock_urlopen):
        from app.geo.lookup import iplookup, GEO_IP_SERVICE

        mock_urlopen().read.return_value = json.dumps(TEST_IP_RESPONSE)

        self.assertEqual(iplookup(TEST_IP)["city"], TEST_IP_RESPONSE["city"])

        mock_urlopen.assert_called_with(GEO_IP_SERVICE.format(ip=TEST_IP))
Ejemplo n.º 5
0
    def test_iplookup_service_unavailable(self, mock_urlopen):
        from app.geo.lookup import iplookup, GEO_IP_SERVICE
        from urllib2 import HTTPError

        mock_urlopen().read.side_effect = HTTPError("-1", 500, None, None, None)

        self.assertEqual(iplookup(TEST_IP), {})

        mock_urlopen.assert_called_with(GEO_IP_SERVICE.format(ip=TEST_IP))
Ejemplo n.º 6
0
    def test_iplookup_invalid(self, mock_urlopen):
        from app.geo.lookup import iplookup, GEO_IP_SERVICE
        from urllib2 import HTTPError

        mock_urlopen().read.side_effect = HTTPError("-1", 404, None, None, None)

        self.assertEqual(iplookup("-1"), {})

        mock_urlopen.assert_called_with(GEO_IP_SERVICE.format(ip="-1"))
Ejemplo n.º 7
0
    def test_iplookup_service_unavailable(self, mock_urlopen):
        from app.geo.lookup import iplookup, GEO_IP_SERVICE
        from urllib2 import HTTPError

        mock_urlopen().read.side_effect = HTTPError('-1', 500, None, None,
                                                    None)

        self.assertEqual(iplookup(TEST_IP), {})

        mock_urlopen.assert_called_with(GEO_IP_SERVICE.format(ip=TEST_IP))
Ejemplo n.º 8
0
    def test_iplookup_invalid(self, mock_urlopen):
        from app.geo.lookup import iplookup, GEO_IP_SERVICE
        from urllib2 import HTTPError

        mock_urlopen().read.side_effect = HTTPError('-1', 404, None, None,
                                                    None)

        self.assertEqual(iplookup('-1'), {})

        mock_urlopen.assert_called_with(GEO_IP_SERVICE.format(ip='-1'))