From d0612f548a086f43d3f34d260960412711c809cd Mon Sep 17 00:00:00 2001 From: James Burgess Date: Thu, 16 May 2024 12:20:44 +0000 Subject: [PATCH 1/2] Add handling of forbidden errors from here api response --- herepy/routing_api.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/herepy/routing_api.py b/herepy/routing_api.py index 782a8a4..216e8ac 100644 --- a/herepy/routing_api.py +++ b/herepy/routing_api.py @@ -987,6 +987,8 @@ def error_from_routing_service_error(json_data): # V8 error handling if "error" in json_data and json_data["error"] == "Unauthorized": return InvalidCredentialsError(json_data["error_description"]) + elif "error" in json_data and json_data["error"] == "Forbidden": + return InvalidCredentialsError(json_data["error_description"]) elif "status" in json_data: error_msg = str.format( "Cause: {0}; Action: {1}", json_data["cause"], json_data["action"] From f12eecba51c9ae6b25296e549d36df7ccd179381 Mon Sep 17 00:00:00 2001 From: James Burgess Date: Fri, 17 May 2024 09:51:18 +0000 Subject: [PATCH 2/2] Add in test case for forbidden response from api --- .../routing_error_forbidden_credentials.json | 4 ++++ tests/test_routing_api.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 testdata/models/routing_error_forbidden_credentials.json diff --git a/testdata/models/routing_error_forbidden_credentials.json b/testdata/models/routing_error_forbidden_credentials.json new file mode 100644 index 0000000..ad3aa79 --- /dev/null +++ b/testdata/models/routing_error_forbidden_credentials.json @@ -0,0 +1,4 @@ +{ + "error": "Forbidden", + "error_description": "These credentials do not authorize access" +} diff --git a/tests/test_routing_api.py b/tests/test_routing_api.py index 00050ca..89b2169 100644 --- a/tests/test_routing_api.py +++ b/tests/test_routing_api.py @@ -140,6 +140,20 @@ def test_carroute_when_error_invalid_credentials_occurred(self): with self.assertRaises(herepy.InvalidCredentialsError): api.car_route([11.0, 12.0], [22.0, 23.0]) + @responses.activate + def test_carroute_when_error_forbidden_credentials_occurred(self): + with open("testdata/models/routing_error_forbidden_credentials.json", "r") as f: + expectedResponse = f.read() + responses.add( + responses.GET, + "https://route.ls.hereapi.com/routing/7.2/calculateroute.json", + expectedResponse, + status=401, + ) + api = herepy.RoutingApi("forbidden_api_key", "forbidden_app_code") + with self.assertRaises(herepy.InvalidCredentialsError): + api.car_route([11.0, 12.0], [22.0, 23.0]) + @responses.activate def test_carroute_when_error_no_route_found_occurred(self): with open("testdata/models/routing_error_no_route_found.json", "r") as f: