Esempio n. 1
0
def call_geovelo_func_with_circuit_breaker_error_test():
    instance = MagicMock()
    geovelo = Geovelo(instance=instance, service_url='http://bob.com')
    geovelo.breaker = MagicMock()
    geovelo.breaker.call = MagicMock(
        side_effect=pybreaker.CircuitBreakerError())
    assert geovelo._call_geovelo(geovelo.service_url) == None
Esempio n. 2
0
def isochrone_geovelo_test():
    instance = MagicMock()
    geovelo = Geovelo(instance=instance, service_url='http://bob.com')
    resp_json = isochrone_response_valid()

    origins = [
        make_pt_object(type_pb2.ADDRESS, lon=2, lat=48.2, uri='refStart1')
    ]
    destinations = [
        make_pt_object(type_pb2.ADDRESS, lon=3, lat=48.3, uri='refEnd1'),
        make_pt_object(type_pb2.ADDRESS, lon=4, lat=48.4, uri='refEnd2'),
    ]

    with requests_mock.Mocker() as req:
        req.post('http://bob.com/api/v2/routes_m2m',
                 json=resp_json,
                 status_code=200)
        geovelo_response = geovelo.get_street_network_routing_matrix(
            instance, origins, destinations, 'bike', 13371337, MOCKED_REQUEST)
        assert geovelo_response.rows[0].routing_response[0].duration == 1051
        assert geovelo_response.rows[0].routing_response[
            0].routing_status == response_pb2.reached
        assert geovelo_response.rows[0].routing_response[1].duration == 1656
        assert geovelo_response.rows[0].routing_response[
            1].routing_status == response_pb2.reached
Esempio n. 3
0
def call_geovelo_func_with_unknown_exception_test():
    instance = MagicMock()
    geovelo = Geovelo(instance=instance,
                      service_url='http://bob.com')
    geovelo.breaker = MagicMock()
    geovelo.breaker.call = MagicMock(side_effect=ValueError())
    assert geovelo._call_geovelo(geovelo.service_url) == None
Esempio n. 4
0
def direct_path_geovelo_zero_test():
    instance = MagicMock()
    geovelo = Geovelo(instance=instance, service_url='http://bob.com')
    resp_json = direct_path_response_zero()

    origin = make_pt_object(type_pb2.ADDRESS, lon=2, lat=48, uri='refStart1')
    destination = make_pt_object(type_pb2.ADDRESS, lon=2, lat=48, uri='refEnd1')
    fallback_extremity = PeriodExtremity(str_to_time_stamp('20161010T152000'), False)
    with requests_mock.Mocker() as req:
        req.post(
            'http://bob.com/api/v2/computedroutes?instructions=true&elevations=true&geometry=true'
            '&single_result=true&bike_stations=false&objects_as_ids=true&',
            json=resp_json,
        )
        geovelo_resp = geovelo.direct_path_with_fp(
            instance, 'bike', origin, destination, fallback_extremity, MOCKED_REQUEST, None, None
        )
        assert geovelo_resp.status_code == 200
        assert geovelo_resp.response_type == response_pb2.ITINERARY_FOUND
        assert len(geovelo_resp.journeys) == 1
        assert geovelo_resp.journeys[0].duration == 0
        assert len(geovelo_resp.journeys[0].sections) == 1
        assert geovelo_resp.journeys[0].arrival_date_time == str_to_time_stamp('20161010T152000')
        assert geovelo_resp.journeys[0].departure_date_time == str_to_time_stamp('20161010T152000')
        assert geovelo_resp.journeys[0].sections[0].type == response_pb2.STREET_NETWORK
        assert geovelo_resp.journeys[0].sections[0].type == response_pb2.STREET_NETWORK
        assert geovelo_resp.journeys[0].sections[0].duration == 0
        assert geovelo_resp.journeys[0].sections[0].length == 0
        assert geovelo_resp.journeys[0].sections[0].origin == origin
        assert geovelo_resp.journeys[0].sections[0].destination == destination
        assert geovelo_resp.journeys[0].sections[0].street_network.path_items[0].name == "voie pietonne"
        assert geovelo_resp.journeys[0].sections[0].street_network.path_items[0].direction == 0
        assert geovelo_resp.journeys[0].sections[0].street_network.path_items[0].length == 0
        assert geovelo_resp.journeys[0].sections[0].street_network.path_items[0].duration == 0
Esempio n. 5
0
def call_geovelo_func_with_unknown_exception_test():
    instance = MagicMock()
    geovelo = Geovelo(instance=instance, service_url='http://bob.com')
    geovelo.breaker = MagicMock()
    geovelo.breaker.call = MagicMock(side_effect=ValueError())
    with pytest.raises(jormungandr.exceptions.GeoveloTechnicalError):
        geovelo._call_geovelo(geovelo.service_url)
