Skip to content

Commit d086d7d

Browse files
committed
Update tests
1 parent c589df9 commit d086d7d

File tree

2 files changed

+348
-20
lines changed

2 files changed

+348
-20
lines changed
Lines changed: 309 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,309 @@
1+
from commercetools.platform import models
2+
3+
4+
def test_deserialize_order_paged_query_response():
5+
response = models.OrderPagedQueryResponse.deserialize({
6+
"limit": 20,
7+
"offset": 0,
8+
"count": 20,
9+
"total": 612,
10+
"results": [
11+
{
12+
"type": "Order",
13+
"id": "c28ba890-0595-475f-8c8b-ca96d7c5c602",
14+
"version": 4,
15+
"lastMessageSequenceNumber": 4,
16+
"createdAt": "2020-12-17T12:45:22.407Z",
17+
"lastModifiedAt": "2021-01-18T09:07:07.198Z",
18+
"lastModifiedBy": {
19+
"isPlatformClient": True,
20+
"user": {
21+
"typeId": "user",
22+
"id": "cf8fd14f-384d-4a13-a81a-fdb1fc76623a",
23+
},
24+
},
25+
"createdBy": {
26+
"clientId": "1qGcTSsoGLHvmiRUnMOut5__",
27+
"isPlatformClient": False,
28+
"anonymousId": "75c0fe8c-d4b8-40b2-9138-a39278acf406",
29+
},
30+
"orderNumber": "5000158",
31+
"customerEmail": "test@example.org",
32+
"anonymousId": "75c0fe8c-d4b8-40b2-9138-a39278acf406",
33+
"locale": "nl-NL",
34+
"totalPrice": {
35+
"type": "centPrecision",
36+
"currencyCode": "EUR",
37+
"centAmount": 5716,
38+
"fractionDigits": 2,
39+
},
40+
"taxedPrice": {
41+
"totalNet": {
42+
"type": "centPrecision",
43+
"currencyCode": "EUR",
44+
"centAmount": 4724,
45+
"fractionDigits": 2,
46+
},
47+
"totalGross": {
48+
"type": "centPrecision",
49+
"currencyCode": "EUR",
50+
"centAmount": 5716,
51+
"fractionDigits": 2,
52+
},
53+
"taxPortions": [
54+
{
55+
"rate": 0.21,
56+
"amount": {
57+
"type": "centPrecision",
58+
"currencyCode": "EUR",
59+
"centAmount": 992,
60+
"fractionDigits": 2,
61+
},
62+
"name": "21% BTW",
63+
}
64+
],
65+
},
66+
"country": "NL",
67+
"orderState": "Confirmed",
68+
"paymentState": "Pending",
69+
"syncInfo": [],
70+
"returnInfo": [],
71+
"shippingInfo": {
72+
"shippingMethodName": "Standard shipping method",
73+
"price": {
74+
"type": "centPrecision",
75+
"currencyCode": "EUR",
76+
"centAmount": 5000,
77+
"fractionDigits": 2,
78+
},
79+
"shippingRate": {
80+
"price": {
81+
"type": "centPrecision",
82+
"currencyCode": "EUR",
83+
"centAmount": 5000,
84+
"fractionDigits": 2,
85+
},
86+
"freeAbove": {
87+
"type": "centPrecision",
88+
"currencyCode": "EUR",
89+
"centAmount": 50000,
90+
"fractionDigits": 2,
91+
},
92+
"tiers": [],
93+
},
94+
"taxRate": {
95+
"name": "21% BTW",
96+
"amount": 0.21,
97+
"includedInPrice": True,
98+
"country": "NL",
99+
"id": "Z0wLUuYw",
100+
"subRates": [],
101+
},
102+
"taxCategory": {
103+
"typeId": "tax-category",
104+
"id": "ac8b6c6c-424f-4cbb-aec5-d3754fb8dd78",
105+
},
106+
"deliveries": [],
107+
"shippingMethod": {
108+
"typeId": "shipping-method",
109+
"id": "fdf53457-487f-4b0e-bfbb-3124e44686e7",
110+
},
111+
"taxedPrice": {
112+
"totalNet": {
113+
"type": "centPrecision",
114+
"currencyCode": "EUR",
115+
"centAmount": 4132,
116+
"fractionDigits": 2,
117+
},
118+
"totalGross": {
119+
"type": "centPrecision",
120+
"currencyCode": "EUR",
121+
"centAmount": 5000,
122+
"fractionDigits": 2,
123+
},
124+
},
125+
"shippingMethodState": "MatchesCart",
126+
},
127+
"taxMode": "Platform",
128+
"inventoryMode": "ReserveOnOrder",
129+
"taxRoundingMode": "HalfEven",
130+
"taxCalculationMode": "LineItemLevel",
131+
"origin": "Customer",
132+
"lineItems": [
133+
{
134+
"id": "7c0e2cbf-3434-494a-89cb-6fc0f8881662",
135+
"productId": "02e00188-0f19-4b43-9c35-55ae702fd1be",
136+
"name": {"nl-NL": "Some Product"},
137+
"productType": {
138+
"typeId": "product-type",
139+
"id": "109caecb-abe6-4900-ab03-7af5af985ff3",
140+
"version": 1,
141+
},
142+
"productSlug": {"nl-NL": "some-product"},
143+
"variant": {
144+
"id": 1,
145+
"sku": "PRODUCT1",
146+
"key": "PRODUCT1",
147+
"prices": [
148+
{
149+
"value": {
150+
"type": "centPrecision",
151+
"currencyCode": "EUR",
152+
"centAmount": 895,
153+
"fractionDigits": 2,
154+
},
155+
"id": "36506ccc-e770-4937-a027-3e4ff0e7e70e",
156+
"channel": {
157+
"typeId": "channel",
158+
"id": "d75c2a23-fb85-4916-bd9c-9862dca9138c",
159+
},
160+
"discounted": {
161+
"value": {
162+
"type": "centPrecision",
163+
"currencyCode": "EUR",
164+
"centAmount": 716,
165+
"fractionDigits": 2,
166+
},
167+
"discount": {
168+
"typeId": "product-discount",
169+
"id": "57b26c6e-ebea-4197-ac24-ed602d1a0c04",
170+
},
171+
},
172+
}
173+
],
174+
"images": [
175+
{
176+
"url": "http://example.org/image.jpg",
177+
"dimensions": {"w": 1200, "h": 800},
178+
},
179+
],
180+
"attributes": [
181+
{"name": "brand", "value": {"nl-NL": "SomeBrand"}},
182+
],
183+
"assets": [],
184+
"availability": {
185+
"channels": {
186+
"d75c2a23-fb85-4916-bd9c-9862dca9138c": {
187+
"isOnStock": False,
188+
"restockableInDays": 12,
189+
"availableQuantity": -1,
190+
}
191+
}
192+
},
193+
},
194+
"price": {
195+
"value": {
196+
"type": "centPrecision",
197+
"currencyCode": "EUR",
198+
"centAmount": 895,
199+
"fractionDigits": 2,
200+
},
201+
"id": "36506ccc-e770-4937-a027-3e4ff0e7e70e",
202+
"channel": {
203+
"typeId": "channel",
204+
"id": "d75c2a23-fb85-4916-bd9c-9862dca9138c",
205+
},
206+
"discounted": {
207+
"value": {
208+
"type": "centPrecision",
209+
"currencyCode": "EUR",
210+
"centAmount": 716,
211+
"fractionDigits": 2,
212+
},
213+
"discount": {
214+
"typeId": "product-discount",
215+
"id": "57b26c6e-ebea-4197-ac24-ed602d1a0c04",
216+
},
217+
},
218+
},
219+
"quantity": 1,
220+
"discountedPricePerQuantity": [],
221+
"supplyChannel": {
222+
"typeId": "channel",
223+
"id": "d75c2a23-fb85-4916-bd9c-9862dca9138c",
224+
},
225+
"distributionChannel": {
226+
"typeId": "channel",
227+
"id": "d75c2a23-fb85-4916-bd9c-9862dca9138c",
228+
},
229+
"taxRate": {
230+
"name": "21% BTW",
231+
"amount": 0.21,
232+
"includedInPrice": True,
233+
"country": "NL",
234+
"id": "Z0wLUuYw",
235+
"subRates": [],
236+
},
237+
"addedAt": "2020-12-17T12:43:22.773Z",
238+
"lastModifiedAt": "2020-12-17T12:43:22.773Z",
239+
"state": [
240+
{
241+
"quantity": 1,
242+
"state": {
243+
"typeId": "state",
244+
"id": "f1d9531d-41f0-46a7-82f2-c4b0748aa9f5",
245+
},
246+
}
247+
],
248+
"priceMode": "Platform",
249+
"totalPrice": {
250+
"type": "centPrecision",
251+
"currencyCode": "EUR",
252+
"centAmount": 716,
253+
"fractionDigits": 2,
254+
},
255+
"taxedPrice": {
256+
"totalNet": {
257+
"type": "centPrecision",
258+
"currencyCode": "EUR",
259+
"centAmount": 592,
260+
"fractionDigits": 2,
261+
},
262+
"totalGross": {
263+
"type": "centPrecision",
264+
"currencyCode": "EUR",
265+
"centAmount": 716,
266+
"fractionDigits": 2,
267+
},
268+
},
269+
"lineItemMode": "Standard",
270+
}
271+
],
272+
"customLineItems": [],
273+
"transactionFee": True,
274+
"discountCodes": [],
275+
"cart": {"typeId": "cart", "id": "a25425a1-f557-44a6-b2ab-c06f5134bb99"},
276+
"custom": {
277+
"type": {
278+
"typeId": "type",
279+
"id": "05ce0769-40bf-4246-a72a-7a5064e49cd1",
280+
},
281+
"fields": {
282+
"customerNotes": "<p>&#x1F525</p>\n👍",
283+
"dateOfBirth": "1919-12-31",
284+
},
285+
},
286+
"paymentInfo": {
287+
"payments": [
288+
{"typeId": "payment", "id": "5b8e9bbe-a6dd-47cf-bc16-1f81d8c0e9dd"}
289+
]
290+
},
291+
"shippingAddress": {"country": "NL"},
292+
"billingAddress": {
293+
"firstName": "is",
294+
"lastName": "emoji accepted",
295+
"streetName": "sdafsdf",
296+
"streetNumber": "11111111111111111111111111111111111111111111111111111111111111111111",
297+
"postalCode": "1234hh",
298+
"city": "sdffd",
299+
"country": "NL",
300+
"company": "",
301+
"building": "",
302+
"phone": "06123456789",
303+
},
304+
"itemShippingAddresses": [],
305+
"refusedGifts": [],
306+
"store": {"typeId": "store", "key": "store"},
307+
},
308+
],
309+
})
Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,56 @@
11
import pytest
22

33
from commercetools import CommercetoolsError
4+
from commercetools.platform.client import Client as PlatformClient
45
from commercetools.platform import models
56

67

7-
def test_correlation_id_is_set_in_exception(old_client):
8-
product = old_client.products.create(
9-
models.ProductDraft(
10-
key="test-product",
11-
name=models.LocalizedString(en=f"my-product"),
12-
slug=models.LocalizedString(en=f"my-product"),
13-
product_type=models.ProductTypeResourceIdentifier(key="dummy"),
8+
def test_correlation_id_is_set_in_exception(ct_platform_client: PlatformClient):
9+
product = (
10+
ct_platform_client.with_project_key("foo")
11+
.products()
12+
.post(
13+
models.ProductDraft(
14+
key="test-product",
15+
name=models.LocalizedString(en=f"my-product"),
16+
slug=models.LocalizedString(en=f"my-product"),
17+
product_type=models.ProductTypeResourceIdentifier(key="dummy"),
18+
)
1419
)
1520
)
1621

17-
product = old_client.products.update_by_id(
18-
id=product.id,
19-
version=product.version,
20-
actions=[
21-
models.ProductChangeSlugAction(slug=models.LocalizedString(nl="nl-slug2"))
22-
],
22+
product = (
23+
ct_platform_client.with_project_key("foo")
24+
.products()
25+
.with_id(product.id)
26+
.post(
27+
models.ProductUpdate(
28+
version=product.version,
29+
actions=[
30+
models.ProductChangeSlugAction(
31+
slug=models.LocalizedString(nl="nl-slug2")
32+
)
33+
],
34+
)
35+
)
2336
)
2437

2538
# This should raise a version conflict error
2639
with pytest.raises(CommercetoolsError) as exc:
27-
old_client.products.update_by_id(
28-
id=product.id,
29-
version=1,
30-
actions=[
31-
models.ProductChangeSlugAction(
32-
slug=models.LocalizedString(nl="nl-slug3")
40+
product = (
41+
ct_platform_client.with_project_key("foo")
42+
.products()
43+
.with_id(product.id)
44+
.post(
45+
models.ProductUpdate(
46+
version=1, # conflicting version
47+
actions=[
48+
models.ProductChangeSlugAction(
49+
slug=models.LocalizedString(nl="nl-slug2")
50+
)
51+
],
3352
)
34-
],
53+
)
3554
)
3655

3756
assert exc.value.correlation_id is not None

0 commit comments

Comments
 (0)