def get_response_with_0_duration_park_test(): """even if the mode_park_cost is 0, if it's not None we got a park section""" resp_json = response_valid() origin = make_pt_object(type_pb2.ADDRESS, 2.439938, 48.572841) destination = make_pt_object(type_pb2.ADDRESS, 2.440548, 48.57307) fallback_extremity = PeriodExtremity(str_to_time_stamp('20161010T152000'), True) response = Valhalla._get_response( resp_json, 'walking', origin, destination, fallback_extremity, StreetNetworkPathType.BEGINNING_FALLBACK, mode_park_cost=0, ) assert response.status_code == 200 assert response.response_type == response_pb2.ITINERARY_FOUND assert len(response.journeys) == 1 assert response.journeys[0].duration == 6 assert len(response.journeys[0].sections) == 2 assert response.journeys[0].sections[0].type == response_pb2.STREET_NETWORK assert response.journeys[0].sections[0].length == 52 assert response.journeys[0].sections[0].duration == 6 assert response.journeys[0].sections[0].destination == destination assert response.journeys[0].sections[1].type == response_pb2.PARK assert response.journeys[0].sections[1].length == 0 assert response.journeys[0].sections[ 1].duration == 0 # very quick park section assert response.journeys[0].sections[1].origin == destination assert response.journeys[0].sections[1].destination == destination
def get_response_with_leave_parking_test(): resp_json = response_valid() origin = make_pt_object(type_pb2.ADDRESS, 2.439938, 48.572841) destination = make_pt_object(type_pb2.ADDRESS, 2.440548, 48.57307) fallback_extremity = PeriodExtremity(str_to_time_stamp('20161010T152000'), True) response = Valhalla._get_response( resp_json, 'walking', origin, destination, fallback_extremity, StreetNetworkPathType.ENDING_FALLBACK, mode_park_cost=5 * 60, ) assert response.status_code == 200 assert response.response_type == response_pb2.ITINERARY_FOUND assert len(response.journeys) == 1 assert response.journeys[0].duration == 6 + 5 * 60 assert len(response.journeys[0].sections) == 2 assert response.journeys[0].sections[0].type == response_pb2.LEAVE_PARKING assert response.journeys[0].sections[0].length == 0 assert response.journeys[0].sections[0].duration == 5 * 60 assert response.journeys[0].sections[0].origin == origin assert response.journeys[0].sections[0].destination == origin assert response.journeys[0].sections[1].type == response_pb2.STREET_NETWORK assert response.journeys[0].sections[1].length == 52 assert response.journeys[0].sections[1].duration == 6 assert response.journeys[0].sections[1].destination == destination
def get_response_func_with_unknown_exception_test(): resp_json = response_valid() origin = make_pt_object(type_pb2.ADDRESS, 2.439938, 48.572841) destination = make_pt_object(type_pb2.ADDRESS, 2.440548, 48.57307) fallback_extremity = PeriodExtremity(str_to_time_stamp('20161010T152000'), True) response = Valhalla._get_response(resp_json, 'walking', origin, destination, fallback_extremity) assert response.status_code == 200 assert response.response_type == response_pb2.ITINERARY_FOUND assert len(response.journeys) == 1 assert response.journeys[0].duration == 6 assert len(response.journeys[0].sections) == 1 assert response.journeys[0].sections[0].type == response_pb2.STREET_NETWORK assert response.journeys[0].sections[0].type == response_pb2.STREET_NETWORK assert response.journeys[0].sections[0].length == 52 assert response.journeys[0].sections[0].destination == destination
def get_response_func_with_unknown_exception_test(): instance = MagicMock() valhalla = Valhalla(instance=instance, url='http://bob.com', costing_options={'bib': 'bom'}) resp_json = response_valid() origin = get_pt_object(type_pb2.ADDRESS, 2.439938, 48.572841) destination = get_pt_object(type_pb2.ADDRESS, 2.440548, 48.57307) response = valhalla._get_response(resp_json, 'walking', origin, destination, str_to_time_stamp('20161010T152000')) assert response.status_code == 200 assert response.response_type == response_pb2.ITINERARY_FOUND assert len(response.journeys) == 1 assert response.journeys[0].duration == 6 assert len(response.journeys[0].sections) == 1 assert response.journeys[0].sections[0].type == response_pb2.STREET_NETWORK assert response.journeys[0].sections[0].type == response_pb2.STREET_NETWORK assert response.journeys[0].sections[0].length == 52 assert response.journeys[0].sections[0].destination == destination