Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
def _parse_direction_json(response, alternatives):
if response is None: # pragma: no cover
if alternatives:
return Directions()
else:
return Direction()
if alternatives is not None and alternatives > 1:
routes = []
for route in response['response']['route']:
routes.append(
Direction(
geometry=[
list(reversed(list((map(float, coordinates.split(','))))))
for coordinates in route['shape']
],
duration=int(route['summary']['baseTime']),
distance=int(route['summary']['distance']),
raw=route
)
)
def _parse_direction_json(response, alternatives):
if response is None: # pragma: no cover
if alternatives:
return Directions()
else:
return Direction()
if alternatives is not None and alternatives > 1:
routes = []
for route in response['response']['route']:
routes.append(
Direction(
geometry=[
list(reversed(list((map(float, coordinates.split(','))))))
for coordinates in route['shape']
],
duration=int(route['summary']['baseTime']),
distance=int(route['summary']['distance']),
raw=route
)
)
return Directions(directions=routes, raw=response)
else:
geometry = [
list(reversed(list(map(float, coordinates.split(',')))))
for coordinates in response['response']['route'][0].get('shape')
distance=int(route['summary']['distance']),
raw=route
)
)
return Directions(directions=routes, raw=response)
else:
geometry = [
list(reversed(list(map(float, coordinates.split(',')))))
for coordinates in response['response']['route'][0].get('shape')
]
duration = int(response['response']['route'][0]['summary'].get('baseTime'))
distance = int(response['response']['route'][0]['summary'].get('distance'))
return Direction(geometry=geometry, duration=duration, distance=distance, raw=response)
geometry = utils.decode_polyline5(route_geometry, is3d=False)
elif geometry_format == 'polyline6':
geometry = utils.decode_polyline6(route_geometry, is3d=False)
elif geometry_format == 'geojson':
geometry = route_geometry['coordinates']
else:
raise ValueError(
"OSRM: parameter geometries needs one of ['polyline', 'polyline6', 'geojson"
)
return geometry
if alternatives:
routes = []
for route in response['routes']:
routes.append(
Direction(
geometry=_parse_geometry(route['geometry']),
duration=int(route['duration']),
distance=int(route['distance']),
raw=route
)
)
return Directions(routes, response)
else:
return Direction(
geometry=_parse_geometry(response['routes'][0]['geometry']),
duration=int(response['routes'][0]['duration']),
distance=int(response['routes'][0]['distance']),
raw=response
)
def _parse_direction_json(response, units):
if response is None: # pragma: no cover
return Direction()
geometry, duration, distance = [], 0, 0
for leg in response['trip']['legs']:
geometry.extend([list(reversed(coord)) for coord in utils.decode_polyline6(leg['shape'])])
duration += leg['summary']['time']
factor = 0.621371 if units == 'mi' else 1
distance += int(leg['summary']['length'] * 1000 * factor)
return Direction(geometry=geometry, duration=int(duration), distance=int(distance), raw=response)
return geometry
if alternatives:
routes = []
for route in response['routes']:
routes.append(
Direction(
geometry=_parse_geometry(route['geometry']),
duration=int(route['duration']),
distance=int(route['distance']),
raw=route
)
)
return Directions(routes, response)
else:
return Direction(
geometry=_parse_geometry(response['routes'][0]['geometry']),
duration=int(response['routes'][0]['duration']),
distance=int(response['routes'][0]['distance']),
raw=response
)
return geometry
if alternatives:
routes = []
for route in response['routes']:
routes.append(
Direction(
geometry=_parse_geometry(route['geometry']),
duration=int(route['duration']),
distance=int(route['distance']),
raw=route
)
)
return Directions(routes, response)
else:
return Direction(
geometry=_parse_geometry(response['routes'][0]['geometry']),
duration=int(response['routes'][0]['duration']),
distance=int(response['routes'][0]['distance']),
raw=response
)