Beispiel #1
0
def direct_path_func_without_response_valhalla_test():
    instance = MagicMock()
    valhalla = Valhalla(instance=instance, service_url='http://bob.com', costing_options={'bib': 'bom'})
    valhalla.breaker = MagicMock()
    valhalla._call_valhalla = MagicMock(return_value=None)
    valhalla._make_request_arguments = MagicMock(return_value=None)
    with pytest.raises(TechnicalError) as excinfo:
        valhalla.direct_path_with_fp(None, None, None, None, None, None, None)
    assert '500 Internal Server Error' in str(excinfo.value)
    assert 'TechnicalError' == str(excinfo.typename)
Beispiel #2
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 = 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:
        req.post('http://bob.com/route', json=resp_json)
        valhalla_response = valhalla.direct_path_with_fp(
            instance, 'walking', origin, destination, fallback_extremity,
            MOCKED_REQUEST, None)
        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
Beispiel #3
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_with_fp(
                instance, 'walking', origin, destination, fallback_extremity, MOCKED_REQUEST, None, None
            )
        assert '500 Internal Server Error' in str(excinfo.value)
        assert (
            str(excinfo.value.data['message'])
            == 'Valhalla service unavailable, impossible to query : http://bob.com/route'
        )
        assert str(excinfo.typename) == 'TechnicalError'
Beispiel #4
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 = 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:
        req.post('http://bob.com/route', json={'error_code': 442}, status_code=400)
        valhalla_response = valhalla.direct_path_with_fp(
            instance, 'walking', origin, destination, fallback_extremity, MOCKED_REQUEST, None, None
        )
        assert valhalla_response.status_code == 200
        assert valhalla_response.response_type == response_pb2.NO_SOLUTION
        assert len(valhalla_response.journeys) == 0