Add function cdb_routing_with_waypoints
Add routing with waypoints functions to client and server. Includes signature checks tests for the Postgresql functions and unit and integration tests for the Python library. Add client v0.6.0 and server v0.9.0
This commit is contained in:
@@ -17,9 +17,9 @@ requests_mock.Mocker.TEST_PREFIX = 'test_'
|
||||
@requests_mock.Mocker()
|
||||
class MapzenRoutingTestCase(unittest.TestCase):
|
||||
|
||||
GOOD_SHAPE = [(38.5, -120.2), (43.2, -126.4)]
|
||||
GOOD_SHAPE_SIMPLE = [(38.5, -120.2), (43.2, -126.4)]
|
||||
|
||||
GOOD_RESPONSE = """{{
|
||||
GOOD_RESPONSE_SIMPLE = """{{
|
||||
"id": "ethervoid-route",
|
||||
"trip": {{
|
||||
"status": 0,
|
||||
@@ -51,7 +51,50 @@ class MapzenRoutingTestCase(unittest.TestCase):
|
||||
}}
|
||||
]
|
||||
}}
|
||||
}}""".format(GOOD_SHAPE)
|
||||
}}""".format(GOOD_SHAPE_SIMPLE)
|
||||
|
||||
GOOD_SHAPE_MULTI = [(40.4, -3.7), (40.1, -3.4), (40.6, -3.9)]
|
||||
|
||||
GOOD_RESPONSE_MULTI = """{{
|
||||
"id": "ethervoid-route",
|
||||
"trip": {{
|
||||
"language":"en-US",
|
||||
"summary":{{
|
||||
"length": 1.261,
|
||||
"time": 913
|
||||
}},
|
||||
"locations":[
|
||||
{{
|
||||
"side_of_street":"right",
|
||||
"lon": -3.7,
|
||||
"lat": 40.4,
|
||||
"type":"break"
|
||||
}},
|
||||
{{
|
||||
"lon": -3.4,
|
||||
"lat": 40.1,
|
||||
"type": "through"
|
||||
}},
|
||||
{{
|
||||
"lon": -3.9,
|
||||
"lat": 40.6,
|
||||
"type": "break"
|
||||
}}
|
||||
],
|
||||
"units":"kilometers",
|
||||
"legs":[
|
||||
{{
|
||||
"shape": "_squF~sqU~qy@_ry@_t`B~s`B",
|
||||
"summary": {{
|
||||
"length":1.261,
|
||||
"time":913
|
||||
}}
|
||||
}}
|
||||
],
|
||||
"status_message": "Found route between points",
|
||||
"status": 0
|
||||
}}
|
||||
}}""".format(GOOD_SHAPE_MULTI)
|
||||
|
||||
MALFORMED_RESPONSE = """{"manolo": "escobar"}"""
|
||||
|
||||
@@ -61,23 +104,39 @@ class MapzenRoutingTestCase(unittest.TestCase):
|
||||
|
||||
def test_calculate_simple_routing_with_valid_params(self, req_mock):
|
||||
req_mock.register_uri('GET', requests_mock.ANY,
|
||||
text=self.GOOD_RESPONSE)
|
||||
text=self.GOOD_RESPONSE_SIMPLE)
|
||||
origin = Coordinate('-120.2', '38.5')
|
||||
destination = Coordinate('-126.4', '43.2')
|
||||
response = self.routing.calculate_route_point_to_point(origin,
|
||||
destination,
|
||||
waypoints = [origin, destination]
|
||||
response = self.routing.calculate_route_point_to_point(waypoints,
|
||||
'car')
|
||||
|
||||
self.assertEqual(response.shape, self.GOOD_SHAPE)
|
||||
self.assertEqual(response.shape, self.GOOD_SHAPE_SIMPLE)
|
||||
self.assertEqual(response.length, 444.59)
|
||||
self.assertEqual(response.duration, 16969)
|
||||
|
||||
def test_uknown_mode_raise_exception(self, req_mock):
|
||||
req_mock.register_uri('GET', requests_mock.ANY,
|
||||
text=self.GOOD_RESPONSE)
|
||||
text=self.GOOD_RESPONSE_SIMPLE)
|
||||
origin = Coordinate('-120.2', '38.5')
|
||||
destination = Coordinate('-126.4', '43.2')
|
||||
waypoints = [origin, destination]
|
||||
|
||||
assert_raises(WrongParams,
|
||||
self.routing.calculate_route_point_to_point,
|
||||
origin, destination, 'unknown')
|
||||
waypoints, 'unknown')
|
||||
|
||||
def test_calculate_routing_waypoints_with_valid_params(self, req_mock):
|
||||
req_mock.register_uri('GET', requests_mock.ANY,
|
||||
text=self.GOOD_RESPONSE_MULTI)
|
||||
origin = Coordinate('-3.7', '40.4')
|
||||
pass_through = Coordinate('-3.4', '40.1')
|
||||
destination = Coordinate('-3.9', '40.6')
|
||||
waypoints = [origin, pass_through, destination]
|
||||
|
||||
response = self.routing.calculate_route_point_to_point(waypoints,
|
||||
'walk')
|
||||
|
||||
self.assertEqual(response.length, 1.261)
|
||||
self.assertEqual(response.duration, 913)
|
||||
self.assertEqual(response.shape, self.GOOD_SHAPE_MULTI)
|
||||
|
||||
Reference in New Issue
Block a user