From d31df8c00bc04610acbda9fa8c32354cbc41c6cc Mon Sep 17 00:00:00 2001 From: Natalie Schultz <90212258+nataliejschultz@users.noreply.github.com> Date: Wed, 11 Oct 2023 10:01:22 -0600 Subject: [PATCH] Cleanup (2) - Deleting createfakeplace.py and setup_integrationtests.sh - Reverting to setup_tests.sh in start_integration_tests.sh - Moving creation of fake place to TestNominatim.py setup function - Adding logging for query URL and modifying a print in nominatim.py --- bin/createfakeplace.py | 10 ---------- emission/individual_tests/TestNominatim.py | 16 +++++++++++----- .../integrationTests/start_integration_tests.sh | 2 +- emission/net/ext_service/geocoder/nominatim.py | 4 ++-- setup/setup_integrationtests.sh | 9 --------- 5 files changed, 14 insertions(+), 27 deletions(-) delete mode 100644 bin/createfakeplace.py delete mode 100644 setup/setup_integrationtests.sh diff --git a/bin/createfakeplace.py b/bin/createfakeplace.py deleted file mode 100644 index cfebb6a1c..000000000 --- a/bin/createfakeplace.py +++ /dev/null @@ -1,10 +0,0 @@ -import emission.core.wrapper.entry as ecwe - -#Creates a fake, cleaned place in Rhode Island for use in TestNominatim.py: -def create_fake_place(): - fake_id = "place_in_rhodeisland" - key = "segmentation/raw_place" - write_ts = 1694344333 - data = {'source': 'FakeTripGenerator','location': {'type': 'Point', 'coordinates': [-71.4128343, 41.8239891]}} - fake_place = ecwe.Entry.create_fake_entry(fake_id, key, data, write_ts) - return fake_place \ No newline at end of file diff --git a/emission/individual_tests/TestNominatim.py b/emission/individual_tests/TestNominatim.py index 22fb02fbb..fa51f239b 100644 --- a/emission/individual_tests/TestNominatim.py +++ b/emission/individual_tests/TestNominatim.py @@ -10,7 +10,7 @@ import os from emission.core.wrapper.trip_old import Coordinate import requests -import bin.createfakeplace as bc +import emission.core.wrapper.entry as ecwe import emission.analysis.intake.cleaning.clean_and_resample as clean import emission.net.ext_service.geocoder.nominatim as eco @@ -22,8 +22,14 @@ class NominatimTest(unittest.TestCase): maxDiff = None - def setUp(self) -> None: - return super().setUp() + def setUp(self): + #Creates a fake, cleaned place in Rhode Island + fake_id = "place_in_rhodeisland" + key = "segmentation/raw_place" + write_ts = 1694344333 + data = {'source': 'FakeTripGenerator','location': {'type': 'Point', 'coordinates': [-71.4128343, 41.8239891]}} + fake_place = ecwe.Entry.create_fake_entry(fake_id, key, data, write_ts) + return fake_place #When a nominatim service is called, we set the value of the NOMINATIM_QUERY_URL environment variable in nominatim.py and re-load the module. def nominatim(service): @@ -54,7 +60,7 @@ def test_geofabrik_and_nominatim(self): #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): - fake_place_raw = bc.create_fake_place() + fake_place_raw = self.setUp() fake_place_data = clean.get_filtered_place(fake_place_raw).__getattr__("data") actual_result = fake_place_data.__getattr__("display_name") expected_result = "Dorrance Street, Providence" @@ -72,7 +78,7 @@ def test_make_url_reverse(self): NominatimTest.nominatim("geofabrik") lat, lon = 41.8239891, -71.4128343 expected_result = GEOFABRIK_QUERY_URL + (f"/reverse?lat={lat}&lon={lon}&format=json") - actual_result = (eco.Geocoder.make_url_reverse(41.8239891, -71.4128343)) + actual_result = (eco.Geocoder.make_url_reverse(lat, lon)) self.assertEqual(expected_result, actual_result) #Testing get_json_geo, which passes in an address as a query. Compares three select k,v pairs in the results. diff --git a/emission/integrationTests/start_integration_tests.sh b/emission/integrationTests/start_integration_tests.sh index fa69e3b4d..da2e30e5b 100644 --- a/emission/integrationTests/start_integration_tests.sh +++ b/emission/integrationTests/start_integration_tests.sh @@ -16,7 +16,7 @@ echo "Setting up conda..." source setup/setup_conda.sh Linux-x86_64 echo "Setting up the test environment..." -source setup/setup_integrationtests.sh +source setup/setup_tests.sh echo "Running tests..." source setup/activate_tests.sh diff --git a/emission/net/ext_service/geocoder/nominatim.py b/emission/net/ext_service/geocoder/nominatim.py index 01299313f..c0e311560 100644 --- a/emission/net/ext_service/geocoder/nominatim.py +++ b/emission/net/ext_service/geocoder/nominatim.py @@ -14,13 +14,13 @@ from emission.core.wrapper.trip_old import Coordinate try: NOMINATIM_QUERY_URL = os.environ.get("NOMINATIM_QUERY_URL") - # logging.info(f"NOMINATIM_QUERY_URL: {NOMINATIM_QUERY_URL}") + logging.info(f"NOMINATIM_QUERY_URL: {NOMINATIM_QUERY_URL}") print("Nominatim Query URL Configured!") if NOMINATIM_QUERY_URL is None: raise Exception("Nominatim query url not configured") except: - print("URL not configured, place decoding must happen on the client") + print("Nominatim URL not configured, place decoding must happen on the client") class Geocoder(object): diff --git a/setup/setup_integrationtests.sh b/setup/setup_integrationtests.sh deleted file mode 100644 index 72de46840..000000000 --- a/setup/setup_integrationtests.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -source setup/checks/check_for_conda.sh - -conda env update --name emissiontest --file setup/environment36.yml -# python bin/deploy/habitica_conf.py -python bin/deploy/push_conf.py -python bin/deploy/model_copy.py -python bin/createfakeplace.py