Skip to content

Commit ab7da3b

Browse files
committed
fixed None values.
1 parent 991f5c4 commit ab7da3b

2 files changed

Lines changed: 28 additions & 18 deletions

File tree

geolocation/google_maps.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,22 @@ class GoogleMaps(object):
1616

1717
def __init__(self, api_key):
1818
self._geocode_api = GeocodeApi(api_key)
19-
self._reset_data()
19+
self.clear()
2020

2121
def __repr__(self):
2222
return '<GoogleMaps %s >' % self.all()
2323

24-
def _reset_data(self):
24+
def clear(self):
2525
self._data = set()
2626

27+
@staticmethod
28+
def validate(data):
29+
"""Method should always returns false when data doesn't have city value."""
30+
if not data.city:
31+
return False
32+
33+
return True
34+
2735
def _to_python(self, json_results):
2836
"""Method should converts json_results to python object."""
2937
for item in json_results:
@@ -49,7 +57,8 @@ def _to_python(self, json_results):
4957
location.formatted_address =\
5058
self._geocode_parser.get_formatted_address()
5159

52-
self._data.add(location)
60+
if self.validate(location):
61+
self._data.add(location)
5362

5463
return self.all()
5564

tests/tests.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@
44
import unittest
55
from geolocation.google_maps import GoogleMaps
66

7-
TEST_API_KEY = 'AIzaSyBm0PtaxCuo7iy1KVAnKrl7h8dtA61DXz8'
7+
8+
TEST_API_KEY = 'AIzaSyDNvdrZ_HEtfsuPYHV9UvZGc41BSFBolOM',
89

910

1011
class GeolocationTest(unittest.TestCase):
1112
def setUp(self):
1213
self.google_maps = GoogleMaps(api_key=TEST_API_KEY)
1314

1415
def test_query(self):
15-
address = "New York City Wall Street 12"
16+
address = "New York City Wall Street 15"
1617

1718
location = self.google_maps.search(address)
1819

1920
self.assertIsNotNone(location.all())
2021

2122
def test_city(self):
22-
address = "New York City Wall Street 12"
23+
address = "New York City Wall Street 14"
2324

2425
location = self.google_maps.search(address)
2526

@@ -37,7 +38,7 @@ def test_route(self):
3738
self.assertEqual('Wall Street', my_location.route.decode('utf-8'))
3839

3940
def test_country(self):
40-
address = "New York City Wall Street 12"
41+
address = "New York City Wall Street 110"
4142

4243
location = self.google_maps.search(address)
4344

@@ -46,7 +47,7 @@ def test_country(self):
4647
self.assertEqual('United States', my_location.country.decode('utf-8'))
4748

4849
def test_country_shortcut(self):
49-
address = "New York City Wall Street 12"
50+
address = "New York City Wall Street 2"
5051

5152
location = self.google_maps.search(address)
5253

@@ -55,35 +56,35 @@ def test_country_shortcut(self):
5556
self.assertEqual('US', my_location.country_shortcut.decode('utf-8'))
5657

5758
def test_lat(self):
58-
address = "New York City Wall Street 12"
59+
address = "New York City Wall Street 1"
5960

6061
location = self.google_maps.search(address)
6162

6263
my_location = location.first()
6364

64-
self.assertEqual(40.7060008, my_location.lat)
65+
self.assertEqual(40.707222, my_location.lat)
6566

6667
def test_lng(self):
67-
address = "New York City Wall Street 12"
68+
address = "New York City Wall Street 19"
6869

6970
location = self.google_maps.search(address)
7071

7172
my_location = location.first()
7273

73-
self.assertEqual(-74.0088189, my_location.lng)
74+
self.assertEqual(-74.0134436, my_location.lng)
7475

7576
def test_formatted_address(self):
76-
address = "New York City Wall Street 12"
77+
address = "New York City Wall Street 124"
7778

7879
location = self.google_maps.search(address)
7980

8081
my_location = location.first()
8182

82-
self.assertEqual('Wall Street, New York, NY, USA',
83+
self.assertEqual('Charging Bull, Broadway, New York, NY 10004, USA',
8384
my_location.formatted_address)
8485

8586
def test_administrative_area_level_1(self):
86-
address = "New York City Wall Street 12"
87+
address = "New York City Wall Street 125"
8788

8889
location = self.google_maps.search(address)
8990

@@ -94,7 +95,7 @@ def test_administrative_area_level_1(self):
9495
my_location.administrative_area[0].name.decode('utf-8'))
9596

9697
def test_administrative_area_level_2(self):
97-
address = "New York City Wall Street 12"
98+
address = "New York City Wall Street 126"
9899

99100
location = self.google_maps.search(address)
100101

@@ -112,8 +113,8 @@ def test_coding(self):
112113
self.assertEqual(u"São Paulo", my_location.city.decode('utf-8'))
113114

114115
def test_latlng(self):
115-
lat = 37.42291810
116-
lng = -122.08542120
116+
lat = 37.4229210
117+
lng = -122.0852112
117118

118119
my_location = self.google_maps.search(lat=lat, lng=lng).first()
119120

0 commit comments

Comments
 (0)