Esempio n. 6
0
def call_geovelo_func_with_circuit_breaker_error_test():
    instance = MagicMock()
    geovelo = Geovelo(instance=instance, service_url='http://bob.com')
    geovelo.breaker = MagicMock()
    geovelo.breaker.call = MagicMock(side_effect=pybreaker.CircuitBreakerError())
    with pytest.raises(jormungandr.exceptions.GeoveloTechnicalError):
        geovelo._call_geovelo(geovelo.service_url)
Esempio n. 7
0
def direct_path_geovelo_test():
    instance = MagicMock()
    geovelo = Geovelo(instance=instance, service_url='http://bob.com')
    resp_json = direct_path_response_valid()

    origin = make_pt_object(type_pb2.ADDRESS, lon=2, lat=48.2, uri='refStart1')
    destination = make_pt_object(type_pb2.ADDRESS,
                                 lon=3,
                                 lat=48.3,
                                 uri='refEnd1')
    fallback_extremity = PeriodExtremity(str_to_time_stamp('20161010T152000'),
                                         False)
    with requests_mock.Mocker() as req:
        req.post(
            'http://bob.com/api/v2/computedroutes?instructions=true&elevations=false&geometry=true'
            '&single_result=true&bike_stations=false&objects_as_ids=true&',
            json=resp_json)
        geovelo_resp = geovelo.direct_path_with_fp('bike', origin, destination,
                                                   fallback_extremity, None,
                                                   None)
        assert geovelo_resp.status_code == 200
        assert geovelo_resp.response_type == response_pb2.ITINERARY_FOUND
        assert len(geovelo_resp.journeys) == 1
        assert geovelo_resp.journeys[0].duration == 3155  # 52min35s
        assert len(geovelo_resp.journeys[0].sections) == 1
        assert geovelo_resp.journeys[0].arrival_date_time == str_to_time_stamp(
            '20161010T152000')
        assert geovelo_resp.journeys[
            0].departure_date_time == str_to_time_stamp('20161010T142725')
        assert geovelo_resp.journeys[0].sections[
            0].type == response_pb2.STREET_NETWORK
        assert geovelo_resp.journeys[0].sections[
            0].type == response_pb2.STREET_NETWORK
        assert geovelo_resp.journeys[0].sections[0].duration == 3155
        assert geovelo_resp.journeys[0].sections[0].length == 11393
        assert geovelo_resp.journeys[0].sections[0].street_network.coordinates[
            2].lon == 2.314258
        assert geovelo_resp.journeys[0].sections[0].street_network.coordinates[
            2].lat == 48.887428
        assert geovelo_resp.journeys[0].sections[0].origin == origin
        assert geovelo_resp.journeys[0].sections[0].destination == destination
        assert geovelo_resp.journeys[0].sections[0].street_network.path_items[
            1].name == "Rue Jouffroy d'Abbans"
        assert geovelo_resp.journeys[0].sections[0].street_network.path_items[
            1].direction == 0
        assert geovelo_resp.journeys[0].sections[0].street_network.path_items[
            1].length == 40
        assert geovelo_resp.journeys[0].sections[0].street_network.path_items[
            1].duration == 144
Esempio n. 8
0
def make_request_arguments_bike_details_test():
    """
    Check that the bikeDetails is well formatted for the request with right averageSpeed value
    """
    instance = MagicMock()
    geovelo = Geovelo(instance=instance, service_url='http://bob.com')
    data = geovelo._make_request_arguments_bike_details(bike_speed_mps=3.33)
    assert ujson.loads(ujson.dumps(data)) == ujson.loads(
        '''{"profile": "MEDIAN", "averageSpeed": 12,
    "bikeType": "TRADITIONAL"}''')

    data = geovelo._make_request_arguments_bike_details(bike_speed_mps=4.1)
    assert ujson.loads(ujson.dumps(data)) == ujson.loads(
        '''{"profile": "MEDIAN", "averageSpeed": 15,
    "bikeType": "TRADITIONAL"}''')
Esempio n. 9
0
def get_matrix_test():
    resp_json = isochrone_response_valid()
    matrix = Geovelo._get_matrix(resp_json)
    assert matrix.rows[0].routing_response[0].duration == 1051
    assert matrix.rows[0].routing_response[0].routing_status == response_pb2.reached
    assert matrix.rows[0].routing_response[1].duration == 1656
    assert matrix.rows[0].routing_response[1].routing_status == response_pb2.reached
