From 6bd7a80a1801e8bd98e412a5b270dcacdbd1ef78 Mon Sep 17 00:00:00 2001 From: Brendan Ebers Date: Thu, 23 Jul 2015 21:17:19 -0500 Subject: [PATCH 1/2] Changed administrative_area from a class attribute to an instance attribute. This fixes an issue where multiple search results would share the same list of administrative areas. --- geolocation/geocode/models.py | 4 ++-- tests/tests.py | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/geolocation/geocode/models.py b/geolocation/geocode/models.py index f9d6da9..1c71af7 100644 --- a/geolocation/geocode/models.py +++ b/geolocation/geocode/models.py @@ -2,7 +2,6 @@ class LocationModel(object): - _administrative_area = list() def __init__(self, **kwargs): self.city = kwargs.get('city') @@ -14,6 +13,7 @@ def __init__(self, **kwargs): self.lat = kwargs.get('lat') self.lng = kwargs.get('lng') self.formatted_address = kwargs.get('formatted_address') + self._administrative_area = list() def __repr__(self): return '' % self.city @@ -35,4 +35,4 @@ def __init__(self, area_type, name): self.name = name def __repr__(self): - return '' % self.name \ No newline at end of file + return '' % self.name diff --git a/tests/tests.py b/tests/tests.py index 2194e44..40b6ab7 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -123,6 +123,19 @@ def test_latlng(self): self.assertEqual('Mountain View', my_location.city.decode('utf-8')) + def test_administrative_area_resets(self): + address = "São Paulo" + + my_location = self.google_maps.search(address).first() + + self.assertEqual(len(my_location.administrative_area), 2) + + address = "Rio de Janeiro" + + my_location = self.google_maps.search(address).first() + + self.assertEqual(len(my_location.administrative_area), 2) + class DistanceMatrixTest(unittest.TestCase): def setUp(self): @@ -212,4 +225,8 @@ def test_distance_matrix_avoid_ferries(self): self.assertEqual(item.distance.kilometers, 1851) self.assertEqual(item.distance.meters, 1851000) self.assertEqual(item.distance.miles, 1150.1559) - self.assertEqual(str(item.duration), '0d 17h 35m 44s') \ No newline at end of file + self.assertEqual(str(item.duration), '0d 17h 35m 44s') + + +if __name__ == '__main__': + unittest.main() From 06427149bc5c8a07970756d70221d9a2bf5de7d1 Mon Sep 17 00:00:00 2001 From: Brendan Ebers Date: Thu, 23 Jul 2015 22:46:17 -0500 Subject: [PATCH 2/2] Improved test resiliency. --- tests/tests.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/tests.py b/tests/tests.py index 40b6ab7..aa25322 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -125,16 +125,12 @@ def test_latlng(self): def test_administrative_area_resets(self): address = "São Paulo" + sao_paulo = self.google_maps.search(address).first() - my_location = self.google_maps.search(address).first() - - self.assertEqual(len(my_location.administrative_area), 2) - - address = "Rio de Janeiro" - - my_location = self.google_maps.search(address).first() + address = "Houston, TX" + houston = self.google_maps.search(address).first() - self.assertEqual(len(my_location.administrative_area), 2) + self.assertNotEqual(sao_paulo, houston) class DistanceMatrixTest(unittest.TestCase):