From 5a958d01d070e12fcffbbcbbeebe7d913bf40fc5 Mon Sep 17 00:00:00 2001 From: Matthew Perry Date: Mon, 26 Oct 2015 09:11:39 -0400 Subject: [PATCH] raise_for_status #45, rm useless distance_matrix func --- mapbox/services/distance.py | 14 ++++---------- tests/test_distances.py | 3 ++- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/mapbox/services/distance.py b/mapbox/services/distance.py index 8172107..069d30a 100644 --- a/mapbox/services/distance.py +++ b/mapbox/services/distance.py @@ -22,13 +22,7 @@ def distances(self, features): uri = URITemplate('%s/{profile}' % self.baseuri).expand( profile=self.profile) - return self.session.post(uri, data=coords, - headers={'Content-Type': 'application/json'}) - - def distance_matrix(self, features): - res = self.distances(features) - if res.status_code == 200: - data = res.json() - return data['durations'] - else: - raise Exception(res.text) + res = self.session.post(uri, data=coords, + headers={'Content-Type': 'application/json'}) + res.raise_for_status() + return res diff --git a/tests/test_distances.py b/tests/test_distances.py index 5e666cf..09c964e 100644 --- a/tests/test_distances.py +++ b/tests/test_distances.py @@ -54,7 +54,8 @@ def test_distances_matrix(): status=200, content_type='application/json') - matrix = mapbox.Distance(access_token='pk.test').distance_matrix(points) + res = mapbox.Distance(access_token='pk.test').distances(points) + matrix = res.json()['durations'] # 3x3 list assert len(matrix) == 3 assert len(matrix[0]) == 3