Skip to content

Commit 6772297

Browse files
authored
Merge pull request #22 from cuenca-mx/messenger_location
Avoiding Messenger Location Error
2 parents e705c55 + cd0963f commit 6772297

6 files changed

Lines changed: 265 additions & 6 deletions

File tree

ivoy/exc.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ def __init__(self, **kwargs):
111111
super().__init__(message=message, **kwargs)
112112

113113

114+
class MessengerLocationNotAvailable(IvoyException):
115+
def __init__(self, **kwargs):
116+
message = f'Messenger Location is not available'
117+
super().__init__(message=message, **kwargs)
118+
119+
114120
IVOY_EXCEPTIONS = {
115121
-101: InvalidPhone,
116122
-102: InvalidPhone,
@@ -185,6 +191,7 @@ def __init__(self, **kwargs):
185191
-252: InvalidVehicle,
186192
-258: InvalidVehicle,
187193
-327: InvalidWarehouse,
194+
-999: MessengerLocationNotAvailable,
188195
}
189196

190197

ivoy/resources/carrier_location.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from dataclasses import dataclass
22
from typing import ClassVar
33

4+
from ivoy.exc import raise_ivoy_exception
5+
46
from .base import Resource
57

68

@@ -18,8 +20,12 @@ def get_location(cls, order_id: str) -> 'CarrierLocation':
1820
json_data = dict(data=dict(bOrder=dict(idOrder=order_id)))
1921
resp = cls._client.post(cls._endpoint, json=json_data)
2022
resp = resp.json()
23+
try:
24+
messenger_location = resp['data']['messengerLocation']
25+
except KeyError as e:
26+
raise_ivoy_exception(-999, str(e))
2127
return cls(
2228
id=order_id,
23-
latitude=resp['data']['messengerLocation']['latitude'],
24-
longitude=resp['data']['messengerLocation']['longitude'],
29+
latitude=messenger_location['latitude'],
30+
longitude=messenger_location['longitude'],
2531
)

