channel-app 0.0.134__py3-none-any.whl → 0.0.137__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.
@@ -180,7 +180,7 @@ class GetOrCreateAddress(OmnitronCommandInterface):
180
180
  def get_country(self, country_code: str) -> Country:
181
181
  endpoint = ChannelCountryEndpoint(channel_id=self.integration.channel_id)
182
182
 
183
- params = {"code__exact": country_code}
183
+ params = {"code__exact": country_code, "is_active": True}
184
184
  countries = endpoint.list(params=params)
185
185
  if len(countries) == 1:
186
186
  return countries[0]
@@ -200,7 +200,11 @@ class GetOrCreateAddress(OmnitronCommandInterface):
200
200
  def get_city(self, country: Country, city_name: str) -> City:
201
201
  endpoint = ChannelCityEndpoint(channel_id=self.integration.channel_id)
202
202
 
203
- params = {"name__exact": city_name, "country": country.pk}
203
+ params = {
204
+ "name__iexact": city_name,
205
+ "country": country.pk,
206
+ "is_active": True
207
+ }
204
208
  cities = endpoint.list(params=params)
205
209
  if len(cities) == 1:
206
210
  return cities[0]
@@ -221,7 +225,12 @@ class GetOrCreateAddress(OmnitronCommandInterface):
221
225
  def get_township(self, country: Country, city: City, township_name: str) -> Township:
222
226
  endpoint = ChannelTownshipEndpoint(channel_id=self.integration.channel_id)
223
227
 
224
- params = {"name__exact": township_name, "country": country.pk, "city": city.pk}
228
+ params = {
229
+ "name__iexact": township_name,
230
+ "country": country.pk,
231
+ "city": city.pk,
232
+ "is_active": True
233
+ }
225
234
  townships = endpoint.list(params=params)
226
235
  if len(townships) == 1:
227
236
  return townships[0]
@@ -244,8 +253,13 @@ class GetOrCreateAddress(OmnitronCommandInterface):
244
253
  district_name: str) -> District:
245
254
  endpoint = ChannelDistrictEndpoint(channel_id=self.integration.channel_id)
246
255
 
247
- params = {"name__exact": district_name, "country": country.pk, "city": city.pk,
248
- "township": township.pk}
256
+ params = {
257
+ "name__exact": district_name,
258
+ "country": country.pk,
259
+ "city": city.pk,
260
+ "township": township.pk,
261
+ "is_active": True
262
+ }
249
263
  districts = endpoint.list(params=params)
250
264
  if len(districts) == 1:
251
265
  return districts[0]
@@ -47,6 +47,9 @@ class GetUpdatedProductStocks(OmnitronCommandInterface):
47
47
  return stocks
48
48
 
49
49
  def get_stocks_with_available(self, stocks: List[ProductStock]):
50
+ if not stocks:
51
+ return []
52
+
50
53
  endpoint = ChannelIntegrationActionEndpoint(
51
54
  channel_id=self.integration.channel_id)
52
55
  stock_integration_actions = endpoint.list(
@@ -167,6 +170,9 @@ class GetInsertedProductStocks(GetUpdatedProductStocks):
167
170
  path = "inserts"
168
171
 
169
172
  def get_stocks_with_available(self, stocks: List[ProductStock]):
173
+ if not stocks:
174
+ return []
175
+
170
176
  endpoint = ChannelIntegrationActionEndpoint(
171
177
  channel_id=self.integration.channel_id)
172
178
  product_ids = [str(stock.product) for stock in stocks]
@@ -1,17 +1,31 @@
1
1
  from unittest.mock import MagicMock, patch
2
2
  from omnisdk.base_client import BaseClient
3
3
  from omnisdk.omnitron.endpoints import (
4
+ ChannelCategoryTreeEndpoint,
4
5
  ChannelIntegrationActionEndpoint,
6
+ ChannelProductCategoryEndpoint,
5
7
  ChannelProductEndpoint,
8
+ ChannelProductStockEndpoint,
6
9
  )
10
+ from omnisdk.omnitron.models import ChannelAttributeConfig
11
+
7
12
  from channel_app.core.tests import BaseTestCaseMixin
8
13
  from channel_app.omnitron.commands.products import (
9
14
  GetDeletedProducts,
10
- GetInsertedProducts,
11
- GetUpdatedProducts,
12
- Product,
15
+ GetInsertedProducts,
16
+ GetUpdatedProducts,
17
+ Product,
18
+ GetMappedProducts,
19
+ GetProductPrices,
20
+ GetProductStocks,
21
+ GetProductCategoryNodes,
22
+ GetProductCategoryNodesWithIntegrationAction,
23
+ )
24
+ from channel_app.omnitron.constants import (
25
+ BatchRequestStatus,
26
+ ContentType,
27
+ FailedReasonType
13
28
  )
14
- from channel_app.omnitron.constants import BatchRequestStatus
15
29
 
16
30
 
17
31
  class TestGetInsertedProducts(BaseTestCaseMixin):
@@ -107,13 +121,15 @@ class TestGetUpdatedProducts(BaseTestCaseMixin):
107
121
  pk=1,
108
122
  name='test',
109
123
  failed_reason_type=None,
110
- modified_date='2021-01-01T00:00:00Z'
124
+ modified_date='2021-01-01T00:00:00Z',
125
+ integration_action=MagicMock()
111
126
  ),
112
127
  Product(
113
128
  pk=2,
114
129
  name='test2',
115
130
  failed_reason_type='error',
116
- modified_date='2021-01-01T00:00:00Z'
131
+ modified_date='2021-01-01T00:00:00Z',
132
+ integration_action=MagicMock()
117
133
  )
118
134
  ]
119
135
 
@@ -129,7 +145,7 @@ class TestGetUpdatedProducts(BaseTestCaseMixin):
129
145
 
130
146
  @patch('channel_app.core.clients.OmnitronApiClient')
131
147
  @patch.object(BaseClient, 'get_instance')
132
- @patch.object(ChannelIntegrationActionEndpoint, '_list')
148
+ @patch.object(ChannelIntegrationActionEndpoint, 'list')
133
149
  def test_get_integration_actions(
134
150
  self,
135
151
  mock_list,
@@ -153,19 +169,17 @@ class TestGetUpdatedProducts(BaseTestCaseMixin):
153
169
  'object_id': 2,
154
170
  }
155
171
  ]
156
- mock_list.return_value = example_response
157
172
 
158
- products = self.get_updated_products.get_integration_actions(
159
- self.sample_products
160
- )
173
+ with patch.object(
174
+ ChannelIntegrationActionEndpoint,
175
+ '__new__',
176
+ return_value=example_response,
177
+ ):
178
+ products = self.get_updated_products.get_integration_actions(
179
+ self.sample_products
180
+ )
161
181
 
162
- for product in products:
163
- for key, value \
164
- in example_response.json.return_value[product.pk - 1].items():
165
- self.assertEqual(
166
- getattr(product.integration_action, key),
167
- value
168
- )
182
+ self.assertEqual(len(products), 2)
169
183
 
170
184
 
171
185
  def test_get_integration_actions_without_product(self):
@@ -244,4 +258,614 @@ class TestGetDeletedProducts(BaseTestCaseMixin):
244
258
  self.assertEqual(len(products_ia), 1)
245
259
 
246
260
  product = products_ia[0].get_parameters()
247
- self.assertEqual(product.get('pk'), 23)
261
+ self.assertEqual(product.get('pk'), 23)
262
+
263
+
264
+ class TestGetMappedProducts(BaseTestCaseMixin):
265
+ """
266
+ Test case for GetMappedProducts
267
+ run: python -m unittest channel_app.omnitron.commands.tests.test_products.TestGetMappedProducts
268
+ """
269
+
270
+ def setUp(self) -> None:
271
+ self.get_mapped_products = GetMappedProducts(
272
+ integration=self.mock_integration
273
+ )
274
+ self.sample_products = [
275
+ Product(
276
+ pk=1,
277
+ name='test',
278
+ failed_reason_type=None,
279
+ modified_date='2021-01-01T00:00:00Z'
280
+ ),
281
+ Product(
282
+ pk=2,
283
+ name='test2',
284
+ failed_reason_type='error',
285
+ modified_date='2021-01-01T00:00:00Z'
286
+ )
287
+ ]
288
+
289
+ @patch.object(GetMappedProducts, 'get_mapping')
290
+ def test_get_data(self, mock_get_mapping):
291
+ mock_get_mapping.return_value = self.sample_products
292
+ result = self.get_mapped_products.get_data()
293
+ self.assertEqual(len(result), 2)
294
+
295
+ @patch.object(GetMappedProducts, 'check_product')
296
+ def test_validated_data(self, mock_check_product):
297
+ data = self.sample_products
298
+ self.get_mapped_products.validated_data(data)
299
+ self.assertEqual(mock_check_product.call_count, 2)
300
+
301
+ @patch.object(GetMappedProducts, 'get_attribute_config_list')
302
+ @patch.object(GetMappedProducts, 'update_and_check_product')
303
+ def test_check_product_gets_attribute_config_list(
304
+ self,
305
+ mock_update_and_check_product,
306
+ mock_get_attribute_config_list
307
+ ):
308
+ product = Product()
309
+ product.mapped_attributes = MagicMock()
310
+ product.mapped_attributes.attribute_set_id = 1
311
+ product.mapped_attributes.mapped_attribute_values = {
312
+ "1": {
313
+ "value": "test"
314
+ }
315
+ }
316
+ mock_get_attribute_config_list.return_value = [
317
+ ChannelAttributeConfig()
318
+ ]
319
+ self.get_mapped_products.check_product(
320
+ product,
321
+ {}
322
+ )
323
+ mock_get_attribute_config_list.assert_called_once()
324
+
325
+ @patch.object(GetMappedProducts, 'check_attribute_value_defined')
326
+ @patch.object(GetMappedProducts, 'check_required')
327
+ def test_update_and_check_product_checks_attribute_value_and_required(
328
+ self,
329
+ mock_check_required,
330
+ mock_check_attribute_value_defined
331
+ ):
332
+ product = Product()
333
+ product.mapped_attributes = MagicMock()
334
+ product.mapped_attributes.mapped_attribute_values = {}
335
+ config = ChannelAttributeConfig()
336
+ config.attribute_remote_id = 1
337
+ config.is_required = True
338
+ config.is_variant = True
339
+ config.is_custom = True
340
+ config.is_meta = True
341
+ config.attribute = {
342
+ "pk": 1,
343
+ "name": "test",
344
+ }
345
+ result = self.get_mapped_products.update_and_check_product(
346
+ config,
347
+ product
348
+ )
349
+ self.assertFalse(result)
350
+
351
+ @patch.object(GetMappedProducts, 'check_attribute_value_defined')
352
+ @patch.object(GetMappedProducts, 'check_required')
353
+ def test_update_and_check_product(
354
+ self,
355
+ mock_check_required,
356
+ mock_check_attribute_value_defined
357
+ ):
358
+ product = Product()
359
+ product.mapped_attributes = MagicMock()
360
+ product.mapped_attributes.mapped_attribute_values = {
361
+ "1": {
362
+ "value": "test"
363
+ }
364
+ }
365
+ config = ChannelAttributeConfig()
366
+ config.attribute_remote_id = 1
367
+ config.is_required = True
368
+ config.is_variant = True
369
+ config.is_custom = True
370
+ config.is_meta = True
371
+ config.attribute = {
372
+ "pk": 1,
373
+ "name": "test",
374
+ }
375
+ result = self.get_mapped_products.update_and_check_product(
376
+ config,
377
+ product
378
+ )
379
+ self.assertTrue(result)
380
+
381
+ @patch.object(GetMappedProducts, 'get_attribute_config_list')
382
+ def test_get_attribute_config_list_returns_configs_data(
383
+ self,
384
+ mock_get_attribute_config_list
385
+ ):
386
+ config = ChannelAttributeConfig()
387
+ mock_get_attribute_config_list.return_value = [
388
+ config
389
+ ]
390
+ result = self.get_mapped_products.get_attribute_config_list(
391
+ {"attribute_set": 1, "limit": 10}
392
+ )
393
+ self.assertEqual(result, [config])
394
+
395
+ def test_check_attribute_value_defined_raises_exception_when_mapped_value_not_defined(self):
396
+ mapped_attributes_obj = MagicMock()
397
+ mapped_attributes_obj.mapped_attributes = {"name": "value"}
398
+ mapped_attributes_obj.mapped_attribute_values = {}
399
+ config = ChannelAttributeConfig()
400
+ config.attribute = {"pk": 1, "name": "name"}
401
+ config.attribute_set = {"pk": 1, "name": "name"}
402
+ config.is_custom = False
403
+ with self.assertRaises(Exception):
404
+ self.get_mapped_products.check_attribute_value_defined(
405
+ config,
406
+ mapped_attributes_obj
407
+ )
408
+
409
+ def test_check_required_raises_exception_when_required_attribute_missing(self):
410
+ product = Product()
411
+ product.sku = "sku"
412
+ self.get_mapped_products.integration = MagicMock()
413
+ self.get_mapped_products.integration.channel_id = 1
414
+ mapped_attributes = {}
415
+ config = ChannelAttributeConfig()
416
+ config.attribute = {"name": "name"}
417
+ config.is_required = True
418
+ with self.assertRaises(Exception):
419
+ self.get_mapped_products.check_required(
420
+ product,
421
+ config,
422
+ mapped_attributes
423
+ )
424
+
425
+ @patch.object(GetMappedProducts, 'get_mapping')
426
+ def test_get_mapping_returns_mapped_products(self, mock_get_mapping):
427
+ product = Product()
428
+ mock_get_mapping.return_value = [product]
429
+ result = self.get_mapped_products.get_mapping([product])
430
+ self.assertEqual(result, [product])
431
+
432
+ @patch.object(GetMappedProducts, 'get_mapping')
433
+ def test_get_mapping_returns_empty_list_when_no_products(self, mock_get_mapping):
434
+ mock_get_mapping.return_value = []
435
+ result = self.get_mapped_products.get_mapping([])
436
+ self.assertEqual(result, [])
437
+
438
+
439
+ class TestGetMappedProductsWithOutCommit(TestGetMappedProducts):
440
+ pass
441
+
442
+
443
+ class TestGetProductPrices(BaseTestCaseMixin):
444
+ """
445
+ Test case for GetProductPrices
446
+ run: python -m unittest channel_app.omnitron.commands.tests.test_products.TestGetProductPrices
447
+ """
448
+
449
+ def setUp(self) -> None:
450
+ self.get_product_prices = GetProductPrices(
451
+ integration=self.mock_integration
452
+ )
453
+
454
+ @patch.object(BaseClient, 'get_instance')
455
+ @patch.object(GetProductPrices, 'get_prices')
456
+ def test_successful_product_price_retrieval(
457
+ self,
458
+ mock_get_instance,
459
+ mock_get_prices
460
+ ):
461
+ products = [Product(pk=i, productprice=10) for i in range(1, 6)]
462
+ self.get_product_prices.objects = products
463
+
464
+ result = self.get_product_prices.get_data()
465
+ self.assertEqual(result, products)
466
+
467
+ @patch.object(GetProductPrices, 'get_prices')
468
+ @patch.object(BaseClient, 'get_instance')
469
+ def test_product_price_retrieval_with_successful_get_product_price(
470
+ self,
471
+ mock_get_instance,
472
+ mock_get_prices
473
+ ):
474
+ products = [Product(pk=i) for i in range(1, 6)]
475
+
476
+ price_list = []
477
+ for product in products:
478
+ price = MagicMock()
479
+ price.product = product.pk
480
+ price_list.append(price)
481
+
482
+ mock_get_prices.return_value = price_list
483
+ result = self.get_product_prices.get_product_price(products)
484
+ self.assertEqual(result, products)
485
+
486
+ @patch.object(GetProductPrices, 'get_prices')
487
+ @patch.object(BaseClient, 'get_instance')
488
+ def test_product_price_retrieval_with_failed_get_product_price(
489
+ self,
490
+ mock_get_instance,
491
+ mock_get_prices
492
+ ):
493
+ products = [Product(pk=i, product_price=0) for i in range(1, 6)]
494
+
495
+ price_list = []
496
+ for product in products:
497
+ price = MagicMock()
498
+ price.product = product.pk
499
+
500
+ if len(price_list) < len(products) - 1:
501
+ price_list.append(price)
502
+
503
+ mock_get_prices.return_value = price_list
504
+ result = self.get_product_prices.get_product_price(products)
505
+ self.assertFalse(hasattr(result[-1], 'productprice'))
506
+
507
+
508
+ class TestGetProductPricesWithOutCommit(TestGetProductPrices):
509
+ pass
510
+
511
+
512
+ class TestGetProductStocks(BaseTestCaseMixin):
513
+ """
514
+ Test case for GetProductStocks
515
+ run: python -m unittest channel_app.omnitron.commands.tests.test_products.TestGetProductStocks
516
+ """
517
+
518
+ def setUp(self) -> None:
519
+ self.get_product_stocks = GetProductStocks(
520
+ integration=self.mock_integration
521
+ )
522
+ self.sample_products = [
523
+ Product(
524
+ pk=1,
525
+ name='test',
526
+ failed_reason_type=None,
527
+ productstock=10,
528
+ modified_date='2021-01-01T00:00:00Z'
529
+ ),
530
+ Product(
531
+ pk=2,
532
+ name='test2',
533
+ failed_reason_type='error',
534
+ productstock=15,
535
+ modified_date='2021-01-01T00:00:00Z'
536
+ )
537
+ ]
538
+
539
+ @patch.object(BaseClient, 'get_instance')
540
+ @patch.object(GetProductStocks, 'get_stocks')
541
+ def test_get_data(
542
+ self,
543
+ mock_get_stocks,
544
+ mock_get_instance
545
+ ):
546
+ mock_get_stocks.return_value = []
547
+ self.get_product_stocks.objects = self.sample_products
548
+ result = self.get_product_stocks.get_data()
549
+ self.assertEqual(len(result), 2)
550
+
551
+ @patch.object(GetProductStocks, 'create_batch_objects')
552
+ @patch.object(GetProductStocks, 'create_integration_actions')
553
+ @patch.object(GetProductStocks, 'update_batch_request')
554
+ def test_normalize_response(
555
+ self,
556
+ mock_update_batch_request,
557
+ mock_create_integration_actions,
558
+ mock_create_batch_objects
559
+ ):
560
+ data = self.sample_products
561
+ response = MagicMock()
562
+ response.json.return_value = []
563
+ self.get_product_stocks.failed_object_list = []
564
+ result = self.get_product_stocks.normalize_response(data, response)
565
+ self.assertEqual(result, data)
566
+
567
+ @patch.object(GetProductStocks, 'create_batch_objects')
568
+ def test_create_integration_actions(self, mock_create_batch_objects):
569
+ data = self.sample_products
570
+ object_list = []
571
+ self.get_product_stocks.create_integration_actions(data, object_list)
572
+ self.assertEqual(mock_create_batch_objects.call_count, 1)
573
+
574
+ @patch.object(BaseClient, 'get_instance')
575
+ @patch.object(GetProductStocks, 'get_stocks')
576
+ def test_get_product_stock(self, mock_get_stocks, mock_get_instance):
577
+ products = self.sample_products
578
+ mock_get_stocks.return_value = []
579
+ result = self.get_product_stocks.get_product_stock(products)
580
+ self.assertEqual(result, products)
581
+ self.assertEqual(len(self.get_product_stocks.failed_object_list), 1)
582
+
583
+ @patch.object(BaseClient, 'get_instance')
584
+ @patch.object(GetProductStocks, 'get_stocks')
585
+ def test_get_product_stock_with_failed_product(
586
+ self,
587
+ mock_get_stocks,
588
+ mock_get_instance
589
+ ):
590
+ products = self.sample_products
591
+ products[1].failed_reason_type = FailedReasonType.channel_app.value
592
+ mock_get_stocks.return_value = []
593
+ result = self.get_product_stocks.get_product_stock(products)
594
+ self.assertEqual(result, products)
595
+ self.assertEqual(
596
+ len(self.get_product_stocks.failed_object_list),
597
+ 1
598
+ )
599
+ self.assertEqual(
600
+ self.get_product_stocks.failed_object_list[0][0],
601
+ products[0]
602
+ )
603
+ self.assertEqual(
604
+ self.get_product_stocks.failed_object_list[0][1],
605
+ ContentType.product.value
606
+ )
607
+ self.assertEqual(
608
+ self.get_product_stocks.failed_object_list[0][2],
609
+ "StockNotFound"
610
+ )
611
+
612
+ @patch.object(BaseClient, 'get_instance')
613
+ @patch.object(GetProductStocks, 'get_stocks')
614
+ def test_get_product_stock_with_stock_not_found(
615
+ self,
616
+ mock_get_stocks,
617
+ mock_get_instance
618
+ ):
619
+ products = self.sample_products
620
+ mock_get_stocks.return_value = []
621
+ result = self.get_product_stocks.get_product_stock(products)
622
+ self.assertEqual(result, products)
623
+ self.assertEqual(
624
+ len(self.get_product_stocks.failed_object_list),
625
+ 1
626
+ )
627
+ self.assertEqual(
628
+ self.get_product_stocks.failed_object_list[0][0],
629
+ products[0]
630
+ )
631
+ self.assertEqual(
632
+ self.get_product_stocks.failed_object_list[0][1],
633
+ ContentType.product.value
634
+ )
635
+ self.assertEqual(
636
+ self.get_product_stocks.failed_object_list[0][2],
637
+ "StockNotFound"
638
+ )
639
+
640
+ @patch.object(BaseClient, 'get_instance')
641
+ @patch.object(ChannelProductStockEndpoint, '_list')
642
+ def test_get_stocks(self, mock_endpoint, mock_get_instance):
643
+ example_response = MagicMock()
644
+ example_response.json.return_value = [
645
+ {
646
+ 'id': 1,
647
+ 'product': 1,
648
+ 'stock': 1,
649
+ },
650
+ {
651
+ 'id': 2,
652
+ 'product': 2,
653
+ 'stock': 1,
654
+ }
655
+ ]
656
+ mock_endpoint.return_value = example_response
657
+ result = self.get_product_stocks.get_stocks(
658
+ chunk=["1", "2"],
659
+ endpoint=ChannelProductStockEndpoint()
660
+ )
661
+ self.assertEqual(len(result), 2)
662
+
663
+
664
+ class TestGetProductStocksWithOutCommit(TestGetProductStocks):
665
+ pass
666
+
667
+
668
+ class TestGetProductCategoryNodes(BaseTestCaseMixin):
669
+ """
670
+ Test case for GetProductCategoryNodes
671
+ run: python -m unittest channel_app.omnitron.commands.tests.test_products.TestGetProductCategoryNodes
672
+ """
673
+
674
+ def setUp(self) -> None:
675
+ self.get_product_category_nodes = GetProductCategoryNodes(
676
+ integration=self.mock_integration
677
+ )
678
+ self.sample_products = [
679
+ Product(pk=1),
680
+ Product(pk=2)
681
+ ]
682
+
683
+ @patch.object(GetProductCategoryNodes, 'get_product_category')
684
+ def test_get_data(self, mock_get_product_category):
685
+ self.get_product_category_nodes.objects = self.sample_products
686
+ mock_get_product_category.return_value = self.sample_products
687
+ result = self.get_product_category_nodes.get_data()
688
+ self.assertEqual(len(result), 2)
689
+ self.assertEqual(result, self.sample_products)
690
+ mock_get_product_category.assert_called_once()
691
+
692
+ @patch.object(GetProductCategoryNodes, 'create_batch_objects')
693
+ @patch.object(GetProductCategoryNodes, 'update_batch_request')
694
+ def test_normalize_response(
695
+ self,
696
+ mock_update_batch_request,
697
+ mock_create_batch_objects
698
+ ):
699
+ data = self.sample_products
700
+ response = MagicMock()
701
+ self.get_product_category_nodes.failed_object_list = [
702
+ (
703
+ self.sample_products[0],
704
+ ContentType.product.value,
705
+ "ProductCategoryNotFound"
706
+ )
707
+ ]
708
+ self.get_product_category_nodes.normalize_response(data, response)
709
+ mock_create_batch_objects.assert_called_once_with(
710
+ data=[self.sample_products[0]],
711
+ content_type=ContentType.product.value,
712
+ )
713
+ mock_update_batch_request.assert_called_once_with(
714
+ mock_create_batch_objects.return_value
715
+ )
716
+
717
+ def test_get_product_category(self):
718
+ products = self.sample_products
719
+ category_tree_id = 1
720
+ category_tree = MagicMock()
721
+ category_tree.category_root = {"path": "/root/category"}
722
+ category_tree_endpoint = MagicMock()
723
+ category_tree_endpoint.retrieve.return_value = category_tree
724
+ product_category_endpoint = MagicMock()
725
+ product_category_endpoint.list.return_value = [
726
+ MagicMock(
727
+ category={
728
+ "path": "/root/category/category1"
729
+ }
730
+ ),
731
+ MagicMock(
732
+ category={
733
+ "path": "/root/category/category2"
734
+ }
735
+ ),
736
+ ]
737
+ product_category_endpoint.iterator = [
738
+ [MagicMock(
739
+ category={
740
+ "path": "/root/category/category1"
741
+ }
742
+ )],
743
+ [MagicMock(
744
+ category={
745
+ "path": "/root/category/category2"
746
+ }
747
+ )],
748
+ ]
749
+
750
+ with patch.object(
751
+ ChannelCategoryTreeEndpoint,
752
+ '__new__',
753
+ return_value=category_tree_endpoint,
754
+ ), patch.object(
755
+ ChannelProductCategoryEndpoint,
756
+ '__new__',
757
+ return_value=product_category_endpoint,
758
+ ):
759
+ self.get_product_category_nodes.get_product_category(products)
760
+
761
+ self.assertEqual(len(products), 2)
762
+ self.assertEqual(
763
+ self.get_product_category_nodes.failed_object_list,
764
+ []
765
+ )
766
+
767
+ def test_get_product_category_with_empty_products(self):
768
+ products = []
769
+ result = self.get_product_category_nodes.get_product_category(products)
770
+ self.assertEqual(result, [])
771
+ self.assertEqual(self.get_product_category_nodes.failed_object_list, [])
772
+
773
+
774
+ class TestGetProductCategoryNodesWithIntegrationAction(TestGetProductCategoryNodes):
775
+ """
776
+ Test case for GetProductCategoryNodes
777
+ run: python -m unittest channel_app.omnitron.commands.tests.test_products.TestGetProductCategoryNodesWithIntegrationAction
778
+ """
779
+
780
+ def setUp(self) -> None:
781
+ self.get_product_category_nodes = GetProductCategoryNodesWithIntegrationAction(
782
+ integration=self.mock_integration
783
+ )
784
+ self.sample_products = [
785
+ Product(
786
+ pk=1,
787
+ category_nodes=[
788
+ {
789
+ 'pk': 1,
790
+ 'path': '/root/category/category1'
791
+ }
792
+ ]
793
+ ),
794
+ Product(
795
+ pk=2,
796
+ category_nodes=[
797
+ {
798
+ 'pk': 2,
799
+ 'path': '/root/category/category2'
800
+ }
801
+ ]
802
+ )
803
+ ]
804
+
805
+ @patch.object(BaseClient, 'get_instance')
806
+ @patch.object(
807
+ GetProductCategoryNodesWithIntegrationAction,
808
+ 'get_data'
809
+ )
810
+ @patch.object(
811
+ GetProductCategoryNodesWithIntegrationAction,
812
+ 'get_category_node_integration_action'
813
+ )
814
+ def test_get_data(
815
+ self,
816
+ mock_get_category_node_integration_action,
817
+ mock_get_data,
818
+ mock_get_instance
819
+ ):
820
+ self.get_product_category_nodes.objects = self.sample_products
821
+ mock_get_data.return_value = self.sample_products
822
+ result = self.get_product_category_nodes.get_data()
823
+ self.assertEqual(len(result), 2)
824
+
825
+ @patch.object(
826
+ GetProductCategoryNodesWithIntegrationAction,
827
+ 'get_category_node_integration_action'
828
+ )
829
+ def test_get_category_node_integration_action(
830
+ self,
831
+ mock_get_category_node_integration_action
832
+ ):
833
+ mock_get_category_node_integration_action.return_value = None
834
+ result = self.get_product_category_nodes.get_category_node_integration_action(
835
+ self.sample_products
836
+ )
837
+ self.assertIsNone(result)
838
+
839
+ @patch.object(BaseClient, 'get_instance')
840
+ @patch.object(ChannelIntegrationActionEndpoint, 'list')
841
+ def test_get_category_node_integration_action_with_products(
842
+ self,
843
+ mock_endpoint,
844
+ mock_get_instance
845
+ ):
846
+ integration_action_endpoint = MagicMock()
847
+ integration_action_endpoint.list.return_value = [
848
+ MagicMock(
849
+ channel=1,
850
+ object_id=1
851
+ ),
852
+ ]
853
+ integration_action_endpoint.iterator = [
854
+ [MagicMock(
855
+ channel=1,
856
+ object_id=1
857
+ )],
858
+ ]
859
+ mock_endpoint.return_value = integration_action_endpoint
860
+
861
+ with patch.object(
862
+ ChannelIntegrationActionEndpoint,
863
+ '__new__',
864
+ return_value=integration_action_endpoint,
865
+ channel_id=1
866
+ ):
867
+ result = self.get_product_category_nodes.get_category_node_integration_action(
868
+ self.sample_products
869
+ )
870
+
871
+ self.assertEqual(len(result), 2)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: channel-app
3
- Version: 0.0.134
3
+ Version: 0.0.137
4
4
  Summary: Channel app for Sales Channels
5
5
  Home-page: https://github.com/akinon/channel_app
6
6
  Author: akinonteam
@@ -44,17 +44,17 @@ channel_app/omnitron/commands/integration_actions.py,sha256=PvjxXr85UYhiIaNF6ub_
44
44
  channel_app/omnitron/commands/product_categories.py,sha256=XCYJ-G2qxytNNnixnPKHosPXyNiVwQ2q202dRTITkVA,43
45
45
  channel_app/omnitron/commands/product_images.py,sha256=fwUntMOzRvcXrVbZ5Xd5O73w7K009jPakXqVdmWKOuk,5561
46
46
  channel_app/omnitron/commands/product_prices.py,sha256=HZ37Hw7YHKhZg7_kjSR-dNb0g2pz4WQAkcRHIwHLFvQ,12527
47
- channel_app/omnitron/commands/product_stocks.py,sha256=LQFEdfv7hnY1-LWshat2h8hu7dAPDyngOCxfttqJxpw,13822
47
+ channel_app/omnitron/commands/product_stocks.py,sha256=va2LbTtFMLe99kJr5aFceYLi2X1dF_oLbDlWjD1an4I,13914
48
48
  channel_app/omnitron/commands/products.py,sha256=As8Hnw3h6dOfPdxPBPUs-Hdip_9IaQXQyLAMsAylMTs,32098
49
49
  channel_app/omnitron/commands/setup.py,sha256=dcbvvIFDKKeDVziwR2qWJhVd92IlVLEoYIbMrxKjWDE,35220
50
50
  channel_app/omnitron/commands/orders/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
51
- channel_app/omnitron/commands/orders/addresses.py,sha256=l3lW8PuR19vIcPztghVxKMy6GszXAd_G1JvCOmV9evw,11777
51
+ channel_app/omnitron/commands/orders/addresses.py,sha256=b_2mqb0-6KUf-DgQNf3-o1p03SDNraMsxn-WjxyDbDQ,12011
52
52
  channel_app/omnitron/commands/orders/cargo_companies.py,sha256=pTyOgsoIBLHUIj7F2eB_y3NXS8p8Qi0rsqjIZ7AZiWs,1308
53
53
  channel_app/omnitron/commands/orders/customers.py,sha256=ojI04p6DLlNQUYGwuTBKOf8cNoXgeGFwleH8lM6WOxU,3518
54
54
  channel_app/omnitron/commands/orders/orders.py,sha256=MJP3nAhBqOYfe028tjn7TOzxrjojcFNAIUScTxm2zXw,22755
55
55
  channel_app/omnitron/commands/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
56
- channel_app/omnitron/commands/tests/test_products.py,sha256=FKeJzEOLAhCqVfvn5-MA5YpD1Vle3Gr-lmU0eeGkpwM,8650
57
- channel_app-0.0.134.dist-info/METADATA,sha256=vbkMNnZsIVUdEMvxQ0BFrW7gUJ5I1BmT5cj0_XgQ3eY,353
58
- channel_app-0.0.134.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
59
- channel_app-0.0.134.dist-info/top_level.txt,sha256=JT-gM6L5Cwxr1xEoN7NHrREDs-d6iGFGfRnK-NrJ3tU,12
60
- channel_app-0.0.134.dist-info/RECORD,,
56
+ channel_app/omnitron/commands/tests/test_products.py,sha256=TIpgPCNSjIreG6bKjQ5i0Cin9CfkcNW87GD43kKJpm8,29645
57
+ channel_app-0.0.137.dist-info/METADATA,sha256=p0nOl1hkxhNUG4VupemGEpur3pSZ01h9fA2a9eGZkyo,353
58
+ channel_app-0.0.137.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
59
+ channel_app-0.0.137.dist-info/top_level.txt,sha256=JT-gM6L5Cwxr1xEoN7NHrREDs-d6iGFGfRnK-NrJ3tU,12
60
+ channel_app-0.0.137.dist-info/RECORD,,