Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Deprecate truck parameter in route_v8 #85

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions herepy/routing_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import sys
from typing import Dict, List, Optional, Union
from warnings import warn

import requests

Expand Down Expand Up @@ -370,6 +371,7 @@ def route_v8(
return_fields: List[RoutingApiReturnField] = [RoutingApiReturnField.polyline],
span_fields: Optional[List[RoutingApiSpanField]] = None,
truck: Optional[Dict[str, List[str]]] = None,
vehicle: Optional[Dict[str, List[str]]] = None,
scooter: Optional[Dict[str, str]] = None,
headers: Optional[dict] = None,
) -> Optional[RoutingResponseV8]:
Expand Down Expand Up @@ -417,7 +419,9 @@ def route_v8(
For example, attributes,length will enable the fields attributes and length in the route response.
This parameter also requires that the polyline option is set within the return parameter.
truck (Optional[Dict[str, List[str]]]):
Comma-separated list of shipped hazardous goods in the vehicle.
Deprecated. Use `vehicle` parameter.
vehicle (Optional[Dict[str, List[str]]]):
Comma-separated list of vehicle-specific parameters.
Sample use of parameter: `{"shippedHazardousGoods": [explosive, gas, flammable]}`
scooter (Optional[Dict[str, str]]):
Scooter specific parameters.
Expand Down Expand Up @@ -469,7 +473,15 @@ def route_v8(
if span_fields:
data["spans"] = ",".join([field.__str__() for field in span_fields])
if truck:
data["truck"] = {key: ",".join(vals) for key, vals in truck.items()}
warn(
"'truck' parameter is deprecated in Routing API. Use 'vehicle' parameter instead.",
DeprecationWarning,
stacklevel=2,
)
if vehicle is None:
vehicle = truck
if vehicle:
data["vehicle"] = {key: ",".join(vals) for key, vals in vehicle.items()}
if scooter:
data["scooter"] = scooter

Expand Down
33 changes: 28 additions & 5 deletions tests/test_routing_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import codecs
import datetime
import unittest
import pytest

import responses

Expand Down Expand Up @@ -1095,7 +1096,7 @@ def test_route_v8_success(self):
lang="tr-TR",
return_fields=[herepy.RoutingApiReturnField.polyline],
span_fields=[herepy.RoutingApiSpanField.walkAttributes],
truck={"shippedHazardousGoods": ["explosive", "gas"]},
vehicle={"shippedHazardousGoods": ["explosive", "gas"]},
scooter={"allowHighway": "true"},
)
self.assertTrue(response)
Expand Down Expand Up @@ -1129,7 +1130,7 @@ def test_route_v8_error_invalid_credentials(self):
lang="tr-TR",
return_fields=[herepy.RoutingApiReturnField.polyline],
span_fields=[herepy.RoutingApiSpanField.walkAttributes],
truck={"shippedHazardousGoods": ["explosive", "gas"]},
vehicle={"shippedHazardousGoods": ["explosive", "gas"]},
scooter={"allowHighway": "true"},
)

Expand Down Expand Up @@ -1190,7 +1191,7 @@ def test_route_v8_error_access_denied(self):
lang="tr-TR",
return_fields=[herepy.RoutingApiReturnField.polyline],
span_fields=[herepy.RoutingApiSpanField.walkAttributes],
truck={"shippedHazardousGoods": ["explosive", "gas"]},
vehicle={"shippedHazardousGoods": ["explosive", "gas"]},
scooter={"allowHighway": "true"},
)

Expand Down Expand Up @@ -1225,12 +1226,34 @@ def test_route_v8_url_parameters_multiple(self):
status=200,
match=[
responses.matchers.query_param_matcher(
{"truck[height]": "15000", "truck[width]": "3000"}, strict_match=False
{"vehicle[height]": "15000", "vehicle[width]": "3000"}, strict_match=False
)
],
)
self._api.route_v8(transport_mode=herepy.RoutingTransportMode.truck,
origin=[41.9798, -87.8801],
destination=[41.9043, -87.9216],
truck={"height": ["15000"], "width": ["3000"]}
vehicle={"height": ["15000"], "width": ["3000"]}
)

@responses.activate
@pytest.mark.filterwarnings("ignore:'truck' parameter is deprecated")
def test_route_v8_truck_parameter_deprecated(self):
responses.add(
responses.GET,
"https://router.hereapi.com/v8/routes",
"{}",
status=200,
match=[
responses.matchers.query_param_matcher(
{"vehicle[height]": "15000", "vehicle[width]": "3000"},
strict_match=False,
)
],
)
self._api.route_v8(
transport_mode=herepy.RoutingTransportMode.truck,
origin=[41.9798, -87.8801],
destination=[41.9043, -87.9216],
truck={"height": ["15000"], "width": ["3000"]},
)
Loading