diff --git a/ordigi/geolocation.py b/ordigi/geolocation.py index bfff590..caf6831 100644 --- a/ordigi/geolocation.py +++ b/ordigi/geolocation.py @@ -24,15 +24,7 @@ class GeoLocation: self.prefer_english_names = prefer_english_names self.timeout = timeout - def coordinates_by_name(self, name, db, timeout=options.default_timeout): - # Try to get cached location first - cached_coordinates = db.get_location_coordinates(name) - if cached_coordinates is not None: - return { - 'latitude': cached_coordinates[0], - 'longitude': cached_coordinates[1], - } - + def coordinates_by_name(self, name, timeout=options.default_timeout): # If the name is not cached then we go ahead with an API lookup geocoder = self.geocoder if geocoder == 'Nominatim': diff --git a/tests/test_geolocation.py b/tests/test_geolocation.py new file mode 100644 index 0000000..ad88e17 --- /dev/null +++ b/tests/test_geolocation.py @@ -0,0 +1,21 @@ +from ordigi.geolocation import GeoLocation +import pytest + +class TestGeoLocation: + + def setup_class(cls): + cls.loc = GeoLocation() + + def test_coordinates_by_name(self): + coordinates = self.loc.coordinates_by_name('Sunnyvale, CA') + assert coordinates['latitude'] == 37.3688301 + assert coordinates['longitude'] == -122.036349 + + def test_place_name(self): + place_name = self.loc.place_name(lat=37.368, lon=-122.03) + assert place_name['city'] == 'Sunnyvale', place_name + + # Invalid lat/lon + with pytest.warns(UserWarning): + place_name = self.loc.place_name(lat=999, lon=999) + assert place_name == {'default': None}, place_name