Skip to content

Commit

Permalink
Using new container with preloaded data
Browse files Browse the repository at this point in the history
Since the tests are passing, I decided to try out docker commit to further optimize test time. Depending on how long it takes to build the container, I might remove the dockerize functionality.

Also added some comments about what the tests do.
  • Loading branch information
nataliejschultz committed Sep 26, 2023
1 parent e941b5f commit 8377b59
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
26 changes: 11 additions & 15 deletions emission/individual_tests/TestNominatim.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,36 +41,39 @@
class NominatimTest(unittest.TestCase):
maxDiff = None

#basic query to check that nominatim and geofabrik are calling the same area.
#Basic query to check that nominatim and geofabrik are calling the same area.
def test_geofabrik_and_nominatim(self):
nominatim_result = requests.get(NOMINATIM_QUERY_URL + "/reverse?lat=41.8239891&lon=-71.4128343&format=json").json()
geofabrik_result = requests.get(GEOFABRIK_QUERY_URL + "/reverse?lat=41.8239891&lon=-71.4128343&format=json").json()
key_list = ['osm_id', 'boundingbox']
for k in key_list:
self.assertEqual(nominatim_result[k], geofabrik_result[k])

#checks the display name generated by get_filtered place in clean_and_resample.py, which creates a cleaned place from the fake place
# and reverse geocodes with the coordinates.
#Checks the display name generated by get_filtered_place in clean_and_resample.py, which creates a cleaned place from the fake place
# and reverse geocodes with the coordinates.
def test_get_filtered_place(self):
raw_result = ecww.WrapperBase.__getattr__(clean.get_filtered_place(fake_place), "data")
print(NOMINATIM_QUERY_URL)
actual_result = ecww.WrapperBase.__getattr__(raw_result, "display_name")
expected_result = "Dorrance Street, Providence"
self.assertEqual(expected_result, actual_result)

#Testing make_url_geo, which creates a query URL from the input string.
def test_make_url_geo(self):
expected_result = NOMINATIM_QUERY_URL + "/search?q=Providence%2C+Rhode+Island&format=json"
actual_result = eco.Geocoder.make_url_geo("Providence, Rhode Island")
self.assertEqual(expected_result, actual_result)

#we ignore the place_id because it is an internal Nominatim identifier
#Testing get_json_geo, which passes in an address as a query. Compares three select k,v pairs in the results.
def test_get_json_geo(self):
expected_result = {'place_id': 132490, 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright', 'osm_type': 'way', 'osm_id': 141567710, 'boundingbox': ['41.8325787', '41.8332278', '-71.4161848', '-71.4152064'], 'lat': '41.8330097', 'lon': '-71.41568124868104', 'display_name': 'State of Rhode Island Department of Administration, 1, Park Street, Downtown, Providence, Providence County, 02908, United States', 'class': 'building', 'type': 'civic', 'importance': 1.75001}
actual_result = eco.Geocoder.get_json_geo("State of Rhode Island Department of Administration, 1, Park Street, Downtown, Providence, Providence County, 02908, United States")[0]
key_list = ['osm_id', 'boundingbox', 'display_name']
for k in key_list:
self.assertEqual(expected_result[k], actual_result[k])

#Testing the geocode function, which passes in an address and gets latitude and longitude.
# Test creates instance of coordinates using coordinate class. Getting lat and lon of the coordinate using get_lat and get_lon methods from the class.
def test_geocode(self):
expected_result_lon = Coordinate(41.8239891, -71.4128343).get_lon()
expected_result_lat = Coordinate(41.8239891, -71.4128343).get_lat()
Expand All @@ -80,38 +83,31 @@ def test_geocode(self):
self.assertEqual(expected_result_lon, actual_result_lon)
self.assertEqual(expected_result_lat, actual_result_lat)


#Testing make_url_reverse, which creates a query url from a lat and lon
def test_make_url_reverse(self):
expected_result = NOMINATIM_QUERY_URL + "/reverse?lat=41.8239891&lon=-71.4128343&format=json"
actual_result = (eco.Geocoder.make_url_reverse(41.8239891, -71.4128343))
self.assertEqual(expected_result, actual_result)

#tested result was modified to only look at the name returned with the coordinates, rather than the entire dictionary.
#Testing get_json_reverse, which reverse geocodes from a lat and lon. Tested result was modified to only look at the name returned with the coordinates, rather than the entire dictionary.
def test_get_json_reverse(self):
expected_result = "Providence City Hall"
actual_result = eco.Geocoder.get_json_reverse(41.8239891, -71.4128343)["display_name"].split(",")[0]
self.assertEqual(expected_result, actual_result)

#Testing reverse_geocode, which reverse geocodes from a lat and lon and returns only the display name.
def test_reverse_geocode(self):
expected_result = "Portugal Parkway, Fox Point, Providence, Providence County, 02906, United States"
actual_result = eco.Geocoder.reverse_geocode(41.8174476, -71.3903767)
self.assertEqual(expected_result, actual_result)

#a hard-coded nominatim call to compare with our container.
#Compares the result of a hard-coded nominatim call with our container.
def test_nominatim_api(self):
nominatim_url = "http://nominatim.openstreetmap.org/reverse?lat=41.832942092439694&lon=-71.41558148857203&format=json"
nominatim_result_raw = requests.get(nominatim_url)
nominatim_result = nominatim_result_raw.json()['display_name'][0:70]
# NOMINATIM_QUERY_URL = eco.NOMINATIM_QUERY_URL
docker_result = eco.Geocoder.reverse_geocode(41.832942092439694, -71.41558148857203)[0:70]
print(docker_result)
print(nominatim_result)
self.assertEqual(nominatim_result, docker_result)

# def test_overpass_api(self):
# api = overpy.Overpass()
# result = api.query("""way["name"="Gielgenstraße"](50.7,7.1,50.8,7.25);out;""")


if __name__ == '__main__':
unittest.main()
6 changes: 1 addition & 5 deletions emission/integrationTests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,9 @@ services:
- emission
#adding section to incorporate nominatim server functionality
nominatim:
image: mediagis/nominatim:4.2
image: nataliejschultz/rhodeisland-image:sept25-2023
container_name: rhodeisland-nominatim
# command: "/app/start.sh"
environment:
- PBF_URL=https://download.geofabrik.de/north-america/us/rhode-island-latest.osm.pbf
- REPLICATION_URL=https://download.geofabrik.de/north-america/us/rhode-island-updates/
- IMPORT_WIKIPEDIA=false
ports:
- "8080:8080"
# healthcheck currently commented out, since it isn't necessary and keeps going the entire time the container is running.
Expand Down

0 comments on commit 8377b59

Please sign in to comment.