diff --git a/.github/workflows/continuous_integration.yml b/.github/workflows/continuous_integration.yml index ceadde8..5cebaa9 100644 --- a/.github/workflows/continuous_integration.yml +++ b/.github/workflows/continuous_integration.yml @@ -42,11 +42,11 @@ jobs: - name: Run tests run: python setup.py test - env: - BING_MAPS_API_KEY: ${{ secrets.BING_MAPS_API_KEY }} - ESRI_CLIENT_ID: ${{ secrets.ESRI_CLIENT_ID }} - ESRI_CLIENT_SECRET: ${{ secrets.ESRI_CLIENT_SECRET }} - GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }} - MAPQUEST_API_KEY: ${{ secrets.MAPQUEST_API_KEY }} - PELIAS_API_KEY: ${{ secrets.PELIAS_API_KEY }} + # env: + # BING_MAPS_API_KEY: ${{ secrets.BING_MAPS_API_KEY }} + # ESRI_CLIENT_ID: ${{ secrets.ESRI_CLIENT_ID }} + # ESRI_CLIENT_SECRET: ${{ secrets.ESRI_CLIENT_SECRET }} + # GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }} + # MAPQUEST_API_KEY: ${{ secrets.MAPQUEST_API_KEY }} + # PELIAS_API_KEY: ${{ secrets.PELIAS_API_KEY }} diff --git a/CHANGES.rst b/CHANGES.rst index 71f67db..9b01fe6 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -228,3 +228,10 @@ v6.1.0, 2021-07-20 * Populate match_region using RegionAbbr rather than Region from EsriWGS. For example, when using the EsriWGS geocoder, expect 'PA' rather than 'Pennsylvania' in match_region. + +v6.2.0, 2024-01-22 +------------------ + * Fix /findAddressCandidates calls for EsriWGS when using magicKey. They + previously would provide an internal Loc_name field in the response which + is no longer supplied, which broke the API. Making that field optional in + our code fixes this. diff --git a/omgeo/services/esri.py b/omgeo/services/esri.py index 437bd9d..99f9e99 100644 --- a/omgeo/services/esri.py +++ b/omgeo/services/esri.py @@ -55,6 +55,7 @@ class EsriWGS(GeocodeService): DEFAULT_POSTPROCESSORS = [ AttrFilter(['PointAddress', 'StreetAddress', + 'Locality', # 'PostalExt', # 'Postal' ], @@ -62,6 +63,7 @@ class EsriWGS(GeocodeService): # AttrExclude(['USA_Postal'], 'locator'), #accept postal from everywhere but US (need PostalExt) AttrSorter(['PointAddress', 'StreetAddress', + 'Locality', # 'PostalExt', # 'Postal' ], @@ -195,7 +197,7 @@ def _geocode(self, pq): c = Candidate() attributes = location['attributes'] c.match_addr = attributes['Match_addr'] - c.locator = attributes['Loc_name'] + c.locator = attributes.get('Loc_name', '') c.locator_type = attributes['Addr_type'] c.score = attributes['Score'] c.x = attributes['DisplayX'] # represents the actual location of the address. @@ -210,7 +212,8 @@ def _geocode(self, pq): setattr(c, out_key, attributes.get(in_key, '')) setattr(c, 'match_streetaddr', self._street_addr_from_response(attributes)) returned_candidates.append(c) - except KeyError: + except KeyError as e: + logger.warning('Missing key: ' + e) pass return returned_candidates diff --git a/omgeo/tests/tests.py b/omgeo/tests/tests.py index bd133a0..5c94861 100755 --- a/omgeo/tests/tests.py +++ b/omgeo/tests/tests.py @@ -208,6 +208,16 @@ def test_geocode_esri_wgs_340_12th_bounded(self): self.assertEqual('340 N 12th' in candidates[0].match_addr, True, '"340 N 12th" not found in match_addr. Got "%s"' % candidates[0].match_addr) + def test_geocode_esri_wgs_magicKey(self): + """Check that geocoding New York, USA with a magicKey returns one result.""" + esri = self.g_esri_wgs._sources[0] + suggestions = esri._get_json_obj( + f'{esri._endpoint}/suggest', + {'f': 'json', 'text': 'New York, USA'})['suggestions'] + pq = PlaceQuery(suggestions[0]['text'], key=suggestions[0]['magicKey']) + candidates = self.g_esri_wgs.get_candidates(pq) + self.assertOneCandidate(candidates) + def test_geocode_esri_wgs_zip_plus_4(self): """Check that geocoding 19127-1112 returns one result.""" candidates = self.g_esri_wgs_postal_ok.get_candidates(self.pq['zip_plus_4_in_postal_plus_country']) @@ -229,6 +239,7 @@ def test_esri_short_region(self): candidate = self.g_esri_wgs.get_candidates(self.pq["azavea"])[0] self.assertEqual(candidate.match_region, "PA") + @unittest.skipIf(GOOGLE_API_KEY is None, GOOGLE_KEY_REQUIRED_MSG) def test_google_short_region(self): """Ensure that Google uses region abbreviations""" candidate = self.g_google.get_candidates(self.pq["azavea"])[0] @@ -272,8 +283,8 @@ def test_geocode_nom(self): self.assertEqual(len(candidates) > 0, True, 'No candidates returned.') def test_geocode_census(self): - """Test Azavea's address using US Census geocoder.""" - candidates = self.g_census.get_candidates(PlaceQuery('1200 Callowhill St, Philadelphia, PA')) + """Test Element 84's address using US Census geocoder.""" + candidates = self.g_census.get_candidates(PlaceQuery('210 N. Lee Street, Alexandria, VA')) self.assertEqual(len(candidates) > 0, True, 'No candidates returned.') def test_EsriWGS_address_components(self):