Exemple #1
0
def test_parsing_routes_with_bad_request(
        caplog, bad_request_google_directions_api_response):
    with caplog.at_level(logging.INFO):
        data = google_directions.parse_routes(
            bad_request_google_directions_api_response, 'ahmyHzvYkCvCuCdDcBrB')
    assert_semantically_equal(data, {})
    assert_logging_warning_caught_with_message_containing(
        caplog, 'Request was not successful.')
Exemple #2
0
def test_parsing_routes_with_a_bad_response(
        caplog, request_denied_google_directions_api_response,
        generated_request):
    with caplog.at_level(logging.INFO):
        data = google_directions.parse_routes(
            request_denied_google_directions_api_response,
            generated_request['path_polyline'])
    assert_semantically_equal(data, {})
    assert_logging_warning_caught_with_message_containing(
        caplog, 'Error message: The provided API key is invalid.')
Exemple #3
0
def test_parsing_routes_with_a_response_without_traffic_info(
        google_directions_api_response_without_traffic_info, generated_request,
        caplog):
    legs = google_directions_api_response_without_traffic_info.json(
    )['routes'][0]['legs']
    expected_speed = sum([leg['distance']['value'] for leg in legs]) / sum(
        [leg['duration']['value'] for leg in legs])

    data = google_directions.parse_routes(
        google_directions_api_response_without_traffic_info,
        generated_request['path_polyline'])
    assert_semantically_equal(data, {
        'google_speed': expected_speed,
        'google_polyline': 'ahmyHzvYkCvCuCdDcBrB'
    })
    assert_logging_warning_caught_with_message_containing(
        caplog, 'duration_in_traffic was not found')
def test_building_trips_dataframe_with_stops_accepts_backwards_compatibility(route, mocker, caplog):
    mocker.patch.object(Route, 'trips_with_stops_to_dataframe')
    route.trips_with_stops_to_dataframe(route.trips_to_dataframe())
    route.trips_with_stops_to_dataframe.assert_called_once()
    assert_logging_warning_caught_with_message_containing(caplog, '`route_trips_with_stops_to_dataframe` method is deprecated')