channel-app 0.0.138__py3-none-any.whl → 0.0.140__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.
@@ -5,29 +5,49 @@ from omnisdk.omnitron.endpoints import (
5
5
  ChannelCategoryTreeEndpoint,
6
6
  ChannelIntegrationActionEndpoint,
7
7
  ChannelProductCategoryEndpoint,
8
- ChannelProductEndpoint,
9
- ChannelProductStockEndpoint,
8
+ ChannelProductEndpoint,
9
+ ChannelProductPriceEndpoint,
10
+ ChannelProductStockEndpoint,
11
+ ChannelExtraProductStockEndpoint,
12
+ ChannelExtraProductPriceEndpoint
13
+ )
14
+ from omnisdk.omnitron.models import (
15
+ ChannelAttributeConfig,
16
+ ProductStock,
17
+ ProductPrice
10
18
  )
11
- from omnisdk.omnitron.models import ChannelAttributeConfig, ProductStock
12
19
 
13
20
  from channel_app.core.commands import OmnitronCommandInterface
14
21
  from channel_app.core.tests import BaseTestCaseMixin
15
22
  from channel_app.omnitron.commands.batch_requests import GetBatchRequests
16
- from channel_app.omnitron.commands.product_stocks import GetInsertedProductStocks, GetUpdatedProductStocks
23
+ from channel_app.omnitron.commands.product_prices import (
24
+ GetInsertedProductPrices,
25
+ GetInsertedProductPricesFromExtraPriceList,
26
+ GetProductStocksFromProductPrices,
27
+ GetUpdatedProductPrices,
28
+ GetUpdatedProductPricesFromExtraPriceList
29
+ )
30
+ from channel_app.omnitron.commands.product_stocks import (
31
+ GetInsertedProductStocks,
32
+ GetProductPricesFromProductStocks,
33
+ GetUpdatedProductStocks,
34
+ GetUpdatedProductStocksFromExtraStockList,
35
+ GetInsertedProductStocksFromExtraStockList
36
+ )
17
37
  from channel_app.omnitron.commands.products import (
18
38
  GetDeletedProducts,
19
39
  GetInsertedProducts,
20
40
  GetUpdatedProducts,
21
- Product,
22
- GetMappedProducts,
23
- GetProductPrices,
24
- GetProductStocks,
41
+ Product,
42
+ GetMappedProducts,
43
+ GetProductPrices,
44
+ GetProductStocks,
25
45
  GetProductCategoryNodes,
26
46
  GetProductCategoryNodesWithIntegrationAction,
27
47
  )
28
48
  from channel_app.omnitron.constants import (
29
- BatchRequestStatus,
30
- ContentType,
49
+ BatchRequestStatus,
50
+ ContentType,
31
51
  FailedReasonType
32
52
  )
33
53
 
@@ -38,23 +58,24 @@ class TestGetInsertedProducts(BaseTestCaseMixin):
38
58
 
39
59
  run: python -m unittest channel_app.omnitron.commands.tests.test_products.TestGetInsertedProducts
40
60
  """
61
+
41
62
  def setUp(self) -> None:
42
63
  self.get_inserted_products = GetInsertedProducts(
43
64
  integration=self.mock_integration
44
65
  )
45
66
  self.sample_products = [
46
- Product(name='test', failed_reason_type=None),
67
+ Product(name='test', failed_reason_type=None),
47
68
  Product(name='test2', failed_reason_type='error')
48
69
  ]
49
70
  self.limit = 1
50
-
71
+
51
72
  @patch.object(GetInsertedProducts, 'get_products')
52
73
  def test_get_data(self, mock_get_products):
53
74
  mock_get_products.return_value = [self.sample_products[0]]
54
75
  self.get_inserted_products.BATCH_SIZE = self.limit
55
-
76
+
56
77
  products = self.get_inserted_products.get_data()
57
-
78
+
58
79
  self.assertEqual(len(products), 1)
59
80
  self.assertEqual(products[0].name, 'test')
60
81
  mock_get_products.assert_called_once_with(limit=self.limit)
@@ -63,27 +84,27 @@ class TestGetInsertedProducts(BaseTestCaseMixin):
63
84
  def test_get_data_with_limit_in_objects_dict(self, mock_get_products):
64
85
  mock_get_products.return_value = [self.sample_products[0]]
65
86
  self.get_inserted_products.objects = {'limit': self.limit}
66
-
87
+
67
88
  products = self.get_inserted_products.get_data()
68
-
89
+
69
90
  self.assertEqual(len(products), 1)
70
91
  self.assertEqual(products[0].name, 'test')
71
92
  mock_get_products.assert_called_once_with(limit=self.limit)
72
-
93
+
73
94
  def test_update_state_property(self):
74
95
  self.assertEqual(
75
96
  self.get_inserted_products.update_state,
76
97
  BatchRequestStatus.commit
77
98
  )
78
-
99
+
79
100
  def test_validated_data(self):
80
101
  validated_products = self.get_inserted_products.validated_data(
81
102
  self.sample_products
82
103
  )
83
-
104
+
84
105
  self.assertIn(self.sample_products[0], validated_products)
85
106
  self.assertNotIn(self.sample_products[1], validated_products)
86
-
107
+
87
108
  @patch('channel_app.core.clients.OmnitronApiClient')
88
109
  @patch.object(BaseClient, 'get_instance')
89
110
  @patch.object(GetInsertedProducts, 'update_batch_request')
@@ -98,21 +119,22 @@ class TestGetInsertedProducts(BaseTestCaseMixin):
98
119
  mock_omnitron_api_client,
99
120
  ):
100
121
  mock_list.return_value = self.sample_products
101
-
122
+
102
123
  products = self.get_inserted_products.get_products(
103
124
  limit=self.limit + 1
104
125
  )
105
-
106
- self.assertEqual(len(products), 2)
126
+
127
+ self.assertEqual(len(products), 2)
107
128
  self.assertEqual(products[0].name, 'test')
108
129
  self.assertEqual(products[1].name, 'test2')
109
-
130
+
110
131
 
111
132
  class TestGetUpdatedProducts(BaseTestCaseMixin):
112
133
  """
113
134
  Test case for GetUpdatedProducts
114
135
  run: python -m unittest channel_app.omnitron.commands.tests.test_products.TestGetUpdatedProducts
115
136
  """
137
+
116
138
  def setUp(self):
117
139
  self.get_inserted_products = GetInsertedProducts(
118
140
  integration=self.mock_integration
@@ -122,28 +144,28 @@ class TestGetUpdatedProducts(BaseTestCaseMixin):
122
144
  )
123
145
  self.sample_products = [
124
146
  Product(
125
- pk=1,
126
- name='test',
127
- failed_reason_type=None,
147
+ pk=1,
148
+ name='test',
149
+ failed_reason_type=None,
128
150
  modified_date='2021-01-01T00:00:00Z',
129
151
  integration_action=MagicMock()
130
- ),
152
+ ),
131
153
  Product(
132
- pk=2,
133
- name='test2',
134
- failed_reason_type='error',
154
+ pk=2,
155
+ name='test2',
156
+ failed_reason_type='error',
135
157
  modified_date='2021-01-01T00:00:00Z',
136
158
  integration_action=MagicMock()
137
159
  )
138
160
  ]
139
-
161
+
140
162
  @patch.object(GetInsertedProducts, 'get_products')
141
163
  @patch.object(GetUpdatedProducts, 'get_integration_actions')
142
164
  def test_get_data(self, mock_get_integration_actions, mock_get_products):
143
165
  mock_get_integration_actions.return_value = self.sample_products
144
166
  mock_get_products.return_value = [self.sample_products[0]]
145
167
  products = self.get_updated_products.get_data()
146
-
168
+
147
169
  self.assertEqual(len(products), 1)
148
170
  self.assertEqual(products[0].name, 'test')
149
171
 
@@ -185,27 +207,27 @@ class TestGetUpdatedProducts(BaseTestCaseMixin):
185
207
 
186
208
  self.assertEqual(len(products), 2)
187
209
 
188
-
189
210
  def test_get_integration_actions_without_product(self):
190
211
  products = self.get_updated_products.get_integration_actions([])
191
212
  self.assertEqual(products, [])
192
213
 
193
214
 
194
215
  class TestGetInsertedOrUpdatedProducts(
195
- TestGetInsertedProducts,
216
+ TestGetInsertedProducts,
196
217
  BaseTestCaseMixin
197
218
  ):
198
219
  """
