Skip to content

Commit

Permalink
Testing entrypoint
Browse files Browse the repository at this point in the history
Testing out new entrypoint. Also fixed some of the minor changes from Shankari's code review.
  • Loading branch information
nataliejschultz committed Sep 27, 2023
1 parent 90b7063 commit 5fbf161
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/nominatim-docker-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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


27 changes: 12 additions & 15 deletions emission/individual_tests/TestNominatim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)

Expand All @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion emission/integrationTests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 5fbf161

Please sign in to comment.