From e7b7c570fab58903f9cf93fee7a428f74e0d970c Mon Sep 17 00:00:00 2001 From: Josh Levinger Date: Mon, 10 Jul 2017 18:02:08 -0700 Subject: [PATCH] =?UTF-8?q?Simplify=20test=20location=20data,=20don?= =?UTF-8?q?=E2=80=99t=20wrap=20raw=20fields=20in=20components=20dict?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- call_server/political_data/geocode.py | 5 ++++- tests/test_ca_data.py | 2 +- tests/test_us_data.py | 6 +++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/call_server/political_data/geocode.py b/call_server/political_data/geocode.py index 04eaac97..296aa6cb 100644 --- a/call_server/political_data/geocode.py +++ b/call_server/political_data/geocode.py @@ -76,9 +76,12 @@ def _find_in_raw(self, field): return self.raw['address'].get(field) elif self.service == LOCAL_USDATA_SERVICE: return self.raw.get(field) + else: + # try simple extraction from raw + return self.raw.get(field) except KeyError: try: - # try simple extraction from raw + # fallback to raw return self.raw.get(field) except KeyError, ValueError: raise ValueError('unable to parse raw fields from geocoder service '+self.service) diff --git a/tests/test_ca_data.py b/tests/test_ca_data.py index 9b4b841e..0ebdb327 100644 --- a/tests/test_ca_data.py +++ b/tests/test_ca_data.py @@ -37,7 +37,7 @@ def setUp(self, **kwargs): # well, really montreal self.mock_location = Location('North Pole', (45.500577, -73.567427), - {'components':{'province':'QC','postal_code':'H0H 0H0'}}) + {'province':'QC','postal_code':'H0H 0H0'}) def test_cache(self): self.assertIsNotNone(self.mock_cache) diff --git a/tests/test_us_data.py b/tests/test_us_data.py index b665211d..d2a29841 100644 --- a/tests/test_us_data.py +++ b/tests/test_us_data.py @@ -33,15 +33,15 @@ def setUp(self, **kwargs): # avoid geocoding round-trip self.mock_location = Location('Boston, MA', (42.355662,-71.065483), - {'components':{'state':'MA','zipcode':'02111'}}) + {'state':'MA','zipcode':'02111'}) # this zipcode pretty evenly split between KY-2 & TN-7 self.mock_location_multiple_states = Location('Fort Campbell, KY', (36.647207, -87.451635), - {'components':{'state':'KY','zipcode':'42223'}}) + {'state':'KY','zipcode':'42223'}) # this zipcode pretty evenly split between WI-2 & WI-3 self.mock_location_multiple_districts = Location('Hazel Green, WI', (42.532498, -90.436727), - {'components':{'state':'WI','zipcode':'53811'}}) + {'state':'WI','zipcode':'53811'}) def test_cache(self): self.assertIsNotNone(self.mock_cache)