199
220
  Test case for GetInsertedOrUpdatedProducts
200
221
  run: python -m unittest channel_app.omnitron.commands.tests.test_products.TestGetInsertedOrUpdatedProducts
201
222
  """
223
+
202
224
  def setUp(self) -> None:
203
225
  self.get_inserted_products = GetInsertedProducts(
204
226
  integration=self.mock_integration
205
227
  )
206
228
  self.get_inserted_products.path = "inserts_or_updates"
207
229
  return super().setUp()
208
-
230
+
209
231
 
210
232
  class TestGetDeletedProducts(BaseTestCaseMixin):
211
233
  """
@@ -236,13 +258,13 @@ class TestGetDeletedProducts(BaseTestCaseMixin):
236
258
  "created_date": "2023-11-08T09:11:56.919929Z"
237
259
  }
238
260
  ]
239
-
261
+
240
262
  @patch.object(GetDeletedProducts, 'get_deleted_products_ia')
241
263
  def test_get_data(self, mock_get_deleted_products_ia):
242
264
  mock_get_deleted_products_ia.return_value = self.products
243
265
  products = self.get_deleted_products.get_data()
244
266
  self.assertEqual(len(products), 1)
245
-
267
+
246
268
  product = products[0]
247
269
  self.assertEqual(product.get('pk'), 23)
248
270
 
@@ -252,7 +274,7 @@ class TestGetDeletedProducts(BaseTestCaseMixin):
252
274
  def test_get_deleted_products_ia(
253
275
  self,
254
276
  mock_list,
255
- mock_get_instance,
277
+ mock_get_instance,
256
278
  mock_omnitron_api_client
257
279
  ):
258
280
  example_response = MagicMock()
@@ -260,7 +282,7 @@ class TestGetDeletedProducts(BaseTestCaseMixin):
260
282
  mock_list.return_value = example_response
261
283
  products_ia = self.get_deleted_products.get_deleted_products_ia()
262
284
  self.assertEqual(len(products_ia), 1)
263
-
285
+
264
286
  product = products_ia[0].get_parameters()
265
287
  self.assertEqual(product.get('pk'), 23)
266
288
 
@@ -355,9 +377,9 @@ class TestGetMappedProducts(BaseTestCaseMixin):
355
377
  @patch.object(GetMappedProducts, 'check_attribute_value_defined')
356
378
  @patch.object(GetMappedProducts, 'check_required')
357
379
  def test_update_and_check_product(
358
- self,
359
- mock_check_required,
360
- mock_check_attribute_value_defined
380
+ self,
381
+ mock_check_required,
382
+ mock_check_attribute_value_defined
361
383
  ):
362
384
  product = Product()
363
385
  product.mapped_attributes = MagicMock()
@@ -490,9 +512,9 @@ class TestGetProductPrices(BaseTestCaseMixin):
490
512
  @patch.object(GetProductPrices, 'get_prices')
491
513
  @patch.object(BaseClient, 'get_instance')
492
514
  def test_product_price_retrieval_with_failed_get_product_price(
493
- self,
494
- mock_get_instance,
495
- mock_get_prices
515
+ self,
516
+ mock_get_instance,
517
+ mock_get_prices
496
518
  ):
497
519
  products = [Product(pk=i, product_price=0) for i in range(1, 6)]
498
520
 
@@ -752,9 +774,9 @@ class TestGetProductCategoryNodes(BaseTestCaseMixin):
752
774
  ]
753
775
 
754
776
  with patch.object(
755
- ChannelCategoryTreeEndpoint,
756
- '__new__',
757
- return_value=category_tree_endpoint,
777
+ ChannelCategoryTreeEndpoint,
778
+ '__new__',
779
+ return_value=category_tree_endpoint,
758
780
  ), patch.object(
759
781
  ChannelProductCategoryEndpoint,
760
782
  '__new__',
@@ -787,7 +809,7 @@ class TestGetProductCategoryNodesWithIntegrationAction(TestGetProductCategoryNod
787
809
  )
788
810
  self.sample_products = [
789
811
  Product(
790
- pk=1,
812
+ pk=1,
791
813
  category_nodes=[
792
814
  {
793
815
  'pk': 1,
@@ -796,7 +818,7 @@ class TestGetProductCategoryNodesWithIntegrationAction(TestGetProductCategoryNod
796
818
  ]
797
819
  ),
798
820
  Product(
799
- pk=2,
821
+ pk=2,
800
822
  category_nodes=[
801
823
  {
802
824
  'pk': 2,
@@ -863,10 +885,10 @@ class TestGetProductCategoryNodesWithIntegrationAction(TestGetProductCategoryNod
863
885
  mock_endpoint.return_value = integration_action_endpoint
864
886
 
865
887
  with patch.object(
866
- ChannelIntegrationActionEndpoint,
867
- '__new__',
868
- return_value=integration_action_endpoint,
869
- channel_id=1
888
+ ChannelIntegrationActionEndpoint,
889
+ '__new__',
890
+ return_value=integration_action_endpoint,
891
+ channel_id=1
870
892
  ):
871
893
  result = self.get_product_category_nodes.get_category_node_integration_action(
872
894
  self.sample_products
@@ -921,7 +943,6 @@ class TestGetUpdatedProductStocks(BaseTestCaseMixin):
921
943
  Test case for GetUpdatedProductStocks
922
944
  run: python -m unittest channel_app.omnitron.commands.tests.test_products.TestGetUpdatedProductStocks
923
945
  """
924
-
925
946
  def setUp(self) -> None:
926
947
  self.get_updated_product_stocks = GetUpdatedProductStocks(
927
948
  integration=self.mock_integration
@@ -1205,3 +1226,1224 @@ class TestGetInsertedProductStocks(BaseTestCaseMixin):
1205
1226
  self.assertEqual(len(stocks), 2)
1206
1227
  self.assertEqual(stocks[0].pk, self.sample_stocks[0].pk)
1207
1228
  self.assertEqual(stocks[1].pk, self.sample_stocks[1].pk)
1229
+
1230
+
1231
+ class TestGetUpdatedProductStocksFromExtraStockList(BaseTestCaseMixin):
1232
+ """
1233
+ Test case for GetupdatedProductStocksFromExtraStockList
1234
+ run: python -m unittest channel_app.omnitron.commands.tests.test_products.TestGetUpdatedProductStocksFromExtraStockList
1235
+ """
1236
+
1237
+ def setUp(self) -> None:
1238
+ self.get_updated_product_stocks_from_extra_stock_list = GetUpdatedProductStocksFromExtraStockList(
1239
+ integration=self.mock_integration
1240
+ )
1241
+ self.sample_stocks = [
1242
+ ProductStock(
1243
+ pk=3,
1244
+ product=1,
1245
+ stock=0,
1246
+ stock_list=4,
1247
+ unit_type='qty',
1248
+ extra_field={},
1249
+ sold_quantity_unreported=0,
1250
+ modified_date='2023-12-19T08:38:48.476005Z',
1251
+ created_date='2023-12-19T08:38:48.475992Z'
1252
+ ),
1253
+ ProductStock(
1254
+ pk=4,
1255
+ product=2,
1256
+ stock=0,
1257
+ stock_list=4,
1258
+ unit_type='qty',
1259
+ extra_field={},
1260
+ sold_quantity_unreported=0,
1261
+ modified_date='2023-12-19T08:38:48.476005Z',
1262
+ created_date='2023-12-19T08:38:48.475992Z'
1263
+ )
1264
+ ]
1265
+ self.objects = self.sample_stocks
1266
+ self.stock_list_id = 4
1267
+
1268
+ @patch.object(
1269
+ BaseClient,
1270
+ 'get_instance'
1271
+ )
1272
+ @patch.object(
1273
+ GetUpdatedProductStocksFromExtraStockList,
1274
+ 'get_product_stocks'
1275
+ )
1276
+ @patch.object(
1277
+ GetUpdatedProductStocksFromExtraStockList,
1278
+ 'get_integration_actions'
1279
+ )
1280
+ def test_get_data(
1281
+ self,
1282
+ mock_get_integration_actions,
1283
+ mock_get_product_stocks,
1284
+ mock_get_instance
1285
+ ):
1286
+ mock_get_integration_actions.return_value = self.sample_stocks
1287
+ mock_get_product_stocks.return_value = self.sample_stocks
1288
+ stocks = self.get_updated_product_stocks_from_extra_stock_list.get_data()
1289
+
1290
+ self.assertEqual(len(stocks), 2)
1291
+ self.assertEqual(stocks[0].pk, self.sample_stocks[0].pk)
1292
+ self.assertEqual(stocks[1].pk, self.sample_stocks[1].pk)
1293
+
1294
+ @patch.object(
1295
+ BaseClient,
1296
+ 'get_instance'
1297
+ )
1298
+ @patch.object(
1299
+ ChannelIntegrationActionEndpoint,
1300
+ 'list'
1301
+ )
1302
+ @patch.object(
1303
+ GetUpdatedProductStocksFromExtraStockList,
1304
+ 'create_batch_objects'
1305
+ )
1306
+ @patch.object(
1307
+ GetUpdatedProductStocksFromExtraStockList,
1308
+ 'update_batch_request'
1309
+ )
1310
+ def test_get_product_stocks(
1311
+ self,
1312
+ mock_update_batch_request,
1313
+ mock_create_batch_objects,
1314
+ mock_list,
1315
+ mock_get_instance
1316
+ ):
1317
+ self.get_updated_product_stocks_from_extra_stock_list.objects = self.objects
1318
+ self.get_updated_product_stocks_from_extra_stock_list.stock_list_id = self.stock_list_id
1319
+
1320
+ mock_endpoint = MagicMock()
1321
+ mock_endpoint.list.return_value = [
1322
+ {
1323
+ 'pk': 3,
1324
+ 'product': 1,
1325
+ 'stock': 0,
1326
+ 'stock_list': 4,
1327
+ 'unit_type': 'qty',
1328
+ 'extra_field': {},
1329
+ 'sold_quantity_unreported': 0,
1330
+ 'modified_date': '2023-12-19T08:38:48.476005Z',
1331
+ 'created_date': '2023-12-19T08:38:48.475992Z'
1332
+ },
1333
+ {
1334
+ 'pk': 4,
1335
+ 'product': 2,
1336
+ 'stock': 0,
1337
+ 'stock_list': 4,
1338
+ 'unit_type': 'qty',
1339
+ 'extra_field': {},
1340
+ 'sold_quantity_unreported': 0,
1341
+ 'modified_date': '2023-12-19T08:38:48.476005Z',
1342
+ 'created_date': '2023-12-19T08:38:48.475992Z'
1343
+ }
1344
+ ]
1345
+
1346
+ with patch.object(
1347
+ ChannelExtraProductStockEndpoint,
1348
+ '__new__',
1349
+ return_value=mock_endpoint
1350
+ ):
1351
+ stocks = self.get_updated_product_stocks_from_extra_stock_list.get_product_stocks()
1352
+
1353
+ self.assertEqual(len(stocks), 2)
1354
+ self.assertEqual(stocks[0].get('pk'), 3)
1355
+ self.assertEqual(stocks[1].get('pk'), 4)
1356
+
1357
+ def test_get_integration_actions_without_stocks(self):
1358
+ self.sample_stocks = []
1359
+ stocks = self.get_updated_product_stocks_from_extra_stock_list.get_integration_actions(
1360
+ self.sample_stocks
1361
+ )
1362
+ self.assertEqual(stocks, [])
1363
+
1364
+ @patch.object(BaseClient, 'get_instance')
1365
+ @patch.object(ChannelIntegrationActionEndpoint, 'list')
1366
+ def test_get_integration_actions(
1367
+ self,
1368
+ mock_get_instance,
1369
+ mock_list
1370
+ ):
1371
+ mock_endpoint = MagicMock()
1372
+ mock_endpoint.list.return_value = [
1373
+ MagicMock(
1374
+ pk=1,
1375
+ channel=2,
1376
+ content_type=ContentType.product_stock.value,
1377
+ object_id=self.sample_stocks[0].pk,
1378
+ remote_id=None,
1379
+ version_date="2023-12-28T10:28:17.186730Z",
1380
+ state={},
1381
+ modified_date="2023-12-28T10:28:17.187032Z",
1382
+ local_batch_id=None,
1383
+ status=None,
1384
+ created_date="2023-12-28T10:28:17.187014Z"
1385
+ ),
1386
+ MagicMock(
1387
+ pk=2,
1388
+ channel=2,
1389
+ content_type=ContentType.product_stock.value,
1390
+ object_id=self.sample_stocks[1].pk,
1391
+ remote_id=None,
1392
+ version_date="2023-12-28T10:28:17.186730Z",
1393
+ state={},
1394
+ modified_date="2023-12-28T10:28:17.187032Z",
1395
+ local_batch_id=None,
1396
+ status=None,
1397
+ created_date="2023-12-28T10:28:17.187014Z"
1398
+ )
1399
+ ]
1400
+ mock_endpoint.iterator = [
1401
+ [
1402
+ MagicMock(
1403
+ pk=1,
1404
+ channel=2,
1405
+ content_type=ContentType.product_stock.value,
1406
+ object_id=self.sample_stocks[0].pk,
1407
+ remote_id=None,
1408
+ version_date="2023-12-28T10:28:17.186730Z",
1409
+ state={},
1410
+ modified_date="2023-12-28T10:28:17.187032Z",
1411
+ local_batch_id=None,
1412
+ status=None,
1413
+ created_date="2023-12-28T10:28:17.187014Z"
1414
+ )
1415
+ ],
1416
+ [
1417
+ MagicMock(
1418
+ pk=2,
1419
+ channel=2,
1420
+ content_type=ContentType.product_stock.value,
1421
+ object_id=self.sample_stocks[1].pk,
1422
+ remote_id=None,
1423
+ version_date="2023-12-28T10:28:17.186730Z",
1424
+ state={},
1425
+ modified_date="2023-12-28T10:28:17.187032Z",
1426
+ local_batch_id=None,
1427
+ status=None,
1428
+ created_date="2023-12-28T10:28:17.187014Z"
1429
+ )
1430
+ ]
1431
+ ]
1432
+
1433
+ with patch.object(
1434
+ ChannelIntegrationActionEndpoint,
1435
+ '__new__',
1436
+ return_value=mock_endpoint
1437
+ ):
1438
+ stocks = self.get_updated_product_stocks_from_extra_stock_list.get_integration_actions(
1439
+ self.sample_stocks
1440
+ )
1441
+
1442
+ self.assertEqual(len(stocks), 2)
1443
+ self.assertEqual(stocks[0].pk, self.sample_stocks[0].pk)
1444
+ self.assertEqual(stocks[1].pk, self.sample_stocks[1].pk)
1445
+
1446
+
1447
+ class TestGetProductPricesFromProductStocks(BaseTestCaseMixin):
1448
+ """
1449
+ Test case for GetProductPricesFromProductStocks
1450
+ run: python -m unittest channel_app.omnitron.commands.tests.test_products.TestGetProductPricesFromProductStocks
1451
+ """
1452
+
1453
+ def setUp(self) -> None:
1454
+ self.get_product_prices_from_product_stocks = GetProductPricesFromProductStocks(
1455
+ integration=self.mock_integration
1456
+ )
1457
+ self.sample_stocks = [
1458
+ ProductStock(
1459
+ pk=3,
1460
+ product=1,
1461
+ stock=0,
1462
+ stock_list=4,
1463
+ unit_type='qty',
1464
+ extra_field={},
1465
+ sold_quantity_unreported=0,
1466
+ modified_date='2023-12-19T08:38:48.476005Z',
1467
+ created_date='2023-12-19T08:38:48.475992Z',
1468
+ productprice=10
1469
+ ),
1470
+ ProductStock(
1471
+ pk=4,
1472
+ product=2,
1473
+ stock=0,
1474
+ stock_list=4,
1475
+ unit_type='qty',
1476
+ extra_field={},
1477
+ sold_quantity_unreported=0,
1478
+ modified_date='2023-12-19T08:38:48.476005Z',
1479
+ created_date='2023-12-19T08:38:48.475992Z',
1480
+ productprice=10
1481
+ )
1482
+ ]
1483
+
1484
+ @patch.object(BaseClient, 'get_instance')
1485
+ @patch.object(GetProductPricesFromProductStocks, 'get_product_price')
1486
+ def test_get_data(
1487
+ self,
1488
+ mock_get_product_price,
1489
+ mock_get_instance
1490
+ ):
1491
+ self.get_product_prices_from_product_stocks.objects = self.sample_stocks
1492
+ stocks = self.get_product_prices_from_product_stocks.get_data()
1493
+ self.assertEqual(len(stocks), 2)
1494
+ self.assertEqual(stocks[0].pk, self.sample_stocks[0].pk)
1495
+ self.assertEqual(stocks[1].pk, self.sample_stocks[1].pk)
1496
+
1497
+ @patch.object(BaseClient, 'get_instance')
1498
+ @patch.object(GetProductPricesFromProductStocks, 'create_batch_objects')
1499
+ @patch.object(GetProductPricesFromProductStocks, 'create_integration_actions')
1500
+ @patch.object(GetProductPricesFromProductStocks, 'update_batch_request')
1501
+ def test_normalize_response(
1502
+ self,
1503
+ mock_update_batch_request,
1504
+ mock_create_integration_actions,
1505
+ mock_create_batch_objects,
1506
+ mock_get_instance
1507
+ ):
1508
+ data = self.get_product_prices_from_product_stocks.normalize_response(
1509
+ self.sample_stocks,
1510
+ None
1511
+ )
1512
+ self.assertEqual(len(data), 2)
1513
+ self.assertEqual(data[0].pk, self.sample_stocks[0].pk)
1514
+ self.assertEqual(data[1].pk, self.sample_stocks[1].pk)
1515
+
1516
+ @patch.object(GetProductPricesFromProductStocks, 'create_batch_objects')
1517
+ def test_create_integration_actions(
1518
+ self,
1519
+ mock_create_batch_objects
1520
+ ):
1521
+ self.get_product_prices_from_product_stocks.create_integration_actions(
1522
+ self.sample_stocks,
1523
+ []
1524
+ )
1525
+ self.assertEqual(mock_create_batch_objects.call_count, 1)
1526
+
1527
+ def test_get_product_price_with_empty_stock(self):
1528
+ stocks = self.get_product_prices_from_product_stocks.get_product_price(
1529
+ []
1530
+ )
1531
+ self.assertEqual(stocks, [])
1532
+
1533
+ @patch.object(BaseClient, 'get_instance')
1534
+ @patch.object(ChannelExtraProductPriceEndpoint, 'list')
1535
+ @patch.object(GetProductPricesFromProductStocks, 'get_prices')
1536
+ def test_get_product_price(
1537
+ self,
1538
+ mock_get_prices,
1539
+ mock_list,
1540
+ mock_get_instance
1541
+ ):
1542
+ example_response = MagicMock()
1543
+ example_response.list.return_value = self.sample_stocks
1544
+ example_response.iterator = iter(self.sample_stocks)
1545
+
1546
+ with patch.object(
1547
+ ChannelExtraProductPriceEndpoint,
1548
+ '__new__',
1549
+ return_value=example_response
1550
+ ):
1551
+ stocks = self.get_product_prices_from_product_stocks.get_product_price(
1552
+ self.sample_stocks
1553
+ )
1554
+
1555
+ self.assertEqual(len(stocks), 2)
1556
+ self.assertEqual(stocks[0].pk, self.sample_stocks[0].pk)
1557
+ self.assertEqual(stocks[1].pk, self.sample_stocks[1].pk)
1558
+ self.assertEqual(
1559
+ stocks[0].failed_reason_type,
1560
+ FailedReasonType.channel_app.value
1561
+ )
1562
+ self.assertEqual(
1563
+ stocks[1].failed_reason_type,
1564
+ FailedReasonType.channel_app.value
1565
+ )
1566
+
1567
+ @patch.object(BaseClient, 'get_instance')
1568
+ @patch.object(ChannelExtraProductPriceEndpoint, 'list')
1569
+ def test_get_prices(
1570
+ self,
1571
+ mock_list,
1572
+ mock_get_instance
1573
+ ):
1574
+ product_prices = [
1575
+ MagicMock(
1576
+ pk=1,
1577
+ product=5,
1578
+ price='645670668.11',
1579
+ price_list=1,
1580
+ currency_type='try',
1581
+ tax_rate='32.61',
1582
+ retail_price=None,
1583
+ extra_field={},
1584
+ discount_percentage='63.57',
1585
+ modified_date='2024-01-02T07:53:06.392780Z',
1586
+ created_date='2024-01-02T07:53:06.392771Z',
1587
+ price_type='default'
1588
+ )
1589
+ ]
1590
+
1591
+ example_response = MagicMock()
1592
+ example_response.list.return_value = product_prices
1593
+ example_response.iterator = iter(product_prices)
1594
+
1595
+ with patch.object(
1596
+ ChannelExtraProductPriceEndpoint,
1597
+ '__new__',
1598
+ return_value=example_response
1599
+ ):
1600
+ stocks = self.get_product_prices_from_product_stocks.get_prices(
1601
+ "1,2,3",
1602
+ ChannelExtraProductPriceEndpoint()
1603
+ )
1604
+
1605
+ self.assertEqual(len(stocks), 1)
1606
+ self.assertEqual(stocks[0].pk, product_prices[0].pk)
1607
+ self.assertEqual(stocks[0].product, product_prices[0].product)
1608
+ self.assertEqual(stocks[0].price, product_prices[0].price)
1609
+
1610
+
1611
+ class TestGetProductStocksFromProductPrices(BaseTestCaseMixin):
1612
+ """
1613
+ Test case for GetProductStocksFromProductPrices
1614
+ run: python -m unittest channel_app.omnitron.commands.tests.test_products.TestGetProductStocksFromProductPrices
1615
+ """
1616
+
1617
+ def setUp(self) -> None:
1618
+ self.stocks = [
1619
+ MagicMock(
1620
+ pk=3,
1621
+ product=1,
1622
+ stock=0,
1623
+ stock_list=4,
1624
+ unit_type='qty',
1625
+ extra_field={},
1626
+ sold_quantity_unreported=0,
1627
+ modified_date='2023-12-19T08:38:48.476005Z',
1628
+ created_date='2023-12-19T08:38:48.475992Z'
1629
+ ),
1630
+ ]
1631
+ self.prices = [
1632
+ MagicMock(
1633
+ pk=1,
1634
+ product=5,
1635
+ price='645670668.11',
1636
+ price_list=1,
1637
+ currency_type='try',
1638
+ tax_rate='32.61',
1639
+ retail_price=None,
1640
+ extra_field={},
1641
+ discount_percentage='63.57',
1642
+ modified_date='2024-01-02T07:53:06.392780Z',
1643
+ created_date='2024-01-02T07:53:06.392771Z',
1644
+ price_type='default',
1645
+ failed_reason_type=FailedReasonType.channel_app.value
1646
+ )
1647
+ ]
1648
+ self.get_product_stocks_from_product_prices = GetProductStocksFromProductPrices(
1649
+ integration=self.mock_integration
1650
+ )
1651
+
1652
+ @patch.object(BaseClient, 'get_instance')
1653
+ @patch.object(GetProductStocksFromProductPrices, 'get_product_stock')
1654
+ def test_get_data(self, mock_get_instance, mock_get_product_stock):
1655
+ self.get_product_stocks_from_product_prices.objects = self.prices
1656
+ self.assertEqual(
1657
+ self.get_product_stocks_from_product_prices.get_data(),
1658
+ self.prices
1659
+ )
1660
+
1661
+ @patch.object(
1662
+ BaseClient,
1663
+ 'get_instance'
1664
+ )
1665
+ @patch.object(
1666
+ GetProductStocksFromProductPrices,
1667
+ 'create_batch_objects'
1668
+ )
1669
+ @patch.object(
1670
+ GetProductStocksFromProductPrices,
1671
+ 'create_integration_actions'
1672
+ )
1673
+ @patch.object(
1674
+ GetProductStocksFromProductPrices,
1675
+ 'update_batch_request'
1676
+ )
1677
+ def test_normalize_response(
1678
+ self,
1679
+ mock_update_batch_request,
1680
+ mock_create_integration_actions,
1681
+ mock_create_batch_objects,
1682
+ mock_get_instance
1683
+ ):
1684
+ data = self.get_product_stocks_from_product_prices.normalize_response(
1685
+ self.stocks,
1686
+ None
1687
+ )
1688
+ self.assertEqual(len(data), 1)
1689
+ self.assertEqual(data[0].pk, self.stocks[0].pk)
1690
+
1691
+ @patch.object(GetProductStocksFromProductPrices, 'create_batch_objects')
1692
+ def test_create_integration_actions(self, mock_create_batch_objects):
1693
+ self.get_product_stocks_from_product_prices.create_integration_actions(
1694
+ self.stocks,
1695
+ []
1696
+ )
1697
+ self.assertEqual(mock_create_batch_objects.call_count, 1)
1698
+
1699
+ def test_get_product_stock_with_empty_stock(self):
1700
+ self.stocks = []
1701
+ stocks = self.get_product_stocks_from_product_prices.get_product_stock(
1702
+ self.stocks
1703
+ )
1704
+ self.assertEqual(stocks, [])
1705
+
1706
+ @patch.object(BaseClient, 'get_instance')
1707
+ @patch.object(ChannelExtraProductPriceEndpoint, 'list')
1708
+ @patch.object(GetProductStocksFromProductPrices, 'get_stocks')
1709
+ def test_get_product_stock(self, mock_get_stocks, mock_list, mock_get_instance):
1710
+ mock_get_stocks.return_value = self.stocks
1711
+ prices = self.get_product_stocks_from_product_prices.get_product_stock(
1712
+ self.prices
1713
+ )
1714
+ self.assertEqual(len(prices), 1)
1715
+ self.assertEqual(prices[0].pk, self.prices[0].pk)
1716
+ self.assertEqual(prices[0].product, self.prices[0].product)
1717
+ self.assertEqual(prices[0].price, self.prices[0].price)
1718
+ self.assertEqual(prices[0].failed_reason_type, FailedReasonType.channel_app.value)
1719
+
1720
+ @patch.object(BaseClient, 'get_instance')
1721
+ @patch.object(ChannelExtraProductPriceEndpoint, 'list')
1722
+ def test_get_stocks(self, mock_list, mock_get_instance):
1723
+ example_response = MagicMock()
1724
+ example_response.list.return_value = self.stocks
1725
+ example_response.iterator = iter(self.stocks)
1726
+
1727
+ with patch.object(
1728
+ ChannelExtraProductStockEndpoint,
1729
+ '__new__',
1730
+ return_value=example_response
1731
+ ):
1732
+ stocks = self.get_product_stocks_from_product_prices.get_stocks(
1733
+ "1,2,3",
1734
+ ChannelExtraProductStockEndpoint()
1735
+ )
1736
+
1737
+ self.assertEqual(len(stocks), 1)
1738
+ self.assertEqual(stocks[0].pk, self.stocks[0].pk)
1739
+ self.assertEqual(stocks[0].product, self.stocks[0].product)
1740
+ self.assertEqual(stocks[0].stock, self.stocks[0].stock)
1741
+
1742
+
1743
+ class TestGetInsertedProductStocksFromExtraStockList(BaseTestCaseMixin):
1744
+ """
1745
+ Test case for GetInsertedProductStocksFromExtraStockList
1746
+ run: python -m unittest channel_app.omnitron.commands.tests.test_products.TestGetInsertedProductStocksFromExtraStockList
1747
+ """
1748
+
1749
+ def setUp(self) -> None:
1750
+ self.get_inserted_product_stocks_from_extra_stock_list = GetInsertedProductStocksFromExtraStockList(
1751
+ integration=self.mock_integration
1752
+ )
1753
+ self.sample_stocks = [
1754
+ ProductStock(
1755
+ pk=3,
1756
+ product=1,
1757
+ stock=0,
1758
+ stock_list=4,
1759
+ unit_type='qty',
1760
+ extra_field={},
1761
+ sold_quantity_unreported=0,
1762
+ remote_id=3,
1763
+ modified_date='2023-12-19T08:38:48.476005Z',
1764
+ created_date='2023-12-19T08:38:48.475992Z'
1765
+ ),
1766
+ ProductStock(
1767
+ pk=4,
1768
+ product=2,
1769
+ stock=0,
1770
+ stock_list=4,
1771
+ unit_type='qty',
1772
+ extra_field={},
1773
+ sold_quantity_unreported=0,
1774
+ remote_id=4,
1775
+ modified_date='2023-12-19T08:38:48.476005Z',
1776
+ created_date='2023-12-19T08:38:48.475992Z'
1777
+ )
1778
+ ]
1779
+ self.integration_actions = [
1780
+ MagicMock(
1781
+ pk=1,
1782
+ channel=2,
1783
+ content_type=ContentType.product_stock.value,
1784
+ object_id=self.sample_stocks[0].pk,
1785
+ remote_id=None,
1786
+ version_date="2023-12-28T10:28:17.186730Z",
1787
+ state={},
1788
+ modified_date="2023-12-28T10:28:17.187032Z",
1789
+ local_batch_id=None,
1790
+ status=None,
1791
+ created_date="2023-12-28T10:28:17.187014Z"
1792
+ ),
1793
+ MagicMock(
1794
+ pk=2,
1795
+ channel=2,
1796
+ content_type=ContentType.product_stock.value,
1797
+ object_id=self.sample_stocks[1].pk,
1798
+ remote_id=None,
1799
+ version_date="2023-12-28T10:28:17.186730Z",
1800
+ state={},
1801
+ modified_date="2023-12-28T10:28:17.187032Z",
1802
+ local_batch_id=None,
1803
+ status=None,
1804
+ created_date="2023-12-28T10:28:17.187014Z"
1805
+ )
1806
+ ]
1807
+
1808
+ @patch.object(BaseClient, 'get_instance')
1809
+ @patch.object(ChannelIntegrationActionEndpoint, 'list')
1810
+ def test_get_integration_actions(self, mock_list, mock_get_instance):
1811
+ example_response = MagicMock()
1812
+ example_response.list.return_value = self.integration_actions
1813
+ example_response.iterator = iter(self.integration_actions)
1814
+
1815
+ with patch.object(
1816
+ ChannelIntegrationActionEndpoint,
1817
+ '__new__',
1818
+ return_value=example_response
1819
+ ):
1820
+ stocks = self.get_inserted_product_stocks_from_extra_stock_list.get_integration_actions(
1821
+ self.sample_stocks
1822
+ )
1823
+
1824
+ self.assertEqual(len(stocks), 2)
1825
+ self.assertEqual(stocks[0].pk, self.integration_actions[0].object_id)
1826
+ self.assertEqual(stocks[1].pk, self.integration_actions[1].object_id)
1827
+ self.assertEqual(stocks[0].remote_id, self.sample_stocks[0].remote_id)
1828
+ self.assertEqual(stocks[1].remote_id, self.sample_stocks[1].remote_id)
1829
+
1830
+
1831
+ class TestGetUpdatedProductPrices(BaseTestCaseMixin):
1832
+ """
1833
+ Test case for GetUpdatedProductPrices
1834
+ run: python -m unittest channel_app.omnitron.commands.tests.test_products.TestGetUpdatedProductPrices
1835
+ """
1836
+
1837
+ def setUp(self) -> None:
1838
+ self.get_updated_product_prices = GetUpdatedProductPrices(
1839
+ integration=self.mock_integration
1840
+ )
1841
+ self.product_prices = [
1842
+ ProductPrice(
1843
+ pk=1,
1844
+ product=5,
1845
+ price='645670668.11',
1846
+ price_list=1,
1847
+ currency_type='try',
1848
+ tax_rate='32.61',
1849
+ retail_price=None,
1850
+ extra_field={},
1851
+ discount_percentage='63.57',
1852
+ modified_date='2024-01-02T07:53:06.392780Z',
1853
+ created_date='2024-01-02T07:53:06.392771Z',
1854
+ price_type='default'
1855
+ ),
1856
+ ProductPrice(
1857
+ pk=2,
1858
+ product=6,
1859
+ price='493154528.49',
1860
+ price_list=2,
1861
+ currency_type='try',
1862
+ tax_rate='31.13',
1863
+ retail_price=None,
1864
+ extra_field={},
1865
+ discount_percentage='26.55',
1866
+ modified_date='2024-01-09T13:20:23.472505Z',
1867
+ created_date='2024-01-09T13:20:23.472485Z',
1868
+ price_type='default'
1869
+ )
1870
+ ]
1871
+ self.product_prices_json = [
1872
+ {
1873
+ "pk": 1,
1874
+ "product": 5,
1875
+ "price": "645670668.11",
1876
+ "price_list": 1,
1877
+ "currency_type": "try",
1878
+ "tax_rate": "32.61",
1879
+ "retail_price": None,
1880
+ "extra_field": {},
1881
+ "discount_percentage": "63.57",
1882
+ "modified_date": "2024-01-02T07:53:06.392780Z",
1883
+ "created_date": "2024-01-02T07:53:06.392771Z",
1884
+ "price_type": "default"
1885
+ },
1886
+ {
1887
+ "pk": 2,
1888
+ "product": 6,
1889
+ "price": "493154528.49",
1890
+ "price_list": 2,
1891
+ "currency_type": "try",
1892
+ "tax_rate": "31.13",
1893
+ "retail_price": None,
1894
+ "extra_field": {},
1895
+ "discount_percentage": "26.55",
1896
+ "modified_date": "2024-01-09T13:20:23.472505Z",
1897
+ "created_date": "2024-01-09T13:20:23.472485Z",
1898
+ "price_type": "default"
1899
+ }
1900
+ ]
1901
+ self.integration_actions = [
1902
+ MagicMock(
1903
+ pk=1,
1904
+ channel=2,
1905
+ content_type=ContentType.product_price.value,
1906
+ object_id=self.product_prices[0].pk,
1907
+ remote_id='1',
1908
+ version_date="2023-12-28T10:28:17.186730Z",
1909
+ state={},
1910
+ modified_date="2023-12-28T10:28:17.187032Z",
1911
+ local_batch_id=None,
1912
+ status=None,
1913
+ created_date="2023-12-28T10:28:17.187014Z"
1914
+ ),
1915
+ MagicMock(
1916
+ pk=2,
1917
+ channel=2,
1918
+ content_type=ContentType.product_price.value,
1919
+ object_id=self.product_prices[1].pk,
1920
+ remote_id='2',
1921
+ version_date="2023-12-28T10:28:17.186730Z",
1922
+ state={},
1923
+ modified_date="2023-12-28T10:28:17.187032Z",
1924
+ local_batch_id=None,
1925
+ status=None,
1926
+ created_date="2023-12-28T10:28:17.187014Z"
1927
+ )
1928
+ ]
1929
+
1930
+ @patch.object(
1931
+ GetUpdatedProductPrices,
1932
+ 'get_product_prices'
1933
+ )
1934
+ @patch.object(
1935
+ GetUpdatedProductPrices,
1936
+ 'get_integration_actions'
1937
+ )
1938
+ def test_get_data(
1939
+ self,
1940
+ mock_get_product_prices,
1941
+ mock_get_integration_actions
1942
+ ):
1943
+ mock_get_product_prices.return_value = self.product_prices
1944
+ mock_get_integration_actions.return_value = self.integration_actions
1945
+ data = self.get_updated_product_prices.get_data()
1946
+
1947
+ self.assertEqual(len(data), 2)
1948
+ self.assertEqual(data[0].pk, self.product_prices[0].pk)
1949
+ self.assertEqual(data[1].pk, self.product_prices[1].pk)
1950
+
1951
+ @patch.object(BaseClient, 'get_instance')
1952
+ @patch.object(GetUpdatedProductPrices, 'create_batch_objects')
1953
+ @patch.object(GetUpdatedProductPrices, 'update_batch_request')
1954
+ def test_get_product_prices(
1955
+ self,
1956
+ mock_get_instance,
1957
+ mock_create_batch_objects,
1958
+ mock_update_batch_request
1959
+ ):
1960
+ example_response = MagicMock()
1961
+ example_response.list.return_value = self.product_prices_json
1962
+
1963
+ with patch.object(
1964
+ ChannelProductPriceEndpoint,
1965
+ '__new__',
1966
+ return_value=example_response
1967
+ ):
1968
+ data = self.get_updated_product_prices.get_product_prices()
1969
+
1970
+ self.assertEqual(len(data), 2)
1971
+ self.assertEqual(data[0].get('pk'), self.product_prices[0].pk)
1972
+ self.assertEqual(data[1].get('pk'), self.product_prices[1].pk)
1973
+
1974
+ @patch.object(BaseClient, 'get_instance')
1975
+ def test_get_integration_actions(self, mock_get_instance):
1976
+ example_response = MagicMock()
1977
+ example_response.list.return_value = self.integration_actions
1978
+ example_response.iterator = iter(self.integration_actions)
1979
+
1980
+ with patch.object(
1981
+ ChannelIntegrationActionEndpoint,
1982
+ '__new__',
1983
+ return_value=example_response
1984
+ ):
1985
+ data = self.get_updated_product_prices.get_integration_actions(
1986
+ self.product_prices
1987
+ )
1988
+
1989
+ self.assertEqual(len(data), 2)
1990
+ self.assertEqual(data[0].pk, self.integration_actions[0].object_id)
1991
+ self.assertEqual(data[1].pk, self.integration_actions[1].object_id)
1992
+ self.assertEqual(
1993
+ data[0].remote_id,
1994
+ self.integration_actions[0].remote_id
1995
+ )
1996
+ self.assertEqual(
1997
+ data[1].remote_id,
1998
+ self.integration_actions[1].remote_id
1999
+ )
2000
+
2001
+
2002
+ class TestGetInsertedProductPrices(BaseTestCaseMixin):
2003
+ """
2004
+ Test case for GetInsertedProductPrices
2005
+ run: python -m unittest channel_app.omnitron.commands.tests.test_products.TestGetInsertedProductPrices
2006
+ """
2007
+ def setUp(self) -> None:
2008
+ self.get_inserted_product_prices = GetInsertedProductPrices(
2009
+ integration=self.mock_integration
2010
+ )
2011
+ self.product_prices = [
2012
+ ProductPrice(
2013
+ pk=1,
2014
+ product=5,
2015
+ price='645670668.11',
2016
+ price_list=1,
2017
+ currency_type='try',
2018
+ tax_rate='32.61',
2019
+ remote_id='1',
2020
+ retail_price=None,
2021
+ extra_field={},
2022
+ discount_percentage='63.57',
2023
+ modified_date='2024-01-02T07:53:06.392780Z',
2024
+ created_date='2024-01-02T07:53:06.392771Z',
2025
+ price_type='default'
2026
+ ),
2027
+ ProductPrice(
2028
+ pk=2,
2029
+ product=6,
2030
+ price='493154528.49',
2031
+ price_list=2,
2032
+ currency_type='try',
2033
+ tax_rate='31.13',
2034
+ remote_id='2',
2035
+ retail_price=None,
2036
+ extra_field={},
2037
+ discount_percentage='26.55',
2038
+ modified_date='2024-01-09T13:20:23.472505Z',
2039
+ created_date='2024-01-09T13:20:23.472485Z',
2040
+ price_type='default'
2041
+ )
2042
+ ]
2043
+ self.product_prices_json = [
2044
+ {
2045
+ "pk": 1,
2046
+ "product": 5,
2047
+ "price": "645670668.11",
2048
+ "price_list": 1,
2049
+ "currency_type": "try",
2050
+ "tax_rate": "32.61",
2051
+ "remote_id": None,
2052
+ "retail_price": None,
2053
+ "extra_field": {},
2054
+ "discount_percentage": "63.57",
2055
+ "modified_date": "2024-01-02T07:53:06.392780Z",
2056
+ "created_date": "2024-01-02T07:53:06.392771Z",
2057
+ "price_type": "default"
2058
+ },
2059
+ {
2060
+ "pk": 2,
2061
+ "product": 6,
2062
+ "price": "493154528.49",
2063
+ "price_list": 2,
2064
+ "currency_type": "try",
2065
+ "tax_rate": "31.13",
2066
+ "remote_id": None,
2067
+ "retail_price": None,
2068
+ "extra_field": {},
2069
+ "discount_percentage": "26.55",
2070
+ "modified_date": "2024-01-09T13:20:23.472505Z",
2071
+ "created_date": "2024-01-09T13:20:23.472485Z",
2072
+ "price_type": "default"
2073
+ }
2074
+ ]
2075
+ self.integration_actions = [
2076
+ MagicMock(
2077
+ pk=1,
2078
+ channel=2,
2079
+ content_type=ContentType.product_price.value,
2080
+ object_id=self.product_prices[0].pk,
2081
+ remote_id='1',
2082
+ version_date="2023-12-28T10:28:17.186730Z",
2083
+ state={},
2084
+ modified_date="2023-12-28T10:28:17.187032Z",
2085
+ local_batch_id=None,
2086
+ status=None,
2087
+ created_date="2023-12-28T10:28:17.187014Z"
2088
+ ),
2089
+ MagicMock(
2090
+ pk=2,
2091
+ channel=2,
2092
+ content_type=ContentType.product_price.value,
2093
+ object_id=self.product_prices[1].pk,
2094
+ remote_id='2',
2095
+ version_date="2023-12-28T10:28:17.186730Z",
2096
+ state={},
2097
+ modified_date="2023-12-28T10:28:17.187032Z",
2098
+ local_batch_id=None,
2099
+ status=None,
2100
+ created_date="2023-12-28T10:28:17.187014Z"
2101
+ )
2102
+ ]
2103
+
2104
+ @patch.object(BaseClient, 'get_instance')
2105
+ def test_get_integration_actions(self, mock_get_instance):
2106
+ example_response = MagicMock()
2107
+ example_response.list.return_value = self.integration_actions
2108
+ example_response.iterator = iter(self.integration_actions)
2109
+
2110
+ with patch.object(
2111
+ ChannelIntegrationActionEndpoint,
2112
+ '__new__',
2113
+ return_value=example_response
2114
+ ):
2115
+ data = self.get_inserted_product_prices.get_integration_actions(
2116
+ self.product_prices
2117
+ )
2118
+
2119
+ self.assertEqual(len(data), 2)
2120
+ self.assertEqual(data[0].pk, self.integration_actions[0].object_id)
2121
+ self.assertEqual(data[1].pk, self.integration_actions[1].object_id)
2122
+ self.assertEqual(
2123
+ data[0].remote_id,
2124
+ self.integration_actions[0].remote_id
2125
+ )
2126
+ self.assertEqual(
2127
+ data[1].remote_id,
2128
+ self.integration_actions[1].remote_id
2129
+ )
2130
+
2131
+
2132
+ class TestGetInsertedProductPricesFromExtraPriceList(BaseTestCaseMixin):
2133
+ """
2134
+ Test case for GetInsertedProductPricesFromExtraPriceList
2135
+ run: python -m unittest channel_app.omnitron.commands.tests.test_products.TestGetInsertedProductPricesFromExtraPriceList
2136
+ """
2137
+ def setUp(self) -> None:
2138
+ self.get_inserted_product_prices_from_extra_price_list = GetInsertedProductPricesFromExtraPriceList(
2139
+ integration=self.mock_integration
2140
+ )
2141
+ self.product_prices = [
2142
+ ProductPrice(
2143
+ pk=1,
2144
+ product=5,
2145
+ price='645670668.11',
2146
+ price_list=1,
2147
+ currency_type='try',
2148
+ tax_rate='32.61',
2149
+ remote_id='1',
2150
+ retail_price=None,
2151
+ extra_field={},
2152
+ discount_percentage='63.57',
2153
+ modified_date='2024-01-02T07:53:06.392780Z',
2154
+ created_date='2024-01-02T07:53:06.392771Z',
2155
+ price_type='default'
2156
+ ),
2157
+ ProductPrice(
2158
+ pk=2,
2159
+ product=6,
2160
+ price='493154528.49',
2161
+ price_list=2,
2162
+ currency_type='try',
2163
+ tax_rate='31.13',
2164
+ remote_id='2',
2165
+ retail_price=None,
2166
+ extra_field={},
2167
+ discount_percentage='26.55',
2168
+ modified_date='2024-01-09T13:20:23.472505Z',
2169
+ created_date='2024-01-09T13:20:23.472485Z',
2170
+ price_type='default'
2171
+ )
2172
+ ]
2173
+ self.product_prices_json = [
2174
+ {
2175
+ "pk": 1,
2176
+ "product": 5,
2177
+ "price": "645670668.11",
2178
+ "price_list": 1,
2179
+ "currency_type": "try",
2180
+ "tax_rate": "32.61",
2181
+ "remote_id": None,
2182
+ "retail_price": None,
2183
+ "extra_field": {},
2184
+ "discount_percentage": "63.57",
2185
+ "modified_date": "2024-01-02T07:53:06.392780Z",
2186
+ "created_date": "2024-01-02T07:53:06.392771Z",
2187
+ "price_type": "default"
2188
+ },
2189
+ {
2190
+ "pk": 2,
2191
+ "product": 6,
2192
+ "price": "493154528.49",
2193
+ "price_list": 2,
2194
+ "currency_type": "try",
2195
+ "tax_rate": "31.13",
2196
+ "remote_id": None,
2197
+ "retail_price": None,
2198
+ "extra_field": {},
2199
+ "discount_percentage": "26.55",
2200
+ "modified_date": "2024-01-09T13:20:23.472505Z",
2201
+ "created_date": "2024-01-09T13:20:23.472485Z",
2202
+ "price_type": "default"
2203
+ }
2204
+ ]
2205
+ self.integration_actions = [
2206
+ MagicMock(
2207
+ pk=1,
2208
+ channel=2,
2209
+ content_type=ContentType.product_price.value,
2210
+ object_id=self.product_prices[0].pk,
2211
+ remote_id='1',
2212
+ version_date="2023-12-28T10:28:17.186730Z",
2213
+ state={},
2214
+ modified_date="2023-12-28T10:28:17.187032Z",
2215
+ local_batch_id=None,
2216
+ status=None,
2217
+ created_date="2023-12-28T10:28:17.187014Z"
2218
+ ),
2219
+ MagicMock(
2220
+ pk=2,
2221
+ channel=2,
2222
+ content_type=ContentType.product_price.value,
2223
+ object_id=self.product_prices[1].pk,
2224
+ remote_id='2',
2225
+ version_date="2023-12-28T10:28:17.186730Z",
2226
+ state={},
2227
+ modified_date="2023-12-28T10:28:17.187032Z",
2228
+ local_batch_id=None,
2229
+ status=None,
2230
+ created_date="2023-12-28T10:28:17.187014Z"
2231
+ )
2232
+ ]
2233
+
2234
+ def test_get_integration_actions(self):
2235
+ example_response = MagicMock()
2236
+ example_response.list.return_value = self.integration_actions
2237
+ example_response.iterator = iter(self.integration_actions)
2238
+
2239
+ with patch.object(
2240
+ ChannelIntegrationActionEndpoint,
2241
+ '__new__',
2242
+ return_value=example_response
2243
+ ):
2244
+ data = self.get_inserted_product_prices_from_extra_price_list.get_integration_actions(
2245
+ self.product_prices
2246
+ )
2247
+
2248
+ self.assertEqual(len(data), 2)
2249
+ self.assertEqual(data[0].pk, self.integration_actions[0].object_id)
2250
+ self.assertEqual(data[1].pk, self.integration_actions[1].object_id)
2251
+ self.assertEqual(
2252
+ data[0].remote_id,
2253
+ self.integration_actions[0].remote_id
2254
+ )
2255
+ self.assertEqual(
2256
+ data[1].remote_id,
2257
+ self.integration_actions[1].remote_id
2258
+ )
2259
+
2260
+
2261
+ class TestGetUpdatedProductPricesFromExtraPriceList(BaseTestCaseMixin):
2262
+ """
2263
+ Test case for GetUpdatedProductPricesFromExtraPriceList
2264
+ run: python -m unittest channel_app.omnitron.commands.tests.test_products.TestGetUpdatedProductPricesFromExtraPriceList
2265
+ """
2266
+ def setUp(self) -> None:
2267
+ self.get_updated_product_prices_from_extra_price_list = GetUpdatedProductPricesFromExtraPriceList(
2268
+ integration=self.mock_integration
2269
+ )
2270
+ self.get_updated_product_prices_from_extra_price_list.objects = [1, 2]
2271
+ self.get_updated_product_prices_from_extra_price_list.price_list_id = 1
2272
+ self.product_prices = [
2273
+ ProductPrice(
2274
+ pk=1,
2275
+ product=5,
2276
+ price='645670668.11',
2277
+ price_list=1,
2278
+ currency_type='try',
2279
+ tax_rate='32.61',
2280
+ remote_id='1',
2281
+ retail_price=None,
2282
+ extra_field={},
2283
+ discount_percentage='63.57',
2284
+ modified_date='2024-01-02T07:53:06.392780Z',
2285
+ created_date='2024-01-02T07:53:06.392771Z',
2286
+ price_type='default'
2287
+ ),
2288
+ ProductPrice(
2289
+ pk=2,
2290
+ product=6,
2291
+ price='493154528.49',
2292
+ price_list=1,
2293
+ currency_type='try',
2294
+ tax_rate='31.13',
2295
+ remote_id='2',
2296
+ retail_price=None,
2297
+ extra_field={},
2298
+ discount_percentage='26.55',
2299
+ modified_date='2024-01-09T13:20:23.472505Z',
2300
+ created_date='2024-01-09T13:20:23.472485Z',
2301
+ price_type='default'
2302
+ )
2303
+ ]
2304
+ self.product_prices_json = [
2305
+ {
2306
+ "pk": 1,
2307
+ "product": 5,
2308
+ "price": "645670668.11",
2309
+ "price_list": 1,
2310
+ "currency_type": "try",
2311
+ "tax_rate": "32.61",
2312
+ "remote_id": None,
2313
+ "retail_price": None,
2314
+ "extra_field": {},
2315
+ "discount_percentage": "63.57",
2316
+ "modified_date": "2024-01-02T07:53:06.392780Z",
2317
+ "created_date": "2024-01-02T07:53:06.392771Z",
2318
+ "price_type": "default"
2319
+ },
2320
+ {
2321
+ "pk": 2,
2322
+ "product": 6,
2323
+ "price": "493154528.49",
2324
+ "price_list": 1,
2325
+ "currency_type": "try",
2326
+ "tax_rate": "31.13",
2327
+ "remote_id": None,
2328
+ "retail_price": None,
2329
+ "extra_field": {},
2330
+ "discount_percentage": "26.55",
2331
+ "modified_date": "2024-01-09T13:20:23.472505Z",
2332
+ "created_date": "2024-01-09T13:20:23.472485Z",
2333
+ "price_type": "default"
2334
+ }
2335
+ ]
2336
+ self.integration_actions = [
2337
+ MagicMock(
2338
+ pk=1,
2339
+ channel=2,
2340
+ content_type=ContentType.product_price.value,
2341
+ object_id=self.product_prices[0].pk,
2342
+ remote_id='1',
2343
+ version_date="2023-12-28T10:28:17.186730Z",
2344
+ state={},
2345
+ modified_date="2023-12-28T10:28:17.187032Z",
2346
+ local_batch_id=None,
2347
+ status=None,
2348
+ created_date="2023-12-28T10:28:17.187014Z"
2349
+ ),
2350
+ MagicMock(
2351
+ pk=2,
2352
+ channel=2,
2353
+ content_type=ContentType.product_price.value,
2354
+ object_id=self.product_prices[1].pk,
2355
+ remote_id='2',
2356
+ version_date="2023-12-28T10:28:17.186730Z",
2357
+ state={},
2358
+ modified_date="2023-12-28T10:28:17.187032Z",
2359
+ local_batch_id=None,
2360
+ status=None,
2361
+ created_date="2023-12-28T10:28:17.187014Z"
2362
+ )
2363
+ ]
2364
+
2365
+ @patch.object(
2366
+ GetUpdatedProductPricesFromExtraPriceList,
2367
+ 'get_product_prices'
2368
+ )
2369
+ @patch.object(
2370
+ GetUpdatedProductPricesFromExtraPriceList,
2371
+ 'get_integration_actions'
2372
+ )
2373
+ def test_get_data(
2374
+ self,
2375
+ mock_get_product_prices,
2376
+ mock_get_integration_actions
2377
+ ):
2378
+ mock_get_product_prices.return_value = self.product_prices
2379
+ mock_get_integration_actions.return_value = self.integration_actions
2380
+ data = self.get_updated_product_prices_from_extra_price_list.get_data()
2381
+ self.assertEqual(len(data), 2)
2382
+ self.assertEqual(data[0].pk, self.product_prices[0].pk)
2383
+ self.assertEqual(data[1].pk, self.product_prices[1].pk)
2384
+
2385
+ @patch.object(
2386
+ BaseClient,
2387
+ 'get_instance'
2388
+ )
2389
+ @patch.object(
2390
+ GetUpdatedProductPricesFromExtraPriceList,
2391
+ 'create_batch_objects'
2392
+ )
2393
+ @patch.object(
2394
+ GetUpdatedProductPricesFromExtraPriceList,
2395
+ 'update_batch_request'
2396
+ )
2397
+ def test_get_product_prices(
2398
+ self,
2399
+ mock_get_instance,
2400
+ mock_create_batch_objects,
2401
+ mock_update_batch_request
2402
+ ):
2403
+ example_response = MagicMock()
2404
+ example_response.list.return_value = self.product_prices_json
2405
+
2406
+ with patch.object(
2407
+ ChannelExtraProductPriceEndpoint,
2408
+ '__new__',
2409
+ return_value=example_response
2410
+ ):
2411
+ data = self.get_updated_product_prices_from_extra_price_list.get_product_prices()
2412
+
2413
+ self.assertEqual(len(data), 2)
2414
+ self.assertEqual(data[0].get('pk'), self.product_prices[0].pk)
2415
+ self.assertEqual(data[1].get('pk'), self.product_prices[1].pk)
2416
+
2417
+ def test_get_integration_actions_with_empty_prices(self):
2418
+ self.product_prices = []
2419
+ data = self.get_updated_product_prices_from_extra_price_list.get_integration_actions(
2420
+ self.product_prices
2421
+ )
2422
+ self.assertEqual(data, [])
2423
+
2424
+ @patch.object(BaseClient, 'get_instance')
2425
+ def test_get_integration_actions(self, mock_get_instance):
2426
+ example_response = MagicMock()
2427
+ example_response.list.return_value = self.integration_actions
2428
+ example_response.iterator = iter(self.integration_actions)
2429
+
2430
+ with patch.object(
2431
+ ChannelIntegrationActionEndpoint,
2432
+ '__new__',
2433
+ return_value=example_response
2434
+ ):
2435
+ data = self.get_updated_product_prices_from_extra_price_list.get_integration_actions(
2436
+ self.product_prices
2437
+ )
2438
+
2439
+ self.assertEqual(len(data), 2)
2440
+ self.assertEqual(data[0].pk, self.integration_actions[0].object_id)
2441
+ self.assertEqual(data[1].pk, self.integration_actions[1].object_id)
2442
+ self.assertEqual(
2443
+ data[0].remote_id,
2444
+ self.integration_actions[0].remote_id
2445
+ )
2446
+ self.assertEqual(
2447
+ data[1].remote_id,
2448
+ self.integration_actions[1].remote_id
2449
+ )