def test_geocode_location_with_no_cache(self, mock_geocode): mock_geocode.return_value = mocks.geocoder_multiple() l = Location(self._read_data()) loc = l._geocode(self.city) nt.ok_('as_string' in loc and 'location' in loc and 'options' in loc, 'Wrong keys') nt.ok_(len(loc['options']) == 2, 'Coordinate list not available')
def test_to_map(self, mock_geocode): mock_geocode.return_value = mocks.geocoder_multiple() l = Location(self._read_data()) map = l._to_map_all(l._locations[0]) # should be 4 for Dallas, Paris, New York # 6 for test geolocation, returns 2 locations for 3 cities nt.ok_(len(map) == 2, "Wrong length of the map")
def test_geocode_location_with_cache(self, mock_geocode): mock_geocode.return_value = mocks.geocoder_multiple() with patch('hniextract.cache.Cache') as MockCache: instance = MockCache.return_value instance.put.return_value = mocks.cache_put() instance.get.return_value = mocks.cache_get() with instance: l = Location(self._read_data(), instance) loc = l._geocode(self.city) nt.ok_(len(loc['location']) == 3, "Location doesn't have necesary components") nt.ok_(len(loc['options']) == 2, "Length of coordinate list not correct")
def test_geocode_all_cache(self, mock_geocode): mock_geocode.return_value = mocks.geocoder_multiple() with patch('hniextract.cache.Cache') as MockCache: instance = MockCache.return_value instance.put.return_value = mocks.cache_put() instance.get.return_value = mocks.cache_get() with instance: l = Location(self._read_data(), instance) locs = l._geocode_all(['Dallas', 'Paris', 'Las Vegas']) nt.ok_(len(locs) == 3, "Not enough locations found") nt.ok_(len(locs[1]['location']) == 3, "Location doesn't have necessary componenets") nt.ok_(len(locs[2]['options']) == 2, "Not enough guessed locations")