Ejemplo n.º 1
0
def test_matrix(valid_here_matrix):
    instance = MagicMock()
    instance.walking_speed = 1.12
    here = Here(instance=instance,
                service_base_url='bob.com',
                app_id='toto',
                app_code='tata')
    origin = make_pt_object(type_pb2.ADDRESS, 2.439938, 48.572841)
    destination = make_pt_object(type_pb2.ADDRESS, 2.440548, 48.57307)
    with requests_mock.Mocker() as req:
        req.get(requests_mock.ANY, json=valid_here_matrix, status_code=200)
        response = here.get_street_network_routing_matrix(
            [origin],
            [destination, destination, destination],
            mode='walking',
            max_duration=42,
            request={'datetime': str_to_time_stamp('20170621T174600')},
        )
        assert response.rows[0].routing_response[0].duration == 440
        assert response.rows[0].routing_response[
            0].routing_status == response_pb2.reached
        assert response.rows[0].routing_response[1].duration == -1
        assert response.rows[0].routing_response[
            1].routing_status == response_pb2.unreached
        assert response.rows[0].routing_response[2].duration == 701
        assert response.rows[0].routing_response[
            2].routing_status == response_pb2.reached
Ejemplo n.º 2
0
def here_basic_routing_test(valid_here_routing_response):
    origin = make_pt_object(type_pb2.POI, 2.439938, 48.572841)
    destination = make_pt_object(type_pb2.STOP_AREA, 2.440548, 48.57307)
    fallback_extremity = PeriodExtremity(str_to_time_stamp('20161010T152000'),
                                         True)
    response = Here._read_response(
        response=valid_here_routing_response,
        mode='walking',
        origin=origin,
        destination=destination,
        fallback_extremity=fallback_extremity,
        request={'datetime': str_to_time_stamp('20170621T174600')},
    )
    assert response.status_code == 200
    assert response.response_type == response_pb2.ITINERARY_FOUND
    assert len(response.journeys) == 1
    assert response.journeys[0].duration == 588
    assert len(response.journeys[0].sections) == 1
    section = response.journeys[0].sections[0]
    assert section.type == response_pb2.STREET_NETWORK
    assert section.length == 4012
    assert section.duration == 588
    assert section.destination == destination
    assert section.origin == origin
    assert section.begin_date_time == str_to_time_stamp('20161010T152000')
    assert section.end_date_time == section.begin_date_time + section.duration
Ejemplo n.º 3
0
def test_post_matrix(valid_matrix_post_resp):
    instance = MagicMock()
    instance.walking_speed = 1.12
    here = Here(instance=instance, service_base_url='bob.com', apiKey='toto')
    origin = make_pt_object(type_pb2.ADDRESS, 2.439938, 48.572841)
    destination = make_pt_object(type_pb2.ADDRESS, 2.440548, 48.57307)
    with requests_mock.Mocker() as req:
        req.post(requests_mock.ANY,
                 json=valid_matrix_post_resp,
                 status_code=202)
        post_resp = here.post_matrix_request(
            [origin],
            [destination, destination, destination],
            request={'datetime': str_to_time_stamp('20170621T174600')},
        )
        assert post_resp['status'] == 'accepted'
        assert post_resp['matrixId'] == 'ca6631e0-6e2a-48cd-a359-f3a4f21d0e54'
Ejemplo n.º 4
0
def test_matrix_timeout():
    instance = MagicMock()
    instance.walking_speed = 1.12
    here = Here(instance=instance,
                service_base_url='bob.com',
                app_id='toto',
                app_code='tata')
    origin = make_pt_object(type_pb2.ADDRESS, 2.439938, 48.572841)
    destination = make_pt_object(type_pb2.ADDRESS, 2.440548, 48.57307)
    with requests_mock.Mocker() as req:
        # a HERE timeout should raise a TechnicalError
        req.get(requests_mock.ANY, exc=requests.exceptions.Timeout)
        with pytest.raises(TechnicalError):
            here.get_street_network_routing_matrix(
                [origin], [destination, destination, destination],
                mode='walking',
                max_duration=42,
                request={'datetime': str_to_time_stamp('20170621T174600')})
Ejemplo n.º 5
0
def status_test():
    here = Here(
        instance=None,
        service_base_url='http://bob.com',
        id=u"tata-é$~#@\"*!'`§èû",
        modes=["walking", "bike", "car"],
        timeout=89,
    )
    status = here.status()
    assert len(status) == 6
    assert status['id'] == u'tata-é$~#@"*!\'`§èû'
    assert status['class'] == "Here"
    assert status['modes'] == ["walking", "bike", "car"]
    assert status['timeout'] == 89
    assert status['max_points'] == 100
    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
