Skip to content

Commit bd629f7

Browse files
author
rubensanchez
committed
shipping v2 tests
1 parent 785770c commit bd629f7

1 file changed

Lines changed: 264 additions & 0 deletions

File tree

Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
import pytest
2+
3+
from sp_api.api.shipping.shippingV2 import Shipping, AmznShippingBusiness
4+
from sp_api.base import SellingApiBadRequestException
5+
6+
7+
def test_get_rates():
8+
res = Shipping().get_rates(
9+
**{
10+
"shipTo": {
11+
"name": "Arlene Purdy",
12+
"addressLine1": "8076 Armstrong Extensions",
13+
"city": "South Kristopherborough",
14+
"countryCode": "UK",
15+
"postalCode": "NW10 0TL",
16+
"email": "buyer@test.com",
17+
"phoneNumber": "700-008-5275",
18+
},
19+
"shipFrom": {
20+
"name": "Orville Miller I",
21+
"addressLine1": "16063 Daugherty Throughway",
22+
"city": "Connland",
23+
"countryCode": "UK",
24+
"postalCode": "NW10 0TL",
25+
"email": "seller@test.com",
26+
"phoneNumber": "662-302-7817",
27+
},
28+
"shipDate": "2024-09-11T14:15:22Z",
29+
"shipperInstruction": {
30+
"deliveryNotes": "TEST"
31+
},
32+
"packages": [
33+
{
34+
"dimensions": {
35+
"length": 30,
36+
"width": 10,
37+
"height": 10,
38+
"unit": "CENTIMETER"
39+
},
40+
"weight": {
41+
"unit": "KILOGRAM",
42+
"value": 1.00,
43+
},
44+
"insuredValue": {
45+
"value": 0.00,
46+
"unit": "EUR",
47+
},
48+
"sellerDisplayName": "SELLER_NAME",
49+
"packageClientReferenceId": "PACKAGE_ID_1",
50+
"items": [
51+
{
52+
"description": "ITEM_1",
53+
"quantity": 1,
54+
"weight": {
55+
"value": 1.00,
56+
"unit": "KILOGRAM",
57+
},
58+
}
59+
]
60+
}
61+
],
62+
"channelDetails": {
63+
"channelType": "EXTERNAL",
64+
},
65+
"shipmentType": "FORWARD",
66+
}
67+
)
68+
assert res.errors is None
69+
assert res.payload.get('requestToken') is not None
70+
assert len(res.payload.get('rates')) > 0
71+
72+
73+
def test_get_additional_inputs_empty():
74+
res = Shipping().get_additional_inputs(
75+
**{
76+
"requestToken": "amzn1.rq.123456789.101",
77+
"rateId": "122324234543535321345436534321423423523452345"
78+
}
79+
)
80+
assert res.errors is None
81+
assert res.payload == {}
82+
83+
84+
def test_get_additional_inputs_invalid():
85+
try:
86+
res = Shipping().get_additional_inputs(
87+
**{
88+
"requestToken": "null",
89+
"rateId": "2314346237423894905834905890346890789075"
90+
}
91+
)
92+
except SellingApiBadRequestException as br:
93+
assert br.code == 400
94+
assert type(br) == SellingApiBadRequestException
95+
assert br.error[0]["details"] == "RequestToken cannot be null"
96+
97+
98+
def test_get_tracking():
99+
res = Shipping().get_tracking(
100+
**{
101+
"trackingId": "23AA47DE2B3B6",
102+
"carrierId": "AMZN_UK",
103+
}
104+
)
105+
assert res.errors is None
106+
assert res.payload.get("trackingId") == "23AA47DE2B3B6"
107+
assert res.payload.get("summary").get("status") == "Delivered"
108+
assert len(res.payload.get("eventHistory")) > 0
109+
110+
111+
def test_cancel_shipment_not_found():
112+
try:
113+
res = Shipping().cancel_shipment("TEST_CASE_400")
114+
assert res.errors is None
115+
except SellingApiBadRequestException as br:
116+
assert br.code == 400
117+
assert type(br) == SellingApiBadRequestException
118+
assert br.error[0]["details"] == "Shipment not found for specified shipmentId"
119+
120+
121+
def test_get_shipment_documents():
122+
try:
123+
res = Shipping().get_shipment_documents(
124+
"445454-3232-3232",
125+
packageClientReferenceId="ASUSDI-45343854"
126+
)
127+
assert res.errors is None
128+
except SellingApiBadRequestException as br:
129+
assert br.code == 400
130+
assert type(br) == SellingApiBadRequestException
131+
assert br.error[0]["details"] == "Shipment not found for specified shipmentId"
132+
133+
134+
def test_purchase_shipment():
135+
try:
136+
res = Shipping().purchase_shipment(
137+
**{
138+
"requestToken": "amzn1.rq.123456789.101",
139+
"rateId": "122324234543535321345436534321423423523452345",
140+
"requestedDocumentSpecification": {
141+
"format": "ZPL",
142+
"size": {
143+
"width": 4,
144+
"length": 6,
145+
"unit": "INCH"
146+
},
147+
"dpi": 203,
148+
"pageLayout": "DEFAULT",
149+
"needFileJoining": False,
150+
"requestedDocumentTypes": ["LABEL"]
151+
}
152+
}
153+
)
154+
assert res.errors is None
155+
except SellingApiBadRequestException as br:
156+
assert br.code == 400
157+
assert type(br) == SellingApiBadRequestException
158+
assert br.error[0]["details"] == "Request not found for specified requestToken"
159+
160+
161+
def test_submit_ndr_feedback():
162+
res = Shipping().submit_ndr_feedback(
163+
**{
164+
"trackingId": "TEST_CASE_200",
165+
"ndrAction": "RESCHEDULE",
166+
"ndrRequestData": {
167+
"rescheduleDate": "2024-12-12T05:24:00.00Z",
168+
"additionalAddressNotes": "string"
169+
}
170+
}
171+
)
172+
assert res.errors is None
173+
174+
175+
def test_get_access_points():
176+
res = Shipping().get_access_points(
177+
**{
178+
"accessPointTypes": "HELIX",
179+
"countryCode": "UK",
180+
"postalCode": "EX332JL"
181+
}
182+
)
183+
assert res.errors is None
184+
185+
186+
def test_one_click_shipment():
187+
res = Shipping().one_click_shipment(
188+
**{
189+
"shipTo": {
190+
"name": "Arlene Purdy",
191+
"addressLine1": "8076 Armstrong Extensions",
192+
"city": "South Kristopherborough",
193+
"countryCode": "UK",
194+
"postalCode": "NW10 0TL",
195+
"email": "buyer@test.com",
196+
"phoneNumber": "700-008-5275",
197+
},
198+
"shipFrom": {
199+
"name": "Orville Miller I",
200+
"addressLine1": "16063 Daugherty Throughway",
201+
"city": "Connland",
202+
"countryCode": "UK",
203+
"postalCode": "NW10 0TL",
204+
"email": "seller@test.com",
205+
"phoneNumber": "662-302-7817",
206+
},
207+
"shipDate": "2024-09-11T14:15:22Z",
208+
"shipperInstruction": {
209+
"deliveryNotes": "TEST"
210+
},
211+
"packages": [
212+
{
213+
"dimensions": {
214+
"length": 30,
215+
"width": 10,
216+
"height": 10,
217+
"unit": "CENTIMETER"
218+
},
219+
"weight": {
220+
"unit": "KILOGRAM",
221+
"value": 1.00,
222+
},
223+
"insuredValue": {
224+
"value": 0.00,
225+
"unit": "EUR",
226+
},
227+
"sellerDisplayName": "SELLER_NAME",
228+
"packageClientReferenceId": "PACKAGE_ID_1",
229+
"items": [
230+
{
231+
"description": "ITEM_1",
232+
"quantity": 1,
233+
"weight": {
234+
"value": 1.00,
235+
"unit": "KILOGRAM",
236+
},
237+
}
238+
]
239+
}
240+
],
241+
"channelDetails": {
242+
"channelType": "EXTERNAL",
243+
},
244+
"labelSpecifications": {
245+
"format": "ZPL",
246+
"size": {
247+
"width": 4,
248+
"length": 6,
249+
"unit": "INCH"
250+
},
251+
"dpi": 203,
252+
"pageLayout": "DEFAULT",
253+
"needFileJoining": False,
254+
"requestedDocumentTypes": ["LABEL"]
255+
},
256+
"serviceSelection": {
257+
"serviceId": ["SWA-UK-PREM"]
258+
},
259+
}
260+
)
261+
assert res.errors is None
262+
assert res.payload.get('shipmentId')
263+
assert res.payload.get('packageDocumentDetails')[0]['trackingId']
264+
assert len(res.payload.get('packageDocumentDetails')[0]['packageDocuments']) > 0

0 commit comments

Comments
 (0)