Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.assertEqual(1, len(responses.calls))
# python 3.5 dict doesn't guarantee the order when added input to x-www-form-urlencoded
expected_url = (
'coordinates=8.688641%2C49.420577%3B8.680916%2C49.415776%3B8.780916%2C49.445776&'
'radiuses=500%3B500%3B500&bearings=50%2C50%3B50%2C50%3B50%2C50&alternatives=3&steps=true&'
'continue_straight=true&annotations=duration%2Cdistance%2Cspeed&geometries=geojson&'
'overview=simplified&exclude=motorway&approaches=%3Bcurb%3Bcurb%3Bcurb&banner_instuctions=true&'
'language=de&roundabout_exits=true&voide_instructions=true&voice_units=metric&'
'waypoint_names=a%3Bb%3Bc&waypoint_targets=%3B8.688641%2C49.420577%3B8.680916%2C49.415776%3B'
'8.780916%2C49.445776'
).split("&")
called_url = responses.calls[0].request.body.split("&")
self.assertTrue(Counter(expected_url) == Counter(called_url))
self.assertIsInstance(routes, Directions)
self.assertEqual(1, len(routes))
self.assertIsInstance(routes[0], Direction)
self.assertIsInstance(routes[0].geometry, list)
self.assertIsInstance(routes[0].duration, int)
self.assertIsInstance(routes[0].distance, int)
self.assertIsInstance(routes.raw, dict)
def test_raise_over_query_limit(self):
query = self.params
responses.add(
responses.POST,
'https://httpbin.org/post',
json=query,
status=429,
content_type='application/json'
)
with self.assertRaises(routingpy.exceptions.OverQueryLimit):
client = RouterMock(base_url="https://httpbin.org", retry_over_query_limit=False)
client.directions(url='/post', post_params=query)
def test_delimit_list(self):
l = [(8.68864, 49.42058), (8.68092, 49.41578)]
s = convert._delimit_list([convert._delimit_list(pair, ',') for pair in l], '|')
self.assertEqual(s, "8.68864,49.42058|8.68092,49.41578")
def test_full_matrix(self):
query = ENDPOINTS_QUERIES[self.name]['matrix']
coords = convert._delimit_list([convert._delimit_list(pair) for pair in query['locations']], ';')
responses.add(
responses.GET,
'https://router.project-osrm.org/table/v1/{}/{}'.format(query['profile'], coords),
status=200,
json=ENDPOINTS_RESPONSES['osrm']['matrix'],
content_type='application/json'
)
matrix = self.client.matrix(**query)
self.assertEqual(1, len(responses.calls))
self.assertURLEqual(
'https://router.project-osrm.org/table/v1/car/8.688641,49.420577;8.680916,49.415776;8.780916,49.445776',
responses.calls[0].request.url
)
responses.GET,
'https://router.project-osrm.org/route/v1/{}/{}'.format(query['profile'], coords),
status=200,
json=ENDPOINTS_RESPONSES['osrm']['directions_geojson'],
content_type='application/json'
)
routes = self.client.directions(**query)
self.assertEqual(1, len(responses.calls))
self.assertURLEqual(
'https://router.project-osrm.org/route/v1/car/8.688641,49.420577;8.680916,49.415776;8.780916,49.445776?'
'alternatives=false&annotations=true&bearings=50%2C50%3B50%2C50%3B50%2C50&continue_straight=true&'
'geometries=geojson&overview=simplified&radiuses=500%3B500%3B500&steps=true',
responses.calls[0].request.url
)
self.assertIsInstance(routes, Direction)
self.assertIsInstance(routes.distance, int)
self.assertIsInstance(routes.duration, int)
self.assertIsInstance(routes.geometry, list)
self.assertIsInstance(routes.raw, dict)
json=ENDPOINTS_RESPONSES['osrm']['directions_geojson'],
content_type='application/json'
)
routes = self.client.directions(**query)
self.assertEqual(1, len(responses.calls))
self.assertURLEqual(
'https://router.project-osrm.org/route/v1/car/8.688641,49.420577;8.680916,49.415776;8.780916,49.445776?'
'alternatives=true&annotations=true&bearings=50%2C50%3B50%2C50%3B50%2C50&continue_straight=true&'
'geometries=geojson&overview=simplified&radiuses=500%3B500%3B500&steps=true',
responses.calls[0].request.url
)
self.assertIsInstance(routes, Directions)
self.assertEqual(1, len(routes))
for route in routes:
self.assertIsInstance(route, Direction)
self.assertIsInstance(route.duration, int)
self.assertIsInstance(route.distance, int)
self.assertIsInstance(route.geometry, list)
self.assertIsInstance(route.raw, dict)
'https://route.api.here.com/routing/7.2/calculateroute.json?alternatives=1&app_code=sample_app_code&'
'app_id=sample_app_id&avoidAreas=49.420577%2C8.688641%3B49.415776%2C8.680916%2149.445776%2C8.780916%3B49.445776%2C8.780916&'
'avoidLinks=-53623477&avoidSeasonalClosures=true&avoidTurns=difficult&combineChange=false&consumptionModel=default&'
'departure=2019-03-29T03%3A00%3A00&excludeCountries=AUT%2CCHE&excludeZoneTypes=vignette%2CcongestionPricing&'
'excludeZones=510%2C511&generalizationTolerances=0.1%2C0.01&height=20&instructionFormat=text&jsonAttributes=9&'
'legAttributes=maneuvers%2Cwaypoint%2Clength%2CtravelTime&length=10&licensePlate=lastcharacter%3A5&limitedWeight=10&'
'linkAttributes=shape%2CspeedLimit&maneuverAttributes=position%2Clength%2CtravelTime&maxNumberOfChanges=5&'
'metricSystem=metric&mode=fastest%3Btruck&requestId=101&resolution=300%3A300&returnElevation=true&'
'routeAttributes=waypoints%2Csummary%2CsummaryByCountry%2Cshape%2CboundingBox%2Clegs%2Cnotes%2Clines%2CrouteId%2Cgroups%2Ctickets%2Cincidents%2Czones&'
'shippedHazardousGoods=gas%2Cflammable&speedProfile=fast&trailersCount=3&truckRestrictionPenalty=soft&truckType=truck&vehicleType=diesel%2C5.5&'
'viewBounds=49.420577%2C8.688641%3B49.415776%2C8.680916&waypoint0=geo%2149.420577%2C8.688641&waypoint1=geo%2149.415776%2C8.680916&'
'waypoint2=geo%2149.445776%2C8.780916&weightPerAxle=100&width=10',
responses.calls[0].request.url
)
self.assertIsInstance(routes, Direction)
self.assertIsInstance(routes.geometry, list)
self.assertIsInstance(routes.duration, int)
self.assertIsInstance(routes.distance, int)
self.assertIsInstance(routes.raw, dict)
responses.GET,
'https://api.mapbox.com/directions-matrix/v1/mapbox/{}/{}'.format(query['profile'], coords),
status=200,
json=ENDPOINTS_RESPONSES['mapbox_osrm']['matrix'],
content_type='application/json'
)
matrix = self.client.matrix(**query)
self.assertEqual(1, len(responses.calls))
self.assertURLEqual(
'https://api.mapbox.com/directions-matrix/v1/mapbox/driving/8.688641,49.420577;8.680916,49.415776;8.780916,49.445776?'
'access_token=sample_key&annotations=distance%2Cduration&fallback_speed=50',
responses.calls[0].request.url
)
self.assertIsInstance(matrix, Matrix)
self.assertIsInstance(matrix.distances, list)
self.assertIsInstance(matrix.durations, list)
self.assertIsInstance(matrix.raw, dict)
'https://route.api.here.com/routing/7.2/calculateroute.json?alternatives=3&app_code=sample_app_code&'
'app_id=sample_app_id&avoidAreas=49.420577%2C8.688641%3B49.415776%2C8.680916%2149.445776%2C8.780916%3B49.445776%2C8.780916&'
'avoidLinks=-53623477&avoidSeasonalClosures=true&avoidTurns=difficult&combineChange=false&consumptionModel=default&'
'departure=2019-03-29T03%3A00%3A00&excludeCountries=AUT%2CCHE&excludeZoneTypes=vignette%2CcongestionPricing&'
'excludeZones=510%2C511&generalizationTolerances=0.1%2C0.01&height=20&instructionFormat=text&jsonAttributes=9&'
'legAttributes=maneuvers%2Cwaypoint%2Clength%2CtravelTime&length=10&licensePlate=lastcharacter%3A5&limitedWeight=10&'
'linkAttributes=shape%2CspeedLimit&maneuverAttributes=position%2Clength%2CtravelTime&maxNumberOfChanges=5&'
'metricSystem=metric&mode=fastest%3Btruck&requestId=101&resolution=300%3A300&returnElevation=true&'
'routeAttributes=waypoints%2Csummary%2CsummaryByCountry%2Cshape%2CboundingBox%2Clegs%2Cnotes%2Clines%2CrouteId%2Cgroups%2Ctickets%2Cincidents%2Czones&'
'shippedHazardousGoods=gas%2Cflammable&speedProfile=fast&trailersCount=3&truckRestrictionPenalty=soft&truckType=truck&vehicleType=diesel%2C5.5&'
'viewBounds=49.420577%2C8.688641%3B49.415776%2C8.680916&waypoint0=geo%2149.420577%2C8.688641&waypoint1=geo%2149.415776%2C8.680916&'
'waypoint2=geo%2149.445776%2C8.780916&weightPerAxle=100&width=10',
responses.calls[0].request.url
)
self.assertIsInstance(routes, Directions)
self.assertEqual(3, len(routes))
for route in routes:
self.assertIsInstance(route, Direction)
self.assertIsInstance(route.geometry, list)
self.assertIsInstance(route.duration, int)
self.assertIsInstance(route.distance, int)
self.assertIsInstance(route.raw, dict)
'https://isoline.route.api.here.com/routing/7.2/calculateisoline.json',
status=200,
json=ENDPOINTS_RESPONSES[self.name]['isochrones'],
content_type='application/json'
)
isochrones = self.client.isochrones(**query)
self.assertEqual(1, len(responses.calls))
self.assertURLEqual(
'https://isoline.route.api.here.com/routing/7.2/calculateisoline.json?app_code=sample_app_code&'
'app_id=sample_app_id&mode=fastest%3Bcar&quality=1&range=1000%2C2000%2C3000&rangeType=distance&'
'singleComponent=false&start=geo%2148.23424%2C8.34234', responses.calls[0].request.url
)
self.assertIsInstance(isochrones, Isochrones)
self.assertEqual(3, len(isochrones))
for iso in isochrones:
self.assertIsInstance(iso, Isochrone)
self.assertIsInstance(iso.geometry, list)
self.assertIsInstance(iso.center, list)
self.assertIsInstance(iso.interval, int)