Skip to content

Commit 90d43d0

Browse files
Merge pull request #85 from maciej-wichowski/fix-route_v8_truck_attribute_depecated
[FIX] Deprecate `truck` parameter in route_v8
2 parents a9a623f + 00af7e7 commit 90d43d0

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

herepy/routing_api.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import sys
77
from typing import Dict, List, Optional, Union
8+
from warnings import warn
89

910
import requests
1011

@@ -370,6 +371,7 @@ def route_v8(
370371
return_fields: List[RoutingApiReturnField] = [RoutingApiReturnField.polyline],
371372
span_fields: Optional[List[RoutingApiSpanField]] = None,
372373
truck: Optional[Dict[str, List[str]]] = None,
374+
vehicle: Optional[Dict[str, List[str]]] = None,
373375
scooter: Optional[Dict[str, str]] = None,
374376
headers: Optional[dict] = None,
375377
) -> Optional[RoutingResponseV8]:
@@ -417,7 +419,9 @@ def route_v8(
417419
For example, attributes,length will enable the fields attributes and length in the route response.
418420
This parameter also requires that the polyline option is set within the return parameter.
419421
truck (Optional[Dict[str, List[str]]]):
420-
Comma-separated list of shipped hazardous goods in the vehicle.
422+
Deprecated. Use `vehicle` parameter.
423+
vehicle (Optional[Dict[str, List[str]]]):
424+
Comma-separated list of vehicle-specific parameters.
421425
Sample use of parameter: `{"shippedHazardousGoods": [explosive, gas, flammable]}`
422426
scooter (Optional[Dict[str, str]]):
423427
Scooter specific parameters.
@@ -469,7 +473,15 @@ def route_v8(
469473
if span_fields:
470474
data["spans"] = ",".join([field.__str__() for field in span_fields])
471475
if truck:
472-
data["truck"] = {key: ",".join(vals) for key, vals in truck.items()}
476+
warn(
477+
"'truck' parameter is deprecated in Routing API. Use 'vehicle' parameter instead.",
478+
DeprecationWarning,
479+
stacklevel=2,
480+
)
481+
if vehicle is None:
482+
vehicle = truck
483+
if vehicle:
484+
data["vehicle"] = {key: ",".join(vals) for key, vals in vehicle.items()}
473485
if scooter:
474486
data["scooter"] = scooter
475487

tests/test_routing_api.py

+28-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import codecs
44
import datetime
55
import unittest
6+
import pytest
67

78
import responses
89

@@ -1095,7 +1096,7 @@ def test_route_v8_success(self):
10951096
lang="tr-TR",
10961097
return_fields=[herepy.RoutingApiReturnField.polyline],
10971098
span_fields=[herepy.RoutingApiSpanField.walkAttributes],
1098-
truck={"shippedHazardousGoods": ["explosive", "gas"]},
1099+
vehicle={"shippedHazardousGoods": ["explosive", "gas"]},
10991100
scooter={"allowHighway": "true"},
11001101
)
11011102
self.assertTrue(response)
@@ -1129,7 +1130,7 @@ def test_route_v8_error_invalid_credentials(self):
11291130
lang="tr-TR",
11301131
return_fields=[herepy.RoutingApiReturnField.polyline],
11311132
span_fields=[herepy.RoutingApiSpanField.walkAttributes],
1132-
truck={"shippedHazardousGoods": ["explosive", "gas"]},
1133+
vehicle={"shippedHazardousGoods": ["explosive", "gas"]},
11331134
scooter={"allowHighway": "true"},
11341135
)
11351136

@@ -1190,7 +1191,7 @@ def test_route_v8_error_access_denied(self):
11901191
lang="tr-TR",
11911192
return_fields=[herepy.RoutingApiReturnField.polyline],
11921193
span_fields=[herepy.RoutingApiSpanField.walkAttributes],
1193-
truck={"shippedHazardousGoods": ["explosive", "gas"]},
1194+
vehicle={"shippedHazardousGoods": ["explosive", "gas"]},
11941195
scooter={"allowHighway": "true"},
11951196
)
11961197

@@ -1225,12 +1226,34 @@ def test_route_v8_url_parameters_multiple(self):
12251226
status=200,
12261227
match=[
12271228
responses.matchers.query_param_matcher(
1228-
{"truck[height]": "15000", "truck[width]": "3000"}, strict_match=False
1229+
{"vehicle[height]": "15000", "vehicle[width]": "3000"}, strict_match=False
12291230
)
12301231
],
12311232
)
12321233
self._api.route_v8(transport_mode=herepy.RoutingTransportMode.truck,
12331234
origin=[41.9798, -87.8801],
12341235
destination=[41.9043, -87.9216],
1235-
truck={"height": ["15000"], "width": ["3000"]}
1236+
vehicle={"height": ["15000"], "width": ["3000"]}
1237+
)
1238+
1239+
@responses.activate
1240+
@pytest.mark.filterwarnings("ignore:'truck' parameter is deprecated")
1241+
def test_route_v8_truck_parameter_deprecated(self):
1242+
responses.add(
1243+
responses.GET,
1244+
"https://router.hereapi.com/v8/routes",
1245+
"{}",
1246+
status=200,
1247+
match=[
1248+
responses.matchers.query_param_matcher(
1249+
{"vehicle[height]": "15000", "vehicle[width]": "3000"},
1250+
strict_match=False,
1251+
)
1252+
],
1253+
)
1254+
self._api.route_v8(
1255+
transport_mode=herepy.RoutingTransportMode.truck,
1256+
origin=[41.9798, -87.8801],
1257+
destination=[41.9043, -87.9216],
1258+
truck={"height": ["15000"], "width": ["3000"]},
12361259
)

0 commit comments

Comments
 (0)