From 3ea22a58148745d507c4508011b674ba8db087e2 Mon Sep 17 00:00:00 2001 From: kovacsbalu Date: Thu, 14 Feb 2019 09:04:31 +0100 Subject: [PATCH] Fix empty vehicle type --- WazeRouteCalculator/WazeRouteCalculator.py | 3 ++- tests.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/WazeRouteCalculator/WazeRouteCalculator.py b/WazeRouteCalculator/WazeRouteCalculator.py index 400587e..766d13e 100644 --- a/WazeRouteCalculator/WazeRouteCalculator.py +++ b/WazeRouteCalculator/WazeRouteCalculator.py @@ -88,7 +88,6 @@ def get_route(self, npaths=1, time_delta=0): url_options = { "from": "x:%s y:%s" % (self.start_coords["lon"], self.start_coords["lat"]), "to": "x:%s y:%s" % (self.end_coords["lon"], self.end_coords["lat"]), - "vehicleType": self.vehicle_type, "at": time_delta, "returnJSON": "true", "returnGeometries": "true", @@ -97,6 +96,8 @@ def get_route(self, npaths=1, time_delta=0): "nPaths": npaths, "options": "AVOID_TRAILS:t", } + if self.vehicle_type: + url_options["vehicleType"] = self.vehicle_type for routing_srv in routing_servers: response = requests.get(self.WAZE_URL + routing_srv, params=url_options, headers=self.HEADERS) diff --git a/tests.py b/tests.py index 4ec28b9..f13fe7c 100644 --- a/tests.py +++ b/tests.py @@ -353,3 +353,13 @@ def test_vehicle_motor(self): route = wrc.WazeRouteCalculator(from_address, to_address, vehicle_type='MOTORCYCLE') route.get_route() assert 'vehicletype=motorcycle' in req.last_request.query + + def test_empty_vehicle_type(self): + from_address = 'From address' + to_address = 'To address' + with requests_mock.mock() as m: + m.get(self.address_req, text=self.address_to_coords_response) + req = m.get(self.routing_req, text=self.routing_response) + route = wrc.WazeRouteCalculator(from_address, to_address) + route.get_route() + assert 'vehicletype' not in req.last_request.query