|
3 | 3 | from nose.tools import eq_ |
4 | 4 | from json import loads |
5 | 5 |
|
6 | | -from .ziptastic import Ziptastic |
| 6 | +from .ziptastic import Ziptastic, ZiptasticAPIKeyRequiredException |
7 | 7 |
|
8 | | -compare_v3_json = """[{"city": "Owosso", "country": "US", |
9 | | - "county": "Shiawassee", "state": "Michigan", "state_short": "MI", |
10 | | - "postal_code": "48867"}]""" |
| 8 | +compare_v3_json = """[{"city": "Owosso", "geohash": "dpshsfsytw8k", |
| 9 | + "country": "US", "county": "Shiawassee", "state": "Michigan", |
| 10 | + "state_short": "MI", "postal_code": "48867", "latitude": 42.9934, |
| 11 | + "longitude": -84.1595, "timezone": "America/Detroit"}]""" |
11 | 12 |
|
12 | 13 | compare_v2_json = """{"city": "Owosso", "country": "US", |
13 | 14 | "county": "Shiawassee", "state": "Michigan", "state_short": "MI", |
@@ -40,6 +41,31 @@ def test_get_from_v2_postal_code(self, m): |
40 | 41 | eq_(url, req.url) |
41 | 42 | eq_(loads(compare_v2_json), result) |
42 | 43 |
|
| 44 | + @requests_mock.mock() |
| 45 | + def test_reverse_geocoding(self, m): |
| 46 | + latitude = '42.9934' |
| 47 | + longitude = '-84.1595' |
| 48 | + url = 'https://zip.getziptastic.com/v3/' + latitude + '/' + longitude |
| 49 | + |
| 50 | + m.get(url, text=compare_v3_json) |
| 51 | + ziptastic = Ziptastic('abc123') |
| 52 | + result = ziptastic.get_from_coordinates(latitude, longitude) |
| 53 | + |
| 54 | + req = m.request_history[0] |
| 55 | + eq_(url, req.url) |
| 56 | + eq_(loads(compare_v3_json), result) |
| 57 | + |
| 58 | + @requests_mock.mock() |
| 59 | + def test_reverse_geocoding_api_key(self, m): |
| 60 | + latitude = '42.9934' |
| 61 | + longitude = '-84.1595' |
| 62 | + url = 'https://zip.getziptastic.com/v3/' + latitude + '/' + longitude |
| 63 | + |
| 64 | + m.get(url, text=compare_v3_json) |
| 65 | + ziptastic = Ziptastic('') |
| 66 | + self.assertRaises(ZiptasticAPIKeyRequiredException, |
| 67 | + ziptastic.get_from_coordinates, latitude, longitude) |
| 68 | + |
43 | 69 | def test_build_url(self): |
44 | 70 | version = 'v42' |
45 | 71 | endpoint = 'test.endpoint' |
|
0 commit comments