Exemplo n.º 1
0
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)
Exemplo n.º 2
0
def direct_path_func_with_valid_response_valhalla_test():
    instance = MagicMock()
    instance.walking_speed = 1.12
    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)
    with requests_mock.Mocker() as req:
        url = 'http://bob.com/route?json={"costing_options": {"pedestrian": {"walking_speed": 4.032000000000001}, ' \
              '"bib": "bom"}, "locations": [{"lat": 48.572841, "type": "break", "lon": 2.439938}, ' \
              '{"lat": 48.57307, "type": "break", "lon": 2.440548}], "costing": "pedestrian", ' \
              '"directions_options": {"units": "kilometers"}}&api_key=None'
        req.get(url, json=resp_json)
        valhalla_response = valhalla.direct_path(
            'walking', origin, destination,
            str_to_time_stamp('20161010T152000'), True)
        assert valhalla_response.status_code == 200
        assert valhalla_response.response_type == response_pb2.ITINERARY_FOUND
        assert len(valhalla_response.journeys) == 1
        assert valhalla_response.journeys[0].duration == 6
        assert len(valhalla_response.journeys[0].sections) == 1
        assert valhalla_response.journeys[0].sections[
            0].type == response_pb2.STREET_NETWORK
        assert valhalla_response.journeys[0].sections[
            0].type == response_pb2.STREET_NETWORK
        assert valhalla_response.journeys[0].sections[0].length == 52
        assert valhalla_response.journeys[0].sections[
            0].destination == destination
Exemplo n.º 3
0
def direct_path_func_with_valid_response_valhalla_test():
    instance = MagicMock()
    instance.walking_speed = 1.12
    valhalla = Valhalla(instance=instance,
                        service_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)
    with requests_mock.Mocker() as req:
        req.post('http://bob.com/route', json=resp_json)
        valhalla_response = valhalla.direct_path(
            'walking', origin, destination,
            str_to_time_stamp('20161010T152000'), True, MOCKED_REQUEST)
        assert valhalla_response.status_code == 200
        assert valhalla_response.response_type == response_pb2.ITINERARY_FOUND
        assert len(valhalla_response.journeys) == 1
        assert valhalla_response.journeys[0].duration == 6
        assert len(valhalla_response.journeys[0].sections) == 1
        assert valhalla_response.journeys[0].sections[
            0].type == response_pb2.STREET_NETWORK
        assert valhalla_response.journeys[0].sections[
            0].type == response_pb2.STREET_NETWORK
        assert valhalla_response.journeys[0].sections[0].length == 52
        assert valhalla_response.journeys[0].sections[
            0].destination == destination
Exemplo n.º 4
0
def direct_path_func_with_status_code_400_response_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)
    fallback_extremity = PeriodExtremity(str_to_time_stamp('20161010T152000'), True)
    with requests_mock.Mocker() as req:
        with pytest.raises(TechnicalError) as excinfo:
            req.post('http://bob.com/route', json={'error_code': 42}, status_code=400)
            valhalla.direct_path('walking',
                                 origin,
                                 destination,
                                 fallback_extremity,
                                 MOCKED_REQUEST)
        assert str(excinfo.value) == '500: Internal Server Error'
        assert str(excinfo.value.data['message']) == 'Valhalla service unavailable, impossible to query : http://bob.com/route'
        assert str(excinfo.typename) == 'TechnicalError'
Exemplo n.º 5
0
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'
Exemplo n.º 6
0
def direct_path_func_with_no_response_valhalla_test():
    instance = MagicMock()
    instance.walking_speed = 1.12
    valhalla = Valhalla(instance=instance,
                        service_url='http://bob.com',
                        costing_options={'bib': 'bom'})
    origin = get_pt_object(type_pb2.ADDRESS, 2.439938, 48.572841)
    destination = get_pt_object(type_pb2.ADDRESS, 2.440548, 48.57307)
    with requests_mock.Mocker() as req:
        req.post('http://bob.com/route',
                 json={'error_code': 442},
                 status_code=400)
        valhalla_response = valhalla.direct_path(
            'walking', origin, destination,
            str_to_time_stamp('20161010T152000'), True, MOCKED_REQUEST)
        assert valhalla_response.status_code == 200
        assert valhalla_response.response_type == response_pb2.NO_SOLUTION
        assert len(valhalla_response.journeys) == 0