Skip to content

Commit b4aba9c

Browse files
committed
Merge pull request googlemaps#21 from markmcd/zeroreturns
0️⃣ added zero_results as success
2 parents ab531f8 + eeb4e85 commit b4aba9c

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

‎googlemaps/common.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def _get(ctx, url, params):
104104

105105
body = resp.json()
106106

107-
if body["status"] == "OK" or body["status"] == "NO_RESULTS":
107+
if body["status"] == "OK" or body["status"] == "ZERO_RESULTS":
108108
return body
109109

110110
# TODO(mdr-eng): use body["error_message"] if present.

‎test/test_directions.py‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,17 @@ def test_toledo_to_madrid_in_spain(self):
215215
self.key,
216216
responses.calls[0].request.url)
217217

218-
# TODO(mdr-eng): Convert ZERO_RETURNS into zero length arrays.
219-
# def test_toledo_to_madrid_not_in_spain(self):
220-
# routes = googlemaps.directions(self.ctx, "Toledo", "Madrid")
221-
# self.assertIsNotNone(routes)
222-
# self.assertEquals(0, len(routes))
218+
@responses.activate
219+
def test_zero_results_returns_response(self):
220+
responses.add(responses.GET,
221+
'https://maps.googleapis.com/maps/api/directions/json',
222+
body='{"status":"ZERO_RESULTS","routes":[]}',
223+
status=200,
224+
content_type='application/json')
225+
226+
routes = googlemaps.directions(self.ctx, "Toledo", "Madrid")
227+
self.assertIsNotNone(routes)
228+
self.assertEquals(0, len(routes))
223229

224230
@responses.activate
225231
def test_language_parameter(self):

0 commit comments

Comments
 (0)