Пример #1
0
    def test_get_from_v2_postal_code(self, m):
        url = 'https://zip.getziptastic.com/v2/US/48867'
        m.get(url, text=compare_v2_json)
        postal_code = '48867'
        ziptastic = Ziptastic('')
        result = ziptastic.get_from_postal_code(postal_code)

        req = m.request_history[0]
        eq_(url, req.url)
        eq_(loads(compare_v2_json), result)
Пример #2
0
    def test_reverse_geocoding(self, m):
        latitude = '42.9934'
        longitude = '-84.1595'
        url = 'https://zip.getziptastic.com/v3/' + latitude + '/' + longitude

        m.get(url, text=compare_v3_json)
        ziptastic = Ziptastic('abc123')
        result = ziptastic.get_from_coordinates(latitude, longitude)

        req = m.request_history[0]
        eq_(url, req.url)
        eq_(loads(compare_v3_json), result)
Пример #3
0
    def test_get_from_v3_postal_code(self):
        postal_code = "48867"
        Ziptastic.api_key = "abc123"
        result = Ziptastic.get_from_postal_code(postal_code)

        self.assertIn("postal_code", result[0])
        self.assertEqual("https://zip.getziptastic.com/v3/US/48867", self.urllib_mock.call_args[0][0].get_full_url())
Пример #4
0
    def test_get_from_v2_postal_code(self):
        self.setUpV3()

        postal_code = "48867"
        result = Ziptastic.get_from_postal_code(postal_code)

        self.assertIn("postal_code", result)
        self.assertEqual("https://zip.getziptastic.com/v2/US/48867", self.urllib_mock.call_args[0][0].get_full_url())
Пример #5
0
    def test_reverse_geocoding_api_key(self, m):
        latitude = '42.9934'
        longitude = '-84.1595'
        url = 'https://zip.getziptastic.com/v3/' + latitude + '/' + longitude

        m.get(url, text=compare_v3_json)
        ziptastic = Ziptastic('')
        self.assertRaises(ZiptasticAPIKeyRequiredException,
                          ziptastic.get_from_coordinates, latitude, longitude)
Пример #6
0
 def test_object_is_returned(self):
     result = Ziptastic.get_from_postal_code("48867")
     self.assertTrue(type(result), "object")
Пример #7
0
 def test_build_url(self):
     version = "v42"
     endpoint = "test.endpoint"
     correct_url = "https://test.endpoint/v42/"
     self.assertEquals(correct_url, Ziptastic.build_url(endpoint, version=version))
Пример #8
0
 def test_build_url(self):
     version = 'v42'
     endpoint = 'test.endpoint'
     correct_url = 'https://test.endpoint/v42'
     eq_(correct_url, Ziptastic.build_url(endpoint, version=version))