Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
content_type='application/json'
)
isochrones = self.client.isochrones(**query)
self.assertEqual(1, len(responses.calls))
self.assertURLEqual(
'https://graphhopper.com/api/1/isochrone?buckets=3&debug=false&key=sample_key&'
'point=48.23424%2C8.34234&vehicle=car&reverse_flow=true&time_limit=1000&type=json',
responses.calls[0].request.url
)
self.assertIsInstance(isochrones, Isochrones)
self.assertEqual(3, len(isochrones))
self.assertIsInstance(isochrones.raw, dict)
for iso in isochrones:
self.assertIsInstance(iso, Isochrone)
self.assertIsInstance(iso.geometry, list)
self.assertIsInstance(iso.interval, int)
self.assertIsInstance(iso.center, list)
json=ENDPOINTS_RESPONSES[self.name]['isochrones'],
content_type='application/json'
)
iso = self.client.isochrones(**query)
self.assertEqual(1, len(responses.calls))
self.assertURLEqual(
'https://api.mapbox.com/isochrone/v1/mapbox/driving/8.34234,48.23424?costing=mapbox/driving&access_token=sample_key&'
'contours_colors=ff0000%2C00FF00&contours_minutes=10%2C20&denoise=0.1&generalize=0.5&polygons=True',
responses.calls[0].request.url
)
self.assertIsInstance(iso, Isochrones)
self.assertEqual(2, len(iso))
for ischrone in iso:
self.assertIsInstance(ischrone, Isochrone)
self.assertIsInstance(ischrone.geometry, list)
self.assertIsInstance(ischrone.interval, int)
self.assertIsInstance(ischrone.center, list)
responses.POST,
'https://api.mapbox.com/valhalla/v1/isochrone',
status=200,
json=ENDPOINTS_RESPONSES[self.name]['isochrones'],
content_type='application/json'
)
iso = self.client.isochrones(**query)
self.assertEqual(1, len(responses.calls))
self.assertEqual(json.loads(responses.calls[0].request.body.decode('utf-8')), expected)
self.assertIsInstance(iso, Isochrones)
self.assertIsInstance(iso.raw, dict)
self.assertEqual(2, len(iso))
for i in iso:
self.assertIsInstance(i, Isochrone)
self.assertIsInstance(i.geometry, list)
self.assertIsInstance(i.interval, int)
self.assertIsInstance(i.center, list)
if response is None: # pragma: no cover
return Isochrones()
geometries = []
for idx, isochrones in enumerate(response['response']['isoline']):
range_polygons = []
if 'component' in isochrones:
for component in isochrones['component']:
if 'shape' in component:
coordinates_list = []
for coordinates in component['shape']:
coordinates_list.append([float(f) for f in coordinates.split(",")])
range_polygons.append(coordinates_list)
geometries.append(
Isochrone(
geometry=range_polygons,
interval=intervals[idx],
center=list(response['response']['start']['mappedPosition'].values())
)
)
return Isochrones(isochrones=geometries, raw=response)
def _parse_isochrone_json(response, type, max_range, buckets, center):
if response is None: # pragma: no cover
return Isochrones()
isochrones = []
accessor = 'polygons' if type == 'json' else 'features'
for index, polygon in enumerate(response[accessor]):
isochrones.append(
Isochrone(
geometry=[l[:2] for l in polygon['geometry']['coordinates'][0]
], # takes in elevation for some reason
interval=int(max_range * ((polygon['properties']['bucket'] + 1) / buckets)),
center=center,
)
)
return Isochrones(isochrones, response)
def _parse_isochrone_json(response):
if response is None: # pragma: no cover
return Isochrones()
isochrones = []
for idx, isochrone in enumerate(response['features']):
isochrones.append(
Isochrone(
geometry=isochrone['geometry']['coordinates'][0],
interval=isochrone['properties']['value'],
center=isochrone['properties']['center']
)
)
return Isochrones(isochrones=isochrones, raw=response)
def _parse_isochrone_json(response, intervals, locations):
if response is None: # pragma: no cover
return Isochrones()
return Isochrones(
[
Isochrone(
geometry=isochrone['geometry']['coordinates'],
interval=intervals[idx],
center=locations
) for idx, isochrone in enumerate(list(reversed(response['features'])))
], response
)