def geocode(address, apikey=settings.CUBANE_GOOGLE_MAP_API_KEY, url='https://maps.googleapis.com/maps/api/geocode/json'): """ Make an API call to google's geocoding API and return the raw response as JSON based on the given human-readable address. """ response = wget(url, {'address': address, 'key': apikey}) if response.code == 200: return decode_json(response.data) else: return None
def reverse_geocode(lat, lng, apikey=settings.CUBANE_GOOGLE_MAP_API_KEY, url='https://maps.googleapis.com/maps/api/geocode/json'): """ Make an API call to google's geocoding API and return the raw response as JSON based on the given latitude/longitude coordinates. """ response = wget(url, {'latlng': '%f,%f' % (lat, lng), 'key': apikey}) if response.code == 200: return decode_json(response.data) else: return None
def test_wget_404(self): response = wget('http://httpbin.org/404') self.assertEqual(response.code, 404)
def test_wget_with_args(self): response = wget('http://httpbin.org/get', {'foo': 'bar'}) j = json.loads(response.data) self.assertEqual(j.get('args').get('foo'), 'bar')
def test_wget_should_download_document(self): response = wget('http://httpbin.org/') self.assertEqual(response.code, 200) self.assertTrue('HTTP Request & Response Service' in response.data)