Esempio n. 10
0
def distances_durations_test():
    """
    Check that the response from geovelo is correctly formatted with 'distances' and 'durations' sections
    """
    instance = MagicMock()
    geovelo = Geovelo(instance=instance, service_url='http://bob.com')
    resp_json = direct_path_response_valid()

    origin = make_pt_object(type_pb2.ADDRESS, lon=2, lat=48.2, uri='refStart1')
    destination = make_pt_object(type_pb2.ADDRESS, lon=3, lat=48.3, uri='refEnd1')
    fallback_extremity = PeriodExtremity(str_to_time_stamp('20161010T152000'), True)

    proto_resp = geovelo._get_response(resp_json, origin, destination, fallback_extremity)
    assert proto_resp.journeys[0].durations.total == 3155
    assert proto_resp.journeys[0].durations.bike == 3155
    assert proto_resp.journeys[0].distances.bike == 11393.0
Esempio n. 11
0
def status_test():
    geovelo = Geovelo(
        instance=None,
        service_url='http://bob.com',
        id=u"tata-é$~#@\"*!'`§èû",
        modes=["walking", "bike", "car"],
        timeout=56,
    )
    status = geovelo.status()
    assert len(status) == 5
    assert status['id'] == u'tata-é$~#@"*!\'`§èû'
    assert status['class'] == "Geovelo"
    assert status['modes'] == ["walking", "bike", "car"]
    assert status['timeout'] == 56
    assert len(status['circuit_breaker']) == 3
    assert status['circuit_breaker']['current_state'] == 'closed'
    assert status['circuit_breaker']['fail_counter'] == 0
    assert status['circuit_breaker']['reset_timeout'] == 60
Esempio n. 12
0
def make_data_test():
    origins = [make_pt_object(type_pb2.ADDRESS, lon=2, lat=48.2, uri='refStart1')]
    destinations = [make_pt_object(type_pb2.ADDRESS, lon=3, lat=48.3, uri='refEnd1'),
                    make_pt_object(type_pb2.ADDRESS, lon=4, lat=48.4, uri='refEnd2')]
    data = Geovelo._make_request_arguments_isochrone(origins, destinations)
    assert json.loads(json.dumps(data)) == json.loads('''{
            "starts":[[48.2,2, "refStart1"]],
            "ends":[[48.3,3, "refEnd1"],
                    [48.4,4, "refEnd2"]]
        }''')
Esempio n. 13
0
def make_data_test():
    origins = [make_pt_object(type_pb2.ADDRESS, lon=2, lat=48.2, uri='refStart1')]
    destinations = [
        make_pt_object(type_pb2.ADDRESS, lon=3, lat=48.3, uri='refEnd1'),
        make_pt_object(type_pb2.ADDRESS, lon=4, lat=48.4, uri='refEnd2'),
    ]
    data = Geovelo._make_request_arguments_isochrone(origins, destinations)
    assert ujson.loads(ujson.dumps(data)) == ujson.loads(
        '''{
            "starts": [[48.2, 2.0, null]], "ends": [[48.3, 3.0, null], [48.4, 4.0, null]],
            "transportMode": "BIKE",
            "bikeDetails": {"profile": "MEDIAN", "averageSpeed": 12, "bikeType": "TRADITIONAL"}}'''
    )
Esempio n. 14
0
def sort_by_mode_test():
    # Sort order Train, RapidTransit, Metro, Tramway, Car, Bus
    points = [
        make_pt_object_with_sp_mode(lon=3, lat=48.3, uri='ref_Bus', mode_uri='physical_mode:Bus'),
        make_pt_object_with_sp_mode(lon=4, lat=48.4, uri='ref_Metro', mode_uri='physical_mode:Metro'),
        make_pt_object_with_sp_mode(lon=5, lat=48.5, uri='ref_Tram', mode_uri='physical_mode:Tramway'),
        make_pt_object_with_sp_mode(lon=6, lat=48.6, uri='ref_Car', mode_uri='physical_mode:Car'),
        make_pt_object_with_sp_mode(lon=6, lat=48.6, uri='ref_NoMode'),
        make_pt_object_with_sp_mode(lon=7, lat=48.7, uri='ref_Train', mode_uri='physical_mode:Train'),
        make_pt_object_with_sp_mode(lon=8, lat=48.8, uri='ref_Rapid', mode_uri='physical_mode:RapidTransit'),
    ]
    points = Geovelo.sort_by_mode(points)
    points[0].uri = 'ref_Train'
    points[1].uri = 'ref_Rapid'
    points[2].uri = 'ref_Metro'
    points[3].uri = 'ref_Tram'
    points[4].uri = 'ref_Car'
    points[5].uri = 'ref_Bus'
    points[6].uri = 'ref_NoMode'
Esempio n. 15
0
def pt_object_summary_test():
    summary = Geovelo._pt_object_summary_isochrone(
        make_pt_object(type_pb2.ADDRESS, lon=1.12, lat=13.15, uri='toto'))
    assert summary == [13.15, 1.12, None]