Ejemplo n.º 6
0
def test_feed_publisher():
    walking_service = Kraken(instance=None,
                             service_url='https://bob.com',
                             id=u"walking_service_id",
                             modes=["walking"])
    car_service = Here(instance=None,
                       service_base_url='https://bobobo.com',
                       id=u"car_service_id",
                       modes=["car"],
                       timeout=1)
    car_with_park = CarWithPark(instance=None,
                                walking_service=walking_service,
                                car_service=car_service)

    fp_car_service = car_service.feed_publisher()
    fp_car_with_park = car_with_park.feed_publisher()

    assert fp_car_service == fp_car_with_park
    assert fp_car_with_park.id == "here"
    assert fp_car_with_park.license == "Private"
    assert fp_car_with_park.name == "here"
    assert fp_car_with_park.url == "https://developer.here.com/terms-and-conditions"
Ejemplo n.º 7
0
def test_get_matrix(valid_matrix_get_resp, valid_matrix_post_resp):
    instance = MagicMock()
    instance.walking_speed = 1.12
    here = Here(instance=instance, service_base_url='bob.com', apiKey='toto')
    origin = make_pt_object(type_pb2.ADDRESS, 2.439938, 48.572841)
    destination = make_pt_object(type_pb2.ADDRESS, 2.440548, 48.57307)
    with requests_mock.Mocker() as req:
        req.get(requests_mock.ANY, json=valid_matrix_get_resp, status_code=200)
        response = here.get_matrix_response(
            [origin], [destination, destination, destination, destination],
            post_resp=valid_matrix_post_resp)
        assert response.rows[0].routing_response[0].duration == 7146
        assert response.rows[0].routing_response[
            0].routing_status == response_pb2.reached
        assert response.rows[0].routing_response[1].duration == 7434
        assert response.rows[0].routing_response[
            1].routing_status == response_pb2.reached
        assert response.rows[0].routing_response[2].duration == 12927
        assert response.rows[0].routing_response[
            2].routing_status == response_pb2.reached
        assert response.rows[0].routing_response[3].duration == 14838
        assert response.rows[0].routing_response[
            3].routing_status == response_pb2.reached
Ejemplo n.º 8
0
def status_test():
    here = Here(
        instance=None,
        service_base_url='http://bob.com',
        id=u"tata-é$~#@\"*!'`§èû",
        modes=["walking", "bike", "car"],
        timeout=89,
    )
    status = here.status()
    assert len(status) == 11
    assert status['id'] == u'tata-é$~#@"*!\'`§èû'
    assert status['class'] == "Here"
    assert status['modes'] == ["walking", "bike", "car"]
    assert status['timeout'] == 89
    assert status['matrix_type'] == "simple_matrix"
    assert status['max_matrix_points'] == 100
    assert status['realtime_traffic'] == "enabled"
    assert status['language'] == "en-gb"
    assert status['engine_type'] == "diesel"
    assert status['engine_average_consumption'] == 7
    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
