def geocode_item(item): newitem = item.copy() try: phid, place_of_work = item['phid'], item['place_of_work'] address = geocode.geocode_address(place_of_work) newitem['address'] = address except geocode.GeocodingError as e: logging.exception('Error geocoding phid=%s, place_of_work=%s : %s ' + \ '(geourl:[%s])', phid, place_of_work, e, e.url) newitem['address'] = None return newitem
def test_sample_data(self): nominatimdata = '[]' googledata = get_contents('geocode_google.json') # Consecutive calls will return results in order results = [StringIO(nominatimdata), StringIO(googledata)] def side_effect(*args): return results.pop(0) with patch('urllib2.urlopen', side_effect=side_effect) as mock: address = geocode.geocode_address('') assert address['canton'] == 'Canton of Fribourg' assert address['locality'] == 'Estavayer-le-Lac' assert address['latitude'] == 46.849340 assert address['longitude'] == 6.847530000000001 assert address['formatted_address'] == '1470 Estavayer-le-Lac, '\ 'Switzerland'