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)
'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)
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')
]
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)
def _parse_directions_json(response, algorithm, elevation):
if response is None: # pragma: no cover
if algorithm == 'alternative_route':
return Directions()
else:
return Direction()
if algorithm == 'alternative_route':
routes = []
for route in response['paths']:
geometry = [
list(reversed(coord))
for coord in utils.decode_polyline5(route['points'], elevation)
]
routes.append(
Direction(
geometry=geometry,
duration=int(route['time'] / 1000),
distance=int(route['distance']),
raw=route
"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
)
"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, alternatives, geometry_format):
if response is None: # pragma: no cover
if alternatives:
return Directions()
else:
return Direction()
def _parse_geometry(route_geometry):
if geometry_format in (None, 'polyline'):
geometry = [
list(reversed(coord))
for coord in utils.decode_polyline5(route_geometry, is3d=False)
]
elif geometry_format == 'polyline6':
geometry = [
list(reversed(coord))
for coord in utils.decode_polyline6(route_geometry, is3d=False)
]
elif geometry_format == 'geojson':
geometry = route_geometry['coordinates']
def _parse_direction_json(response, alternatives):
if response is None: # pragma: no cover
if alternatives:
return Directions()
else:
return Direction()
if alternatives:
routes = []
for route in response['routes']:
geometry = []
duration, distance = 0, 0
for leg in route['legs']:
duration += leg['duration']['value']
distance += leg['distance']['value']
for step in leg['steps']:
geometry.extend(
[
list(reversed(coords))
for coords in utils.decode_polyline5(step['polyline']['points'])
if algorithm == 'alternative_route':
routes = []
for route in response['paths']:
geometry = [
list(reversed(coord))
for coord in utils.decode_polyline5(route['points'], elevation)
]
routes.append(
Direction(
geometry=geometry,
duration=int(route['time'] / 1000),
distance=int(route['distance']),
raw=route
)
)
return Directions(routes, response)
else:
geometry = [
list(reversed(coord))
for coord in utils.decode_polyline5(response['paths'][0]['points'], elevation)
]
return Direction(
geometry=geometry,
duration=int(response['paths'][0]['time'] / 1000),
distance=int(response['paths'][0]['distance']),
raw=response
)