From 5fbf1611288970dc5acc900385e18e9e920737a7 Mon Sep 17 00:00:00 2001 From: Natalie Schultz <90212258+nataliejschultz@users.noreply.github.com> Date: Wed, 27 Sep 2023 14:02:24 -0600 Subject: [PATCH] Testing entrypoint Testing out new entrypoint. Also fixed some of the minor changes from Shankari's code review. --- .github/workflows/nominatim-docker-test.yml | 3 ++- emission/individual_tests/TestNominatim.py | 27 +++++++++----------- emission/integrationTests/docker-compose.yml | 3 ++- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/.github/workflows/nominatim-docker-test.yml b/.github/workflows/nominatim-docker-test.yml index c968893b8..4c8fc3616 100644 --- a/.github/workflows/nominatim-docker-test.yml +++ b/.github/workflows/nominatim-docker-test.yml @@ -29,7 +29,8 @@ jobs: - name: Workflow test run: echo Smoke test - - name: Test nominatim + # Passes the geofabrik key into the docker-compose.yml file. + - name: Test nominatim.py run: GFBK_KEY=${{ secrets.GEOFABRIK_API }} docker-compose -f emission/integrationTests/docker-compose.yml up --exit-code-from web-server diff --git a/emission/individual_tests/TestNominatim.py b/emission/individual_tests/TestNominatim.py index 0f7367711..5de84751e 100644 --- a/emission/individual_tests/TestNominatim.py +++ b/emission/individual_tests/TestNominatim.py @@ -6,22 +6,19 @@ standard_library.install_aliases() from builtins import * import unittest -import unittest.mock as mock -# import overpy import os from emission.core.wrapper.trip_old import Coordinate import requests import emission.core.wrapper.entry as ecwe -import emission.core.wrapper.wrapperbase as ecww import emission.net.ext_service.geocoder.nominatim as eco import emission.analysis.intake.cleaning.clean_and_resample as clean -#temporarily sets NOMINATIM_QUERY_URL to the environment variable for testing. -NOMINATIM_QUERY_URL_env = os.environ.get("NOMINATIM_QUERY_URL") +#Sets OPENSTREETMAP_QUERY_URL to the environment variable. +OPENSTREETMAP_QUERY_URL_env = os.environ.get("OPENSTREETMAP_QUERY_URL") -NOMINATIM_QUERY_URL = ( - NOMINATIM_QUERY_URL_env if NOMINATIM_QUERY_URL_env is not None - else eco.NOMINATIM_QUERY_URL +OPENSTREETMAP_QUERY_URL = ( + OPENSTREETMAP_QUERY_URL_env if OPENSTREETMAP_QUERY_URL_env is not None + else eco.OPENSTREETMAP_QUERY_URL ) GFBK = os.environ.get("GFBK_KEY") @@ -43,24 +40,24 @@ class NominatimTest(unittest.TestCase): #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() + OPENSTREETMAP_result = requests.get(OPENSTREETMAP_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]) + self.assertEqual(OPENSTREETMAP_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. 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") + raw_result = ecwe.Entry.__getattr__(clean.get_filtered_place(fake_place), "data") + print(OPENSTREETMAP_QUERY_URL) + actual_result = ecwe.Entry.__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" + expected_result = OPENSTREETMAP_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) @@ -85,7 +82,7 @@ def test_geocode(self): #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" + expected_result = OPENSTREETMAP_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) diff --git a/emission/integrationTests/docker-compose.yml b/emission/integrationTests/docker-compose.yml index af5436c02..105c2b404 100644 --- a/emission/integrationTests/docker-compose.yml +++ b/emission/integrationTests/docker-compose.yml @@ -9,7 +9,7 @@ services: environment: - DB_HOST=db - WEB_SERVER_HOST=0.0.0.0 - - NOMINATIM_QUERY_URL=http://rhodeisland-nominatim:8080 + - OPENSTREETMAP_QUERY_URL=http://rhodeisland-nominatim:8080 - GFBK_KEY=$GFBK_KEY volumes: # specify the host directory where the source code should live @@ -39,6 +39,7 @@ services: - emission #adding section to incorporate nominatim server functionality nominatim: + entrypoint: /app/start.sh image: nataliejschultz/rhodeisland-image:test container_name: rhodeisland-nominatim ports: