karrio-server-graph 2026.1.1__py3-none-any.whl → 2026.1.4__py3-none-any.whl

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.
@@ -1,34 +1,30 @@
1
1
  from unittest.mock import ANY
2
2
  from karrio.server.graph.tests.base import GraphTestCase
3
3
  import karrio.server.manager.models as manager
4
- import karrio.server.graph.models as graph
5
4
 
6
5
 
7
- class TestAddressTemplate(GraphTestCase):
8
- def _create_address_template(self):
6
+ class TestAddress(GraphTestCase):
7
+ def _create_address(self):
9
8
  return self.query(
10
9
  """
11
- mutation create_address_template($data: CreateAddressTemplateInput!) {
12
- create_address_template(input: $data) {
13
- template {
10
+ mutation create_address($data: CreateAddressInput!) {
11
+ create_address(input: $data) {
12
+ address {
14
13
  id
15
- is_default
16
- label
17
- address {
18
- company_name
19
- person_name
20
- address_line1
21
- address_line2
22
- postal_code
23
- residential
24
- city
25
- state_code
26
- country_code
27
- email
28
- phone_number
29
- validation
30
- validate_location
31
- }
14
+ meta
15
+ company_name
16
+ person_name
17
+ address_line1
18
+ address_line2
19
+ postal_code
20
+ residential
21
+ city
22
+ state_code
23
+ country_code
24
+ email
25
+ phone_number
26
+ validation
27
+ validate_location
32
28
  }
33
29
  errors {
34
30
  field
@@ -37,40 +33,37 @@ class TestAddressTemplate(GraphTestCase):
37
33
  }
38
34
  }
39
35
  """,
40
- operation_name="create_address_template",
41
- variables=ADDRESS_TEMPLATE_DATA,
36
+ operation_name="create_address",
37
+ variables=ADDRESS_DATA,
42
38
  )
43
39
 
44
- def test_create_address_template(self):
45
- response = self._create_address_template()
40
+ def test_create_address(self):
41
+ response = self._create_address()
46
42
  self.assertResponseNoErrors(response)
47
- self.assertDictEqual(response.data, ADDRESS_TEMPLATE_RESPONSE)
43
+ self.assertDictEqual(response.data, ADDRESS_RESPONSE)
48
44
 
49
- def test_update_address_template(self):
50
- template = self._create_address_template().data
45
+ def test_update_address(self):
46
+ address = self._create_address().data
51
47
  response = self.query(
52
48
  """
53
- mutation update_address_template($data: UpdateAddressTemplateInput!) {
54
- update_address_template(input: $data) {
55
- template {
49
+ mutation update_address($data: UpdateAddressInput!) {
50
+ update_address(input: $data) {
51
+ address {
56
52
  id
57
- is_default
58
- label
59
- address {
60
- company_name
61
- person_name
62
- address_line1
63
- address_line2
64
- postal_code
65
- residential
66
- city
67
- state_code
68
- country_code
69
- email
70
- phone_number
71
- validation
72
- validate_location
73
- }
53
+ meta
54
+ company_name
55
+ person_name
56
+ address_line1
57
+ address_line2
58
+ postal_code
59
+ residential
60
+ city
61
+ state_code
62
+ country_code
63
+ email
64
+ phone_number
65
+ validation
66
+ validate_location
74
67
  }
75
68
  errors {
76
69
  field
@@ -79,62 +72,56 @@ class TestAddressTemplate(GraphTestCase):
79
72
  }
80
73
  }
81
74
  """,
82
- operation_name="update_address_template",
75
+ operation_name="update_address",
83
76
  variables={
84
77
  "data": {
85
- "id": template["data"]["create_address_template"]["template"]["id"],
86
- **ADDRESS_TEMPLATE_UPDATE_DATA["data"],
78
+ "id": address["data"]["create_address"]["address"]["id"],
79
+ **ADDRESS_UPDATE_DATA["data"],
87
80
  },
88
81
  },
89
82
  )
90
- response_data = response.data
91
83
 
92
84
  self.assertResponseNoErrors(response)
93
- self.assertDictEqual(response_data, ADDRESS_TEMPLATE_UPDATE_RESPONSE)
85
+ self.assertDictEqual(response.data, ADDRESS_UPDATE_RESPONSE)
94
86
 
95
- def test_delete_address_template(self):
96
- template = self._create_address_template().data
97
- template_id = template["data"]["create_address_template"]["template"]["id"]
98
- delete_template_data = {"data": {"id": template_id}}
87
+ def test_delete_address(self):
88
+ address = self._create_address().data
89
+ address_id = address["data"]["create_address"]["address"]["id"]
90
+ delete_data = {"data": {"id": address_id}}
99
91
  response = self.query(
100
92
  """
101
- mutation delete_template($data: DeleteMutationInput!) {
102
- delete_template(input: $data) {
93
+ mutation delete_address($data: DeleteMutationInput!) {
94
+ delete_address(input: $data) {
103
95
  id
104
96
  }
105
97
  }
106
98
  """,
107
- operation_name="delete_template",
108
- variables=delete_template_data,
99
+ operation_name="delete_address",
100
+ variables=delete_data,
109
101
  )
110
- response_data = response.data
111
102
 
112
103
  self.assertResponseNoErrors(response)
113
- self.assertEqual(response_data["data"]["delete_template"]["id"], template_id)
114
- self.assertEqual(len(graph.Template.objects.all()), 0)
104
+ self.assertEqual(response.data["data"]["delete_address"]["id"], address_id)
115
105
  self.assertEqual(len(manager.Address.objects.all()), 0)
116
106
 
117
107
 
118
- class TestParcelTemplate(GraphTestCase):
119
- def _create_parcel_template(self):
108
+ class TestParcel(GraphTestCase):
109
+ def _create_parcel(self):
120
110
  return self.query(
121
111
  """
122
- mutation create_parcel_template($data: CreateParcelTemplateInput!) {
123
- create_parcel_template(input: $data) {
124
- template {
112
+ mutation create_parcel($data: CreateParcelInput!) {
113
+ create_parcel(input: $data) {
114
+ parcel {
125
115
  id
126
- is_default
127
- label
128
- parcel {
129
- width
130
- height
131
- length
132
- dimension_unit
133
- weight
134
- weight_unit
135
- packaging_type
136
- package_preset
137
- }
116
+ meta
117
+ width
118
+ height
119
+ length
120
+ dimension_unit
121
+ weight
122
+ weight_unit
123
+ packaging_type
124
+ package_preset
138
125
  }
139
126
  errors {
140
127
  field
@@ -143,37 +130,33 @@ class TestParcelTemplate(GraphTestCase):
143
130
  }
144
131
  }
145
132
  """,
146
- operation_name="create_parcel_template",
147
- variables=PARCEL_TEMPLATE_DATA,
133
+ operation_name="create_parcel",
134
+ variables=PARCEL_DATA,
148
135
  )
149
136
 
150
- def test_create_parcel_template(self):
151
- response = self._create_parcel_template()
152
- response_data = response.data
137
+ def test_create_parcel(self):
138
+ response = self._create_parcel()
153
139
 
154
140
  self.assertResponseNoErrors(response)
155
- self.assertDictEqual(response_data, PARCEL_TEMPLATE_RESPONSE)
141
+ self.assertDictEqual(response.data, PARCEL_RESPONSE)
156
142
 
157
- def test_update_parcel_template(self):
158
- template = self._create_parcel_template().data
143
+ def test_update_parcel(self):
144
+ parcel = self._create_parcel().data
159
145
  response = self.query(
160
146
  """
161
- mutation update_parcel_template($data: UpdateParcelTemplateInput!) {
162
- update_parcel_template(input: $data) {
163
- template {
147
+ mutation update_parcel($data: UpdateParcelInput!) {
148
+ update_parcel(input: $data) {
149
+ parcel {
164
150
  id
165
- is_default
166
- label
167
- parcel {
168
- width
169
- height
170
- length
171
- dimension_unit
172
- weight
173
- weight_unit
174
- packaging_type
175
- package_preset
176
- }
151
+ meta
152
+ width
153
+ height
154
+ length
155
+ dimension_unit
156
+ weight
157
+ weight_unit
158
+ packaging_type
159
+ package_preset
177
160
  }
178
161
  errors {
179
162
  field
@@ -182,496 +165,331 @@ class TestParcelTemplate(GraphTestCase):
182
165
  }
183
166
  }
184
167
  """,
185
- operation_name="update_parcel_template",
168
+ operation_name="update_parcel",
186
169
  variables={
187
170
  "data": {
188
- "id": template["data"]["create_parcel_template"]["template"]["id"],
189
- **PARCEL_TEMPLATE_UPDATE_DATA["data"],
171
+ "id": parcel["data"]["create_parcel"]["parcel"]["id"],
172
+ **PARCEL_UPDATE_DATA["data"],
190
173
  },
191
174
  },
192
175
  )
193
- response_data = response.data
194
176
 
195
177
  self.assertResponseNoErrors(response)
196
- self.assertDictEqual(response_data, PARCEL_TEMPLATE_UPDATE_RESPONSE)
178
+ self.assertDictEqual(response.data, PARCEL_UPDATE_RESPONSE)
197
179
 
198
- def test_delete_parcel_template(self):
199
- template = self._create_parcel_template().data
200
- template_id = template["data"]["create_parcel_template"]["template"]["id"]
201
- delete_template_data = {"data": {"id": template_id}}
180
+ def test_delete_parcel(self):
181
+ parcel = self._create_parcel().data
182
+ parcel_id = parcel["data"]["create_parcel"]["parcel"]["id"]
183
+ delete_data = {"data": {"id": parcel_id}}
202
184
  response = self.query(
203
185
  """
204
- mutation delete_template($data: DeleteMutationInput!) {
205
- delete_template(input: $data) {
186
+ mutation delete_parcel($data: DeleteMutationInput!) {
187
+ delete_parcel(input: $data) {
206
188
  id
207
189
  }
208
190
  }
209
191
  """,
210
- operation_name="delete_template",
211
- variables=delete_template_data,
192
+ operation_name="delete_parcel",
193
+ variables=delete_data,
212
194
  )
213
- response_data = response.data
214
195
 
215
196
  self.assertResponseNoErrors(response)
216
- self.assertEqual(response_data["data"]["delete_template"]["id"], template_id)
217
- self.assertEqual(len(graph.Template.objects.all()), 0)
197
+ self.assertEqual(response.data["data"]["delete_parcel"]["id"], parcel_id)
218
198
  self.assertEqual(len(manager.Parcel.objects.all()), 0)
219
199
 
220
200
 
221
- class TestCustomsTemplate(GraphTestCase):
222
- def _create_customs_info_template(self):
223
- return self.query(
224
- """
225
- mutation create_customs_template($data: CreateCustomsTemplateInput!) {
226
- create_customs_template(input: $data) {
227
- template {
228
- id
229
- label
230
- is_default
231
- customs {
232
- incoterm
233
- content_type
234
- commercial_invoice
235
- content_description
236
- duty {
237
- paid_by
238
- currency
239
- account_number
240
- declared_value
241
- bill_to {
242
- company_name
243
- person_name
244
- address_line1
245
- address_line2
246
- postal_code
247
- residential
248
- city
249
- state_code
250
- country_code
251
- email
252
- phone_number
253
- validation
254
- validate_location
255
- }
256
- }
257
- invoice
258
- signer
259
- certify
260
- commodities {
261
- id
262
- sku
263
- weight
264
- quantity
265
- weight_unit
266
- description
267
- value_amount
268
- value_currency
269
- origin_country
270
- }
271
- }
272
- }
273
- errors {
274
- field
275
- messages
276
- }
277
- }
278
- }
279
- """,
280
- operation_name="create_customs_template",
281
- variables=CUSTOMS_TEMPLATE_DATA,
282
- )
283
-
284
- def test_create_customs_info_template(self):
285
- response = self._create_customs_info_template()
286
- response_data = response.data
287
-
288
- self.assertResponseNoErrors(response)
289
- self.assertDictEqual(response_data, CUSTOMS_TEMPLATE_RESPONSE)
290
-
291
- def test_update_customs_info_template(self):
292
- template = self._create_customs_info_template().data
293
- CUSTOMS_TEMPLATE_UPDATE_DATA["data"]["id"] = template["data"][
294
- "create_customs_template"
295
- ]["template"]["id"]
296
- CUSTOMS_TEMPLATE_UPDATE_DATA["data"]["customs"]["commodities"][0]["id"] = next(
297
- c["id"]
298
- for c in template["data"]["create_customs_template"]["template"]["customs"][
299
- "commodities"
300
- ]
301
- if c["sku"]
302
- == template["data"]["create_customs_template"]["template"]["customs"][
303
- "commodities"
304
- ][0]["sku"]
305
- )
306
-
307
- response = self.query(
308
- """
309
- mutation update_customs_template($data: UpdateCustomsTemplateInput!) {
310
- update_customs_template(input: $data) {
311
- template {
312
- id
313
- is_default
314
- label
315
- customs {
316
- incoterm
317
- content_type
318
- commercial_invoice
319
- content_description
320
- duty {
321
- paid_by
322
- currency
323
- account_number
324
- declared_value
325
- bill_to {
326
- company_name
327
- person_name
328
- address_line1
329
- address_line2
330
- postal_code
331
- residential
332
- city
333
- state_code
334
- country_code
335
- email
336
- phone_number
337
- validation
338
- validate_location
339
- }
340
- }
341
- invoice
342
- signer
343
- certify
344
- commodities {
345
- id
346
- sku
347
- weight
348
- quantity
349
- weight_unit
350
- description
351
- value_amount
352
- value_currency
353
- origin_country
354
- }
355
- }
356
- }
357
- errors {
358
- field
359
- messages
360
- }
361
- }
362
- }
363
- """,
364
- operation_name="update_customs_template",
365
- variables=CUSTOMS_TEMPLATE_UPDATE_DATA,
366
- )
367
- response_data = response.data
368
-
369
- self.assertResponseNoErrors(response)
370
- self.assertDictEqual(response_data, CUSTOMS_TEMPLATE_UPDATE_RESPONSE)
371
-
372
- def test_delete_customs_info(self):
373
- template = self._create_customs_info_template().data
374
- template_id = template["data"]["create_customs_template"]["template"]["id"]
375
- delete_template_data = {"data": {"id": template_id}}
376
- response = self.query(
377
- """
378
- mutation delete_template($data: DeleteMutationInput!) {
379
- delete_template(input: $data) {
380
- id
381
- }
382
- }
383
- """,
384
- operation_name="delete_template",
385
- variables=delete_template_data,
386
- )
387
- response_data = response.data
388
-
389
- self.assertResponseNoErrors(response)
390
- self.assertEqual(response_data["data"]["delete_template"]["id"], template_id)
391
- self.assertEqual(len(graph.Template.objects.all()), 0)
392
- self.assertEqual(len(manager.Customs.objects.all()), 0)
393
-
394
-
395
- ADDRESS_TEMPLATE_DATA = {
201
+ ADDRESS_DATA = {
396
202
  "data": {
397
- "label": "Warehouse",
398
- "address": {
399
- "address_line1": "125 Church St",
400
- "person_name": "John Doe",
401
- "company_name": "A corp.",
402
- "phone_number": "514 000 0000",
403
- "city": "Moncton",
404
- "country_code": "CA",
405
- "postal_code": "E1C4Z8",
406
- "residential": False,
407
- "state_code": "NB",
408
- },
203
+ "address_line1": "125 Church St",
204
+ "person_name": "John Doe",
205
+ "company_name": "A corp.",
206
+ "phone_number": "514 000 0000",
207
+ "city": "Moncton",
208
+ "country_code": "CA",
209
+ "postal_code": "E1C4Z8",
210
+ "residential": False,
211
+ "state_code": "NB",
212
+ "meta": {"label": "Warehouse"},
409
213
  }
410
214
  }
411
215
 
412
- ADDRESS_TEMPLATE_RESPONSE = {
216
+ ADDRESS_RESPONSE = {
413
217
  "data": {
414
- "create_address_template": {
415
- "template": {
218
+ "create_address": {
219
+ "address": {
416
220
  "id": ANY,
417
- "is_default": False,
418
- "label": "Warehouse",
419
- "address": {
420
- "company_name": "A corp.",
421
- "person_name": "John Doe",
422
- "address_line1": "125 Church St",
423
- "address_line2": None,
424
- "postal_code": "E1C4Z8",
425
- "residential": False,
426
- "city": "Moncton",
427
- "state_code": "NB",
428
- "country_code": "CA",
429
- "email": None,
430
- "phone_number": "+1 514-000-0000",
431
- "validation": None,
432
- "validate_location": None,
433
- },
221
+ "meta": {"label": "Warehouse", "is_default": False},
222
+ "company_name": "A corp.",
223
+ "person_name": "John Doe",
224
+ "address_line1": "125 Church St",
225
+ "address_line2": None,
226
+ "postal_code": "E1C4Z8",
227
+ "residential": False,
228
+ "city": "Moncton",
229
+ "state_code": "NB",
230
+ "country_code": "CA",
231
+ "email": None,
232
+ "phone_number": "+1 514-000-0000",
233
+ "validation": None,
234
+ "validate_location": None,
434
235
  },
435
236
  "errors": None,
436
237
  }
437
238
  }
438
239
  }
439
240
 
440
- ADDRESS_TEMPLATE_UPDATE_DATA = {
241
+ ADDRESS_UPDATE_DATA = {
441
242
  "data": {
442
- "label": "Warehouse Update",
443
- "address": {
444
- "city": "Moncton",
445
- "email": "test@gmail.com",
446
- "person_name": "John Moe",
447
- },
243
+ "city": "Moncton",
244
+ "email": "test@gmail.com",
245
+ "person_name": "John Moe",
246
+ "meta": {"label": "Warehouse Update"},
448
247
  }
449
248
  }
450
249
 
451
- ADDRESS_TEMPLATE_UPDATE_RESPONSE = {
250
+ ADDRESS_UPDATE_RESPONSE = {
452
251
  "data": {
453
- "update_address_template": {
454
- "template": {
252
+ "update_address": {
253
+ "address": {
455
254
  "id": ANY,
456
- "address": {
457
- "address_line1": "125 Church St",
458
- "address_line2": None,
459
- "city": "Moncton",
460
- "company_name": "A corp.",
461
- "country_code": "CA",
462
- "email": "test@gmail.com",
463
- "person_name": "John Moe",
464
- "phone_number": "+1 514-000-0000",
465
- "postal_code": "E1C4Z8",
466
- "residential": False,
467
- "state_code": "NB",
468
- "validate_location": None,
469
- "validation": None,
470
- },
471
- "id": ANY,
472
- "is_default": False,
473
- "label": "Warehouse Update",
255
+ "meta": {"label": "Warehouse Update", "is_default": False},
256
+ "address_line1": "125 Church St",
257
+ "address_line2": None,
258
+ "city": "Moncton",
259
+ "company_name": "A corp.",
260
+ "country_code": "CA",
261
+ "email": "test@gmail.com",
262
+ "person_name": "John Moe",
263
+ "phone_number": "+1 514-000-0000",
264
+ "postal_code": "E1C4Z8",
265
+ "residential": False,
266
+ "state_code": "NB",
267
+ "validate_location": None,
268
+ "validation": None,
474
269
  },
475
270
  "errors": None,
476
271
  }
477
272
  }
478
273
  }
479
274
 
480
- PARCEL_TEMPLATE_DATA = {
275
+ PARCEL_DATA = {
481
276
  "data": {
482
- "label": "Purple Pack",
483
- "parcel": {
484
- "weight": 1,
485
- "weight_unit": "KG",
486
- "package_preset": "canadapost_corrugated_small_box",
487
- },
277
+ "weight": 1,
278
+ "weight_unit": "KG",
279
+ "package_preset": "canadapost_corrugated_small_box",
280
+ "meta": {"label": "Purple Pack"},
488
281
  }
489
282
  }
490
283
 
491
- PARCEL_TEMPLATE_RESPONSE = {
284
+ PARCEL_RESPONSE = {
492
285
  "data": {
493
- "create_parcel_template": {
286
+ "create_parcel": {
494
287
  "errors": None,
495
- "template": {
288
+ "parcel": {
496
289
  "id": ANY,
497
- "is_default": False,
498
- "label": "Purple Pack",
499
- "parcel": {
500
- "dimension_unit": "CM",
501
- "height": 32.0,
502
- "length": 32.0,
503
- "package_preset": "canadapost_corrugated_small_box",
504
- "packaging_type": None,
505
- "weight": 1.0,
506
- "weight_unit": "KG",
507
- "width": 42.0,
508
- },
290
+ "meta": {"label": "Purple Pack", "is_default": False},
291
+ "dimension_unit": "CM",
292
+ "height": 32.0,
293
+ "length": 32.0,
294
+ "package_preset": "canadapost_corrugated_small_box",
295
+ "packaging_type": None,
296
+ "weight": 1.0,
297
+ "weight_unit": "KG",
298
+ "width": 42.0,
509
299
  },
510
300
  }
511
301
  }
512
302
  }
513
303
 
514
- PARCEL_TEMPLATE_UPDATE_DATA = {
304
+ PARCEL_UPDATE_DATA = {
515
305
  "data": {
516
- "parcel": {
517
- "weight": 0.45,
518
- "weight_unit": "LB",
519
- }
306
+ "weight": 0.45,
307
+ "weight_unit": "LB",
520
308
  }
521
309
  }
522
310
 
523
- PARCEL_TEMPLATE_UPDATE_RESPONSE = {
311
+ PARCEL_UPDATE_RESPONSE = {
524
312
  "data": {
525
- "update_parcel_template": {
313
+ "update_parcel": {
526
314
  "errors": None,
527
- "template": {
315
+ "parcel": {
528
316
  "id": ANY,
529
- "is_default": False,
530
- "label": "Purple Pack",
531
- "parcel": {
532
- "dimension_unit": "CM",
533
- "height": 32.0,
534
- "length": 32.0,
535
- "package_preset": "canadapost_corrugated_small_box",
536
- "packaging_type": None,
537
- "weight": 0.45,
538
- "weight_unit": "LB",
539
- "width": 42.0,
540
- },
317
+ "meta": {"label": "Purple Pack", "is_default": False},
318
+ "dimension_unit": "CM",
319
+ "height": 32.0,
320
+ "length": 32.0,
321
+ "package_preset": "canadapost_corrugated_small_box",
322
+ "packaging_type": None,
323
+ "weight": 0.45,
324
+ "weight_unit": "LB",
325
+ "width": 42.0,
541
326
  },
542
327
  }
543
328
  }
544
329
  }
545
330
 
546
- CUSTOMS_TEMPLATE_DATA = {
547
- "data": {
548
- "label": "Customs info template",
549
- "customs": {
550
- "content_type": "documents",
551
- "incoterm": "DDU",
552
- "commodities": [
553
- {"weight": 1.15, "weight_unit": "KG", "sku": "6787L8K7J8L7J8L7K8"},
554
- {
555
- "weight": 0.75,
556
- "weight_unit": "KG",
557
- "sku": "3PO4I5J4PO5I4HI5OH",
558
- "quantity": 4,
331
+
332
+ class TestProduct(GraphTestCase):
333
+ def _create_product(self):
334
+ return self.query(
335
+ """
336
+ mutation create_product($data: CreateProductInput!) {
337
+ create_product(input: $data) {
338
+ product {
339
+ id
340
+ meta
341
+ weight
342
+ weight_unit
343
+ quantity
344
+ sku
345
+ title
346
+ hs_code
347
+ description
348
+ value_amount
349
+ value_currency
350
+ origin_country
351
+ }
352
+ errors {
353
+ field
354
+ messages
355
+ }
356
+ }
357
+ }
358
+ """,
359
+ operation_name="create_product",
360
+ variables=PRODUCT_DATA,
361
+ )
362
+
363
+ def test_create_product(self):
364
+ response = self._create_product()
365
+
366
+ self.assertResponseNoErrors(response)
367
+ self.assertDictEqual(response.data, PRODUCT_RESPONSE)
368
+
369
+ def test_update_product(self):
370
+ product = self._create_product().data
371
+ response = self.query(
372
+ """
373
+ mutation update_product($data: UpdateProductInput!) {
374
+ update_product(input: $data) {
375
+ product {
376
+ id
377
+ meta
378
+ weight
379
+ weight_unit
380
+ quantity
381
+ sku
382
+ title
383
+ hs_code
384
+ description
385
+ value_amount
386
+ value_currency
387
+ origin_country
388
+ }
389
+ errors {
390
+ field
391
+ messages
392
+ }
393
+ }
394
+ }
395
+ """,
396
+ operation_name="update_product",
397
+ variables={
398
+ "data": {
399
+ "id": product["data"]["create_product"]["product"]["id"],
400
+ **PRODUCT_UPDATE_DATA["data"],
559
401
  },
560
- ],
561
- },
402
+ },
403
+ )
404
+
405
+ self.assertResponseNoErrors(response)
406
+ self.assertDictEqual(response.data, PRODUCT_UPDATE_RESPONSE)
407
+
408
+ def test_delete_product(self):
409
+ product = self._create_product().data
410
+ product_id = product["data"]["create_product"]["product"]["id"]
411
+ delete_data = {"data": {"id": product_id}}
412
+ response = self.query(
413
+ """
414
+ mutation delete_product($data: DeleteMutationInput!) {
415
+ delete_product(input: $data) {
416
+ id
417
+ }
418
+ }
419
+ """,
420
+ operation_name="delete_product",
421
+ variables=delete_data,
422
+ )
423
+
424
+ self.assertResponseNoErrors(response)
425
+ self.assertEqual(response.data["data"]["delete_product"]["id"], product_id)
426
+ self.assertEqual(len(manager.Commodity.objects.filter(meta__label__isnull=False)), 0)
427
+
428
+
429
+ PRODUCT_DATA = {
430
+ "data": {
431
+ "weight": 1.5,
432
+ "weight_unit": "KG",
433
+ "quantity": 1,
434
+ "sku": "TEST-SKU-001",
435
+ "title": "Test Product Title",
436
+ "hs_code": "123456",
437
+ "description": "A test product",
438
+ "value_amount": 99.99,
439
+ "value_currency": "USD",
440
+ "origin_country": "US",
441
+ "meta": {"label": "Test Product"},
562
442
  }
563
443
  }
564
444
 
565
- CUSTOMS_TEMPLATE_RESPONSE = {
445
+ PRODUCT_RESPONSE = {
566
446
  "data": {
567
- "create_customs_template": {
568
- "template": {
447
+ "create_product": {
448
+ "errors": None,
449
+ "product": {
569
450
  "id": ANY,
570
- "label": "Customs info template",
571
- "is_default": False,
572
- "customs": {
573
- "incoterm": "DDU",
574
- "content_type": "documents",
575
- "commercial_invoice": None,
576
- "content_description": None,
577
- "duty": None,
578
- "invoice": None,
579
- "signer": None,
580
- "certify": None,
581
- "commodities": [
582
- {
583
- "id": ANY,
584
- "sku": "6787L8K7J8L7J8L7K8",
585
- "weight": 1.15,
586
- "quantity": 1,
587
- "weight_unit": "KG",
588
- "description": None,
589
- "value_amount": None,
590
- "value_currency": None,
591
- "origin_country": None,
592
- },
593
- {
594
- "id": ANY,
595
- "sku": "3PO4I5J4PO5I4HI5OH",
596
- "weight": 0.75,
597
- "quantity": 4,
598
- "weight_unit": "KG",
599
- "description": None,
600
- "value_amount": None,
601
- "value_currency": None,
602
- "origin_country": None,
603
- },
604
- ],
605
- },
451
+ "meta": {"label": "Test Product", "is_default": False},
452
+ "weight": 1.5,
453
+ "weight_unit": "KG",
454
+ "quantity": 1,
455
+ "sku": "TEST-SKU-001",
456
+ "title": "Test Product Title",
457
+ "hs_code": "123456",
458
+ "description": "A test product",
459
+ "value_amount": 99.99,
460
+ "value_currency": "USD",
461
+ "origin_country": "US",
606
462
  },
607
- "errors": None,
608
463
  }
609
464
  }
610
465
  }
611
466
 
612
- CUSTOMS_TEMPLATE_UPDATE_DATA = {
467
+ PRODUCT_UPDATE_DATA = {
613
468
  "data": {
614
- "customs": {
615
- "commodities": [
616
- {
617
- "weight": 1,
618
- "weight_unit": "LB",
619
- }
620
- ],
621
- "duty": {"paid_by": "sender"},
622
- }
469
+ "weight": 2.0,
470
+ "title": "Updated Title",
471
+ "meta": {"label": "Updated Product"},
623
472
  }
624
473
  }
625
474
 
626
- CUSTOMS_TEMPLATE_UPDATE_RESPONSE = {
475
+ PRODUCT_UPDATE_RESPONSE = {
627
476
  "data": {
628
- "update_customs_template": {
629
- "template": {
477
+ "update_product": {
478
+ "errors": None,
479
+ "product": {
630
480
  "id": ANY,
631
- "is_default": False,
632
- "label": "Customs info template",
633
- "customs": {
634
- "incoterm": "DDU",
635
- "content_type": "documents",
636
- "commercial_invoice": None,
637
- "content_description": None,
638
- "duty": {
639
- "paid_by": "sender",
640
- "currency": None,
641
- "account_number": None,
642
- "declared_value": None,
643
- "bill_to": None,
644
- },
645
- "invoice": None,
646
- "signer": None,
647
- "certify": None,
648
- "commodities": [
649
- {
650
- "id": ANY,
651
- "sku": "6787L8K7J8L7J8L7K8",
652
- "weight": 1.0,
653
- "quantity": 1,
654
- "weight_unit": "LB",
655
- "description": None,
656
- "value_amount": None,
657
- "value_currency": None,
658
- "origin_country": None,
659
- },
660
- {
661
- "id": ANY,
662
- "sku": "3PO4I5J4PO5I4HI5OH",
663
- "weight": 0.75,
664
- "quantity": 4,
665
- "weight_unit": "KG",
666
- "description": None,
667
- "value_amount": None,
668
- "value_currency": None,
669
- "origin_country": None,
670
- },
671
- ],
672
- },
481
+ "meta": {"label": "Updated Product", "is_default": False},
482
+ "weight": 2.0,
483
+ "weight_unit": "KG",
484
+ "quantity": 1,
485
+ "sku": "TEST-SKU-001",
486
+ "title": "Updated Title",
487
+ "hs_code": "123456",
488
+ "description": "A test product",
489
+ "value_amount": 99.99,
490
+ "value_currency": "USD",
491
+ "origin_country": "US",
673
492
  },
674
- "errors": None,
675
493
  }
676
494
  }
677
495
  }