ivoy/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.4.0'
1+
__version__ = '0.4.1'

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
'pycodestyle',
1111
'pytest-cov',
1212
'black',
13-
'isort[pipfile]',
14-
'flake8',
15-
'mypy',
13+
'isort>=4.3.21,<4.4',
14+
'flake8==3.7.9',
15+
'mypy>=0.770',
1616
'iso8601',
1717
]
1818

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
interactions:
2+
- request:
3+
body: '{"data": {"systemRequest": {"user": "USER", "password": "PASS"}}}'
4+
headers:
5+
Accept:
6+
- '*/*'
7+
Accept-Encoding:
8+
- gzip, deflate
9+
Connection:
10+
- keep-alive
11+
Content-Length:
12+
- '91'
13+
Content-Type:
14+
- application/json
15+
User-Agent:
16+
- python-requests/2.22.0
17+
method: POST
18+
uri: https://api.ivoy.dev/api/login/loginClient/json/web
19+
response:
20+
body:
21+
string: '{"code": 0, "token": {"access_token": "123"}, "data":{"idClient": 69319}}'
22+
headers:
23+
Connection:
24+
- keep-alive
25+
Content-Length:
26+
- '4891'
27+
Content-Security-Policy:
28+
- default-src 'self'
29+
Content-Type:
30+
- application/json
31+
Date:
32+
- Wed, 18 Dec 2019 00:36:56 GMT
33+
Referrer-Policy:
34+
- origin-when-cross-origin, strict-origin-when-cross-origin
35+
Vary:
36+
- Origin
37+
Via:
38+
- 1.1 eaf34fdea6961e8abc71da907904f86f.cloudfront.net (CloudFront)
39+
X-Amz-Cf-Id:
40+
- ctNg6Rec5xysnDUZMUsjUg3y-aCyEw7xGxFoWbX0j8QOE4j73uQYzQ==
41+
X-Amz-Cf-Pop:
42+
- DFW53-C1
43+
X-Cache:
44+
- Miss from cloudfront
45+
X-Content-Type-Options:
46+
- nosniff
47+
X-Frame-Options:
48+
- DENY
49+
X-Permitted-Cross-Domain-Policies:
50+
- all
51+
X-XSS-Protection:
52+
- 1; mode=block
53+
x-amz-apigw-id:
54+
- E38qWHoyIAMFXcg=
55+
x-amzn-Remapped-Content-Length:
56+
- '4891'
57+
x-amzn-Remapped-Date:
58+
- Wed, 18 Dec 2019 00:36:56 GMT
59+
x-amzn-RequestId:
60+
- 9c645311-1a0d-46bf-acbf-cd3b6ae28b06
61+
status:
62+
code: 200
63+
message: OK
64+
- request:
65+
body: '{"data": {"systemRequest": {"user": "USER", "password": "PASS"}}}'
66+
headers:
67+
Accept:
68+
- '*/*'
69+
Accept-Encoding:
70+
- gzip, deflate
71+
Connection:
72+
- keep-alive
73+
Content-Length:
74+
- '91'
75+
Content-Type:
76+
- application/json
77+
User-Agent:
78+
- python-requests/2.22.0
79+
method: POST
80+
uri: https://api.ivoy.dev/api/login/loginClient/json/web
81+
response:
82+
body:
83+
string: '{"code": 0, "token": {"access_token": "123"}, "data":{"idClient": 69319}}'
84+
headers:
85+
Connection:
86+
- keep-alive
87+
Content-Length:
88+
- '4890'
89+
Content-Security-Policy:
90+
- default-src 'self'
91+
Content-Type:
92+
- application/json
93+
Date:
94+
- Wed, 18 Dec 2019 00:36:56 GMT
95+
Referrer-Policy:
96+
- origin-when-cross-origin, strict-origin-when-cross-origin
97+
Vary:
98+
- Origin
99+
Via:
100+
- 1.1 eaf34fdea6961e8abc71da907904f86f.cloudfront.net (CloudFront)
101+
X-Amz-Cf-Id:
102+
- xCI1VhgTNBllvsyjjyuoOdjvd9IFPyQWXbgjeOHV0l5zlP-cVeDNEQ==
103+
X-Amz-Cf-Pop:
104+
- DFW53-C1
105+
X-Cache:
106+
- Miss from cloudfront
107+
X-Content-Type-Options:
108+
- nosniff
109+
X-Frame-Options:
110+
- DENY
111+
X-Permitted-Cross-Domain-Policies:
112+
- all
113+
X-XSS-Protection:
114+
- 1; mode=block
115+
x-amz-apigw-id:
116+
- E38qZFvroAMFUiQ=
117+
x-amzn-Remapped-Content-Length:
118+
- '4890'
119+
x-amzn-Remapped-Date:
120+
- Wed, 18 Dec 2019 00:36:56 GMT
121+
x-amzn-RequestId:
122+
- 1d4ae3a0-6065-40d7-b45d-d729f2def073
123+
status:
124+
code: 200
125+
message: OK
126+
- request:
127+
body: '{"data": {"systemRequest": {"user": "USER", "password": "PASS"}}}'
128+
headers:
129+
Accept:
130+
- '*/*'
131+
Accept-Encoding:
132+
- gzip, deflate
133+
Connection:
134+
- keep-alive
135+
Content-Length:
136+
- '85'
137+
Content-Type:
138+
- application/json
139+
User-Agent:
140+
- python-requests/2.22.0
141+
method: POST
142+
uri: https://api.ivoy.dev/api/login/loginClient/json/web
143+
response:
144+
body:
145+
string: '{"code": 0, "token": {"access_token": "123"}, "data": {"idClient":
146+
69319}}'
147+
headers:
148+
Connection:
149+
- keep-alive
150+
Content-Length:
151+
- '6015'
152+
Content-Security-Policy:
153+
- default-src 'self'
154+
Content-Type:
155+
- application/json
156+
Date:
157+
- Mon, 10 Feb 2020 19:26:29 GMT
158+
Referrer-Policy:
159+
- origin-when-cross-origin, strict-origin-when-cross-origin
160+
Vary:
161+
- Origin
162+
Via:
163+
- 1.1 9422830f707ade946de8476fde24aafa.cloudfront.net (CloudFront)
164+
X-Amz-Cf-Id:
165+
- cm7a4D97p75nYquT43lV5grbEVMltMKt3Ds5F7XWEMnpUVG-iMzuoQ==
166+
X-Amz-Cf-Pop:
167+
- IAH50-C4
168+
X-Cache:
169+
- Miss from cloudfront
170+
X-Content-Type-Options:
171+
- nosniff
172+
X-Frame-Options:
173+
- DENY
174+
X-Permitted-Cross-Domain-Policies:
175+
- all
176+
X-XSS-Protection:
177+
- 1; mode=block
178+
x-amz-apigw-id:
179+
- Hsgv6E8QoAMFVNQ=
180+
x-amzn-Remapped-Content-Length:
181+
- '6015'
182+
x-amzn-Remapped-Date:
183+
- Mon, 10 Feb 2020 19:26:29 GMT
184+
x-amzn-RequestId:
185+
- a0f42630-a4c0-4abe-932c-7767754d4df1
186+
status:
187+
code: 200
188+
message: OK
189+
- request:
190+
body: '{"data": {"bOrder": {"idOrder": 1502058}}}'
191+
headers:
192+
Accept:
193+
- '*/*'
194+
Accept-Encoding:
195+
- gzip, deflate
196+
Connection:
197+
- keep-alive
198+
Content-Length:
199+
- '42'
200+
Content-type:
201+
- application/json
202+
User-Agent:
203+
- python-requests/2.22.0
204+
method: POST
205+
uri: https://data.alb.api.ivoy.mx/api/orderSharing/getOrderSharing/json/web
206+
response:
207+
body:
208+
string: '{"code":0,"data":{"idOrder":1502058,"points":[{"latitude":19.424422,"longitude":-99.16791699999999,"location":"19.424422,-99.16791699999999","distance":0.0,"duration":0.0,"order":0},{"latitude":19.517968,"longitude":-99.04116649999997,"location":"19.517968,-99.04116649999997","distance":0.0,"duration":0.0,"order":1}],"clientName":"Bob
209+
Marley CUENCA","messengerName":"Peter Parker","messengerRate":4.92}}'
210+
headers:
211+
Connection:
212+
- keep-alive
213+
Content-Length:
214+
- '554'
215+
Content-Security-Policy:
216+
- default-src 'self'
217+
Content-Type:
218+
- application/json
219+
Date:
220+
- Wed, 18 Dec 2019 00:36:57 GMT
221+
Referrer-Policy:
222+
- origin-when-cross-origin, strict-origin-when-cross-origin
223+
Vary:
224+
- Origin
225+
X-Content-Type-Options:
226+
- nosniff
227+
X-Frame-Options:
228+
- DENY
229+
X-Permitted-Cross-Domain-Policies:
230+
- all
231+
X-XSS-Protection:
232+
- 1; mode=block
233+
status:
234+
code: 200
235+
message: OK
236+
version: 1

tests/resources/test_carrier_location.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ def test_location_sharing_success():
1515
assert type(location_sharing.longitude) == float
1616

1717

18+
@pytest.mark.vcr
19+
def test_location_sharing_no_messenger_location():
20+
with pytest.raises(IvoyException):
21+
client = Client()
22+
location_sharing = client.carrier_location.get_location(1502058)
23+
assert client
24+
assert IvoyException.code == -999
25+
assert location_sharing is None
26+
27+
1828
@pytest.mark.vcr
1929
def test_location_sharing_failed():
2030
with pytest.raises(IvoyException):

0 commit comments

Comments
 (0)