def sources_to_targets_valhalla_test(): instance = MagicMock() instance.walking_speed = 1.12 valhalla = Valhalla(instance=instance, service_url='http://bob.com', costing_options={'bib': 'bom'}) origin = make_pt_object(type_pb2.ADDRESS, 2.439938, 48.572841) destination = make_pt_object(type_pb2.ADDRESS, 2.440548, 48.57307) response = { 'sources_to_targets': [[{ 'time': 42 }, { 'time': None }, { 'time': 1337 }]] } with requests_mock.Mocker() as req: req.post('http://bob.com/sources_to_targets', json=response, status_code=200) valhalla_response = valhalla.get_street_network_routing_matrix( instance, [origin], [destination, destination, destination], 'walking', 42, MOCKED_REQUEST) assert valhalla_response.rows[0].routing_response[0].duration == 42 assert valhalla_response.rows[0].routing_response[ 0].routing_status == response_pb2.reached assert valhalla_response.rows[0].routing_response[1].duration == -1 assert valhalla_response.rows[0].routing_response[ 1].routing_status == response_pb2.unknown assert valhalla_response.rows[0].routing_response[2].duration == 1337 assert valhalla_response.rows[0].routing_response[ 2].routing_status == response_pb2.reached
def sources_to_targets_valhalla_with_park_cost_test(): """ test with a parking cost, we add a different cost on car and bike and no cost on walking """ instance = MagicMock() instance.walking_speed = 1.12 valhalla = Valhalla( instance=instance, service_url='http://bob.com', costing_options={'bib': 'bom'}, mode_park_cost={ 'bike': 30, # 30s for the bike 'car': 5 * 60 # 5 mn for the car # and no park section for walking }, ) origin = make_pt_object(type_pb2.ADDRESS, 2.439938, 48.572841) destination = make_pt_object(type_pb2.ADDRESS, 2.440548, 48.57307) response = { 'sources_to_targets': [[{ 'time': 42 }, { 'time': None }, { 'time': 1337 }]] } with requests_mock.Mocker() as req: req.post('http://bob.com/sources_to_targets', json=response, status_code=200) # it changes nothing for walking valhalla_response = valhalla.get_street_network_routing_matrix( instance, [origin], [destination, destination, destination], mode='walking', max_duration=42, request=MOCKED_REQUEST, ) assert valhalla_response.rows[0].routing_response[0].duration == 42 assert valhalla_response.rows[0].routing_response[ 0].routing_status == response_pb2.reached assert valhalla_response.rows[0].routing_response[1].duration == -1 assert valhalla_response.rows[0].routing_response[ 1].routing_status == response_pb2.unknown assert valhalla_response.rows[0].routing_response[2].duration == 1337 assert valhalla_response.rows[0].routing_response[ 2].routing_status == response_pb2.reached # for bike every reached point have an additional 30s valhalla_response = valhalla.get_street_network_routing_matrix( instance, [origin], [destination, destination, destination], mode='bike', max_duration=42, request=MOCKED_REQUEST, ) assert valhalla_response.rows[0].routing_response[ 0].duration == 42 + 30 assert valhalla_response.rows[0].routing_response[ 0].routing_status == response_pb2.reached assert valhalla_response.rows[0].routing_response[1].duration == -1 assert valhalla_response.rows[0].routing_response[ 1].routing_status == response_pb2.unknown assert valhalla_response.rows[0].routing_response[ 2].duration == 1337 + 30 assert valhalla_response.rows[0].routing_response[ 2].routing_status == response_pb2.reached # for car every reached point have an additional 5mn valhalla_response = valhalla.get_street_network_routing_matrix( instance, [origin], [destination, destination, destination], mode='car', max_duration=42, request=MOCKED_REQUEST, ) assert valhalla_response.rows[0].routing_response[ 0].duration == 42 + 5 * 60 assert valhalla_response.rows[0].routing_response[ 0].routing_status == response_pb2.reached assert valhalla_response.rows[0].routing_response[1].duration == -1 assert valhalla_response.rows[0].routing_response[ 1].routing_status == response_pb2.unknown assert valhalla_response.rows[0].routing_response[ 2].duration == 1337 + 5 * 60 assert valhalla_response.rows[0].routing_response[ 2].routing_status == response_pb2.reached