Ejemplo n.º 9
0
def here_basic_routing_test(valid_here_routing_response):
    origin = make_pt_object(type_pb2.POI, 2.439938, 48.572841)
    destination = make_pt_object(type_pb2.STOP_AREA, 2.440548, 48.57307)

    # for a beginning fallback
    fallback_extremity = PeriodExtremity(str_to_time_stamp('20161010T152000'),
                                         True)
    response = Here._read_response(
        response=valid_here_routing_response,
        mode='walking',
        origin=origin,
        destination=destination,
        fallback_extremity=fallback_extremity,
        request={'datetime': str_to_time_stamp('20161010T152000')},
        direct_path_type=StreetNetworkPathType.BEGINNING_FALLBACK,
    )
    assert response.status_code == 200
    assert response.response_type == response_pb2.ITINERARY_FOUND
    assert len(response.journeys) == 1
    assert response.journeys[0].duration == 1468
    assert len(response.journeys[0].sections) == 1
    section = response.journeys[0].sections[0]
    assert section.type == response_pb2.STREET_NETWORK
    assert section.length == 21919
    assert section.duration == 1468
    assert section.destination == destination
    assert section.origin == origin
    assert section.begin_date_time == str_to_time_stamp('20161010T152000')
    assert section.end_date_time == section.begin_date_time + section.duration
    assert section.base_begin_date_time == str_to_time_stamp(
        '20161010T152000') + (1468 - 1344)
    assert section.base_end_date_time == section.begin_date_time + section.duration
    # dynamic_speed
    dynamic_speeds = section.street_network.dynamic_speeds
    assert len(dynamic_speeds) == 6
    first_ds = dynamic_speeds[0]
    assert round(first_ds.base_speed, 2) == 13.89
    assert round(first_ds.traffic_speed, 2) == 11.94
    assert first_ds.geojson_offset == 0
    last_ds = dynamic_speeds[5]
    assert round(last_ds.base_speed, 2) == 13.89
    assert round(last_ds.traffic_speed, 2) == 13.89
    assert last_ds.geojson_offset == 769

    # for a direct path and clockiwe == True
    response = Here._read_response(
        response=valid_here_routing_response,
        mode='walking',
        origin=origin,
        destination=destination,
        fallback_extremity=fallback_extremity,
        request={'datetime': str_to_time_stamp('20161010T152000')},
        direct_path_type=StreetNetworkPathType.DIRECT,
    )
    assert response.status_code == 200
    assert response.response_type == response_pb2.ITINERARY_FOUND
    assert len(response.journeys) == 1
    assert len(response.journeys[0].sections) == 1
    section = response.journeys[0].sections[0]
    assert section.begin_date_time == str_to_time_stamp('20161010T152000')
    assert section.end_date_time == section.begin_date_time + section.duration
    assert section.base_begin_date_time == str_to_time_stamp(
        '20161010T152000') + (1468 - 1344)
    assert section.base_end_date_time == section.begin_date_time + section.duration

    # for a ending fallback
    fallback_extremity = PeriodExtremity(str_to_time_stamp('20161010T152000'),
                                         True)
    response = Here._read_response(
        response=valid_here_routing_response,
        mode='walking',
        origin=origin,
        destination=destination,
        fallback_extremity=fallback_extremity,
        request={'datetime': str_to_time_stamp('20161010T152000')},
        direct_path_type=StreetNetworkPathType.ENDING_FALLBACK,
    )
    assert response.status_code == 200
    assert response.response_type == response_pb2.ITINERARY_FOUND
    assert len(response.journeys) == 1
    section = response.journeys[0].sections[0]
    assert section.begin_date_time == str_to_time_stamp(
        '20161010T152000') - section.duration
    assert section.end_date_time == str_to_time_stamp('20161010T152000')
    assert section.base_begin_date_time == str_to_time_stamp(
        '20161010T152000') - section.duration
    assert section.base_end_date_time == section.end_date_time - (1468 - 1344)

    # for a direct path and clockiwe == False
    fallback_extremity = PeriodExtremity(str_to_time_stamp('20161010T152000'),
                                         False)
    response = Here._read_response(
        response=valid_here_routing_response,
        mode='walking',
        origin=origin,
        destination=destination,
        fallback_extremity=fallback_extremity,
        request={'datetime': str_to_time_stamp('20161010T152000')},
        direct_path_type=StreetNetworkPathType.DIRECT,
    )
    assert response.status_code == 200
    assert response.response_type == response_pb2.ITINERARY_FOUND
    assert len(response.journeys) == 1
    assert len(response.journeys[0].sections) == 1
    section = response.journeys[0].sections[0]
    assert section.end_date_time == str_to_time_stamp('20161010T152000')
    assert section.begin_date_time == section.end_date_time - section.duration
    assert section.base_end_date_time == section.end_date_time
    assert section.base_begin_date_time == section.base_end_date_time - section.duration + (
        1468 - 1344)

    # for a beginning fallback and clockiwe == False
    fallback_extremity = PeriodExtremity(str_to_time_stamp('20161010T152000'),
                                         False)
    response = Here._read_response(
        response=valid_here_routing_response,
        mode='walking',
        origin=origin,
        destination=destination,
        fallback_extremity=fallback_extremity,
        request={'datetime': str_to_time_stamp('20161010T152000')},
        direct_path_type=StreetNetworkPathType.BEGINNING_FALLBACK,
    )
    assert response.status_code == 200
    assert response.response_type == response_pb2.ITINERARY_FOUND
    assert len(response.journeys) == 1
    assert len(response.journeys[0].sections) == 1
    section = response.journeys[0].sections[0]
    assert section.end_date_time == str_to_time_stamp('20161010T152000')
    assert section.begin_date_time == section.end_date_time - section.duration
    assert section.base_end_date_time == section.end_date_time
    assert section.base_begin_date_time == section.base_end_date_time - section.duration + (
        1468 - 1344)