def format_url_func_invalid_mode_test(): instance = MagicMock() valhalla = Valhalla(instance=instance, url='http://bob.com', costing_options={'bib': 'bom'}) with pytest.raises(InvalidArguments) as excinfo: origin = get_pt_object(type_pb2.ADDRESS, 1.0, 1.0) destination = get_pt_object(type_pb2.ADDRESS, 2.0, 2.0) valhalla._format_url("bob", origin, destination) assert '400: Bad Request' == str(excinfo.value) assert 'InvalidArguments' == str(excinfo.typename)
def direct_path_func_without_response_valhalla_test(): instance = MagicMock() valhalla = Valhalla(instance=instance, url='http://bob.com', costing_options={'bib': 'bom'}) valhalla.breaker = MagicMock() valhalla._call_valhalla = MagicMock(return_value=None) valhalla._format_url = MagicMock(return_value=valhalla.service_url) with pytest.raises(TechnicalError) as excinfo: valhalla.direct_path(None, None, None, None, None) assert '500: Internal Server Error' == str(excinfo.value) assert 'TechnicalError' == str(excinfo.typename)
def direct_path_func_with_status_code_400_response_valhalla_test(): instance = MagicMock() valhalla = Valhalla(instance=instance, url='http://bob.com', costing_options={'bib': 'bom'}) valhalla.breaker = MagicMock() response = requests.Response() response.status_code = 400 response.url = valhalla.service_url valhalla._call_valhalla = MagicMock(return_value=response) valhalla._format_url = MagicMock(return_value=valhalla.service_url) nav_resp = valhalla.direct_path(None, None, None, None, None) assert response.status_code == nav_resp.status_code assert nav_resp.error.message == 'Valhalla service unavailable, impossible to query : http://bob.com'
def format_url_func_with_car_mode_test(): instance = MagicMock() instance.walking_speed = 1 instance.bike_speed = 2 origin = get_pt_object(type_pb2.ADDRESS, 1.0, 1.0) destination = get_pt_object(type_pb2.ADDRESS, 2.0, 2.0) valhalla = Valhalla(instance=instance, url='http://bob.com', costing_options={'bib': 'bom'}) valhalla.costing_options = None assert valhalla._format_url("car", origin, destination) == 'http://bob.com/route?json=' \ '{"locations": [{"lat": 1.0, "type": "break", "lon": 1.0}, ' \ '{"lat": 2.0, "type": "break", "lon": 2.0}], "costing": "auto", ' \ '"directions_options": {"units": "kilometers"}}&' \ 'api_key=None'