herepy 3.6.2__tar.gz → 3.6.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {herepy-3.6.2 → herepy-3.6.3}/PKG-INFO +1 -1
- {herepy-3.6.2 → herepy-3.6.3}/herepy/__init__.py +1 -1
- {herepy-3.6.2 → herepy-3.6.3}/herepy/geocoder_api.py +11 -6
- {herepy-3.6.2 → herepy-3.6.3}/herepy/routing_api.py +61 -29
- {herepy-3.6.2 → herepy-3.6.3}/herepy.egg-info/PKG-INFO +1 -1
- {herepy-3.6.2 → herepy-3.6.3}/tests/test_geocoder_api.py +44 -1
- {herepy-3.6.2 → herepy-3.6.3}/tests/test_routing_api.py +14 -0
- {herepy-3.6.2 → herepy-3.6.3}/COPYING +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/LICENSE +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/MANIFEST.in +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/NOTICE +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/README.rst +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy/destination_weather_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy/error.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy/ev_charging_stations_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy/fleet_telematics_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy/geocoder_autocomplete_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy/geocoder_reverse_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy/here_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy/here_enum.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy/isoline_routing_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy/map_image_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy/map_tile_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy/mercator_projection.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy/models.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy/objects.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy/places_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy/platform/__init__.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy/platform/tour_planning_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy/polling.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy/public_transit_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy/py.typed +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy/rme_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy/traffic_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy/utils.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy/vector_tile_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy.egg-info/SOURCES.txt +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy.egg-info/dependency_links.txt +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy.egg-info/requires.txt +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/herepy.egg-info/top_level.txt +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/requirements.txt +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/setup.cfg +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/setup.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/tests/test_destination_weather_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/tests/test_enum.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/tests/test_ev_charging_stations_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/tests/test_fleet_telematics_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/tests/test_geocoder_autocomplete_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/tests/test_geocoder_reverse_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/tests/test_isoline_routing_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/tests/test_map_image_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/tests/test_map_tile_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/tests/test_mercator_projection.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/tests/test_models.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/tests/test_places_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/tests/test_publictransit_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/tests/test_rme_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/tests/test_traffic_api.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/tests/test_utils.py +0 -0
- {herepy-3.6.2 → herepy-3.6.3}/tests/test_vector_tile_api.py +0 -0
|
@@ -6,7 +6,7 @@ __author__ = "Abdullah Selek"
|
|
|
6
6
|
__email__ = "abdullahselek.os@gmail.com"
|
|
7
7
|
__copyright__ = "Copyright (c) 2017 Abdullah Selek"
|
|
8
8
|
__license__ = "MIT License"
|
|
9
|
-
__version__ = "3.6.
|
|
9
|
+
__version__ = "3.6.3"
|
|
10
10
|
__url__ = "https://github.com/abdullahselek/HerePy"
|
|
11
11
|
__download_url__ = "https://pypi.org/pypi/herepy"
|
|
12
12
|
__description__ = "A library that provides a Python interface to the HERE APIs"
|
|
@@ -106,11 +106,11 @@ class GeocoderApi(HEREApi):
|
|
|
106
106
|
|
|
107
107
|
def address_with_details(
|
|
108
108
|
self,
|
|
109
|
-
house_number: int,
|
|
110
|
-
street: str,
|
|
111
109
|
city: str,
|
|
112
110
|
country: str,
|
|
113
111
|
lang: str = "en-US",
|
|
112
|
+
house_number: Optional[int] = None,
|
|
113
|
+
street: Optional[str] = None,
|
|
114
114
|
) -> Optional[GeocoderResponse]:
|
|
115
115
|
"""Geocodes with given address details
|
|
116
116
|
Args:
|
|
@@ -129,11 +129,16 @@ class GeocoderApi(HEREApi):
|
|
|
129
129
|
Raises:
|
|
130
130
|
HEREError"""
|
|
131
131
|
|
|
132
|
+
qq_query = ""
|
|
133
|
+
if house_number is not None:
|
|
134
|
+
qq_query += f"houseNumber={house_number};"
|
|
135
|
+
if street is not None:
|
|
136
|
+
qq_query += f"street={street};"
|
|
137
|
+
qq_query += f"city={city};"
|
|
138
|
+
qq_query += f"country={country}"
|
|
139
|
+
|
|
132
140
|
data = {
|
|
133
|
-
"qq":
|
|
134
|
-
+ str.format("street={0};", street)
|
|
135
|
-
+ str.format("city={0};", city)
|
|
136
|
-
+ str.format("country={0}", country),
|
|
141
|
+
"qq": qq_query,
|
|
137
142
|
"apiKey": self._api_key,
|
|
138
143
|
"lang": lang,
|
|
139
144
|
}
|
|
@@ -982,34 +982,66 @@ class RouteNotReconstructedError(HEREError):
|
|
|
982
982
|
|
|
983
983
|
# pylint: disable=R0911
|
|
984
984
|
def error_from_routing_service_error(json_data):
|
|
985
|
-
"""Return the correct
|
|
985
|
+
"""Return the correct error class for routing errors."""
|
|
986
986
|
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
return InvalidCredentialsError(json_data["error_description"])
|
|
987
|
+
if "error" in json_data:
|
|
988
|
+
return _auth_error(json_data)
|
|
990
989
|
elif "status" in json_data:
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
)
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
990
|
+
return _status_error(json_data)
|
|
991
|
+
elif "subtype" in json_data:
|
|
992
|
+
return _request_error(json_data)
|
|
993
|
+
else:
|
|
994
|
+
return _default_error(json_data)
|
|
995
|
+
|
|
996
|
+
|
|
997
|
+
def _auth_error(json_data):
|
|
998
|
+
""" 'error' in response data, return appropriate error."""
|
|
999
|
+
|
|
1000
|
+
error_type = json_data["error"]
|
|
1001
|
+
|
|
1002
|
+
if error_type in ["Unauthorized", "Forbidden"]:
|
|
1003
|
+
return InvalidCredentialsError(json_data["error_description"])
|
|
1004
|
+
else:
|
|
1005
|
+
return _default_error(json_data)
|
|
1006
|
+
|
|
1007
|
+
|
|
1008
|
+
def _status_error(json_data):
|
|
1009
|
+
""" 'status' in response data, return appropriate error."""
|
|
1010
|
+
|
|
1011
|
+
error_msg = f"Cause: {json_data['cause']}; Action: {json_data['action']}"
|
|
1012
|
+
status_code = json_data["status"]
|
|
1013
|
+
if status_code == 400:
|
|
1014
|
+
return InvalidRequestError(error_msg)
|
|
1015
|
+
elif status_code == 403:
|
|
1016
|
+
return AccessDeniedError(error_msg)
|
|
1017
|
+
else:
|
|
1018
|
+
return _default_error(json_data)
|
|
1019
|
+
|
|
1020
|
+
|
|
1021
|
+
|
|
1022
|
+
def _request_error(json_data):
|
|
1023
|
+
""" 'subtype' in error response, return appropriate response"""
|
|
1024
|
+
|
|
1025
|
+
subtype = json_data["subtype"]
|
|
1026
|
+
details = json_data["details"]
|
|
1027
|
+
|
|
1028
|
+
if subtype == "InvalidInputData":
|
|
1029
|
+
return InvalidInputDataError(details)
|
|
1030
|
+
elif subtype == "WaypointNotFound":
|
|
1031
|
+
return WaypointNotFoundError(details)
|
|
1032
|
+
elif subtype == "NoRouteFound":
|
|
1033
|
+
return NoRouteFoundError(details)
|
|
1034
|
+
elif subtype == "LinkIdNotFound":
|
|
1035
|
+
return LinkIdNotFoundError(details)
|
|
1036
|
+
elif subtype == "RouteNotReconstructed":
|
|
1037
|
+
return RouteNotReconstructedError(details)
|
|
1038
|
+
else:
|
|
1039
|
+
return _default_error(json_data)
|
|
1040
|
+
|
|
1041
|
+
|
|
1042
|
+
def _default_error(json_data):
|
|
1043
|
+
""" default response message when error type is unknown."""
|
|
1044
|
+
|
|
1045
|
+
function_name = sys._getframe(1).f_code.co_name
|
|
1046
|
+
default_error_message = f"Error occurred on {function_name} - API Response: {json_data}"
|
|
1047
|
+
return HEREError(default_error_message)
|
|
@@ -90,10 +90,53 @@ class GeocoderApiTest(unittest.TestCase):
|
|
|
90
90
|
expectedResponse,
|
|
91
91
|
status=200,
|
|
92
92
|
)
|
|
93
|
-
response = self._api.address_with_details(
|
|
93
|
+
response = self._api.address_with_details(
|
|
94
|
+
street="Barbaros",
|
|
95
|
+
city="Istanbul",
|
|
96
|
+
country="Turkey",
|
|
97
|
+
house_number=34
|
|
98
|
+
)
|
|
99
|
+
self.assertTrue(response)
|
|
100
|
+
self.assertIsInstance(response, herepy.GeocoderResponse)
|
|
101
|
+
|
|
102
|
+
@responses.activate
|
|
103
|
+
def test_address_with_detail_without_street(self):
|
|
104
|
+
with open("testdata/models/geocoder.json", "r") as f:
|
|
105
|
+
expected_response = f.read()
|
|
106
|
+
responses.add(
|
|
107
|
+
responses.GET,
|
|
108
|
+
"https://geocode.search.hereapi.com/v1/geocode",
|
|
109
|
+
expected_response,
|
|
110
|
+
status=200,
|
|
111
|
+
)
|
|
112
|
+
response = self._api.address_with_details(
|
|
113
|
+
city="Istanbul",
|
|
114
|
+
country="Turkey",
|
|
115
|
+
house_number=34,
|
|
116
|
+
street= None
|
|
117
|
+
)
|
|
94
118
|
self.assertTrue(response)
|
|
95
119
|
self.assertIsInstance(response, herepy.GeocoderResponse)
|
|
96
120
|
|
|
121
|
+
@responses.activate
|
|
122
|
+
def test_address_with_detail_without_house_number(self):
|
|
123
|
+
with open("testdata/models/geocoder.json", "r") as f:
|
|
124
|
+
expected_response = f.read()
|
|
125
|
+
responses.add(
|
|
126
|
+
responses.GET,
|
|
127
|
+
"https://geocode.search.hereapi.com/v1/geocode",
|
|
128
|
+
expected_response,
|
|
129
|
+
status=200,
|
|
130
|
+
)
|
|
131
|
+
response = self._api.address_with_details(
|
|
132
|
+
street="Barbaros",
|
|
133
|
+
city="Istanbul",
|
|
134
|
+
country="Turkey",
|
|
135
|
+
house_number= None
|
|
136
|
+
)
|
|
137
|
+
self.assertTrue(response)
|
|
138
|
+
self.assertIsInstance(response, herepy.GeocoderResponse)
|
|
139
|
+
|
|
97
140
|
@responses.activate
|
|
98
141
|
def test_addresswithdetails_whenerroroccurred(self):
|
|
99
142
|
with open("testdata/models/geocoder_error.json", "r") as f:
|
|
@@ -140,6 +140,20 @@ class RoutingApiTest(unittest.TestCase):
|
|
|
140
140
|
with self.assertRaises(herepy.InvalidCredentialsError):
|
|
141
141
|
api.car_route([11.0, 12.0], [22.0, 23.0])
|
|
142
142
|
|
|
143
|
+
@responses.activate
|
|
144
|
+
def test_carroute_when_error_forbidden_credentials_occurred(self):
|
|
145
|
+
with open("testdata/models/routing_error_forbidden_credentials.json", "r") as f:
|
|
146
|
+
expectedResponse = f.read()
|
|
147
|
+
responses.add(
|
|
148
|
+
responses.GET,
|
|
149
|
+
"https://route.ls.hereapi.com/routing/7.2/calculateroute.json",
|
|
150
|
+
expectedResponse,
|
|
151
|
+
status=401,
|
|
152
|
+
)
|
|
153
|
+
api = herepy.RoutingApi("forbidden_api_key", "forbidden_app_code")
|
|
154
|
+
with self.assertRaises(herepy.InvalidCredentialsError):
|
|
155
|
+
api.car_route([11.0, 12.0], [22.0, 23.0])
|
|
156
|
+
|
|
143
157
|
@responses.activate
|
|
144
158
|
def test_carroute_when_error_no_route_found_occurred(self):
|
|
145
159
|
with open("testdata/models/routing_error_no_route_found.json", "r") as f:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|