channel-app 0.0.134__py3-none-any.whl → 0.0.135__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.
- channel_app/omnitron/commands/tests/test_products.py +251 -4
- {channel_app-0.0.134.dist-info → channel_app-0.0.135.dist-info}/METADATA +1 -1
- {channel_app-0.0.134.dist-info → channel_app-0.0.135.dist-info}/RECORD +5 -5
- {channel_app-0.0.134.dist-info → channel_app-0.0.135.dist-info}/WHEEL +0 -0
- {channel_app-0.0.134.dist-info → channel_app-0.0.135.dist-info}/top_level.txt +0 -0
@@ -4,12 +4,15 @@ from omnisdk.omnitron.endpoints import (
|
|
4
4
|
ChannelIntegrationActionEndpoint,
|
5
5
|
ChannelProductEndpoint,
|
6
6
|
)
|
7
|
+
from omnisdk.omnitron.models import ChannelAttributeConfig
|
8
|
+
|
9
|
+
from channel_app.core.commands import OmnitronCommandInterface
|
7
10
|
from channel_app.core.tests import BaseTestCaseMixin
|
8
11
|
from channel_app.omnitron.commands.products import (
|
9
12
|
GetDeletedProducts,
|
10
|
-
GetInsertedProducts,
|
11
|
-
GetUpdatedProducts,
|
12
|
-
Product,
|
13
|
+
GetInsertedProducts,
|
14
|
+
GetUpdatedProducts,
|
15
|
+
Product, GetMappedProducts, GetProductPrices,
|
13
16
|
)
|
14
17
|
from channel_app.omnitron.constants import BatchRequestStatus
|
15
18
|
|
@@ -244,4 +247,248 @@ class TestGetDeletedProducts(BaseTestCaseMixin):
|
|
244
247
|
self.assertEqual(len(products_ia), 1)
|
245
248
|
|
246
249
|
product = products_ia[0].get_parameters()
|
247
|
-
self.assertEqual(product.get('pk'), 23)
|
250
|
+
self.assertEqual(product.get('pk'), 23)
|
251
|
+
|
252
|
+
|
253
|
+
class TestGetMappedProducts(BaseTestCaseMixin):
|
254
|
+
"""
|
255
|
+
Test case for GetMappedProducts
|
256
|
+
run: python -m unittest channel_app.omnitron.commands.tests.test_products.TestGetMappedProducts
|
257
|
+
"""
|
258
|
+
|
259
|
+
def setUp(self) -> None:
|
260
|
+
self.get_mapped_products = GetMappedProducts(
|
261
|
+
integration=self.mock_integration
|
262
|
+
)
|
263
|
+
self.sample_products = [
|
264
|
+
Product(
|
265
|
+
pk=1,
|
266
|
+
name='test',
|
267
|
+
failed_reason_type=None,
|
268
|
+
modified_date='2021-01-01T00:00:00Z'
|
269
|
+
),
|
270
|
+
Product(
|
271
|
+
pk=2,
|
272
|
+
name='test2',
|
273
|
+
failed_reason_type='error',
|
274
|
+
modified_date='2021-01-01T00:00:00Z'
|
275
|
+
)
|
276
|
+
]
|
277
|
+
|
278
|
+
@patch.object(GetMappedProducts, 'get_mapping')
|
279
|
+
def test_get_data(self, mock_get_mapping):
|
280
|
+
mock_get_mapping.return_value = self.sample_products
|
281
|
+
result = self.get_mapped_products.get_data()
|
282
|
+
self.assertEqual(len(result), 2)
|
283
|
+
|
284
|
+
@patch.object(GetMappedProducts, 'check_product')
|
285
|
+
def test_validated_data(self, mock_check_product):
|
286
|
+
data = self.sample_products
|
287
|
+
self.get_mapped_products.validated_data(data)
|
288
|
+
self.assertEqual(mock_check_product.call_count, 2)
|
289
|
+
|
290
|
+
@patch.object(GetMappedProducts, 'get_attribute_config_list')
|
291
|
+
@patch.object(GetMappedProducts, 'update_and_check_product')
|
292
|
+
def test_check_product_gets_attribute_config_list(
|
293
|
+
self,
|
294
|
+
mock_update_and_check_product,
|
295
|
+
mock_get_attribute_config_list
|
296
|
+
):
|
297
|
+
product = Product()
|
298
|
+
product.mapped_attributes = MagicMock()
|
299
|
+
product.mapped_attributes.attribute_set_id = 1
|
300
|
+
product.mapped_attributes.mapped_attribute_values = {
|
301
|
+
"1": {
|
302
|
+
"value": "test"
|
303
|
+
}
|
304
|
+
}
|
305
|
+
mock_get_attribute_config_list.return_value = [
|
306
|
+
ChannelAttributeConfig()
|
307
|
+
]
|
308
|
+
self.get_mapped_products.check_product(
|
309
|
+
product,
|
310
|
+
{}
|
311
|
+
)
|
312
|
+
mock_get_attribute_config_list.assert_called_once()
|
313
|
+
|
314
|
+
@patch.object(GetMappedProducts, 'check_attribute_value_defined')
|
315
|
+
@patch.object(GetMappedProducts, 'check_required')
|
316
|
+
def test_update_and_check_product_checks_attribute_value_and_required(
|
317
|
+
self,
|
318
|
+
mock_check_required,
|
319
|
+
mock_check_attribute_value_defined
|
320
|
+
):
|
321
|
+
product = Product()
|
322
|
+
product.mapped_attributes = MagicMock()
|
323
|
+
product.mapped_attributes.mapped_attribute_values = {}
|
324
|
+
config = ChannelAttributeConfig()
|
325
|
+
config.attribute_remote_id = 1
|
326
|
+
config.is_required = True
|
327
|
+
config.is_variant = True
|
328
|
+
config.is_custom = True
|
329
|
+
config.is_meta = True
|
330
|
+
config.attribute = {
|
331
|
+
"pk": 1,
|
332
|
+
"name": "test",
|
333
|
+
}
|
334
|
+
result = self.get_mapped_products.update_and_check_product(
|
335
|
+
config,
|
336
|
+
product
|
337
|
+
)
|
338
|
+
self.assertFalse(result)
|
339
|
+
|
340
|
+
@patch.object(GetMappedProducts, 'check_attribute_value_defined')
|
341
|
+
@patch.object(GetMappedProducts, 'check_required')
|
342
|
+
def test_update_and_check_product(
|
343
|
+
self,
|
344
|
+
mock_check_required,
|
345
|
+
mock_check_attribute_value_defined
|
346
|
+
):
|
347
|
+
product = Product()
|
348
|
+
product.mapped_attributes = MagicMock()
|
349
|
+
product.mapped_attributes.mapped_attribute_values = {
|
350
|
+
"1": {
|
351
|
+
"value": "test"
|
352
|
+
}
|
353
|
+
}
|
354
|
+
config = ChannelAttributeConfig()
|
355
|
+
config.attribute_remote_id = 1
|
356
|
+
config.is_required = True
|
357
|
+
config.is_variant = True
|
358
|
+
config.is_custom = True
|
359
|
+
config.is_meta = True
|
360
|
+
config.attribute = {
|
361
|
+
"pk": 1,
|
362
|
+
"name": "test",
|
363
|
+
}
|
364
|
+
result = self.get_mapped_products.update_and_check_product(
|
365
|
+
config,
|
366
|
+
product
|
367
|
+
)
|
368
|
+
self.assertTrue(result)
|
369
|
+
|
370
|
+
@patch.object(GetMappedProducts, 'get_attribute_config_list')
|
371
|
+
def test_get_attribute_config_list_returns_configs_data(
|
372
|
+
self,
|
373
|
+
mock_get_attribute_config_list
|
374
|
+
):
|
375
|
+
config = ChannelAttributeConfig()
|
376
|
+
mock_get_attribute_config_list.return_value = [
|
377
|
+
config
|
378
|
+
]
|
379
|
+
result = self.get_mapped_products.get_attribute_config_list(
|
380
|
+
{"attribute_set": 1, "limit": 10}
|
381
|
+
)
|
382
|
+
self.assertEqual(result, [config])
|
383
|
+
|
384
|
+
def test_check_attribute_value_defined_raises_exception_when_mapped_value_not_defined(self):
|
385
|
+
mapped_attributes_obj = MagicMock()
|
386
|
+
mapped_attributes_obj.mapped_attributes = {"name": "value"}
|
387
|
+
mapped_attributes_obj.mapped_attribute_values = {}
|
388
|
+
config = ChannelAttributeConfig()
|
389
|
+
config.attribute = {"pk": 1, "name": "name"}
|
390
|
+
config.attribute_set = {"pk": 1, "name": "name"}
|
391
|
+
config.is_custom = False
|
392
|
+
with self.assertRaises(Exception):
|
393
|
+
self.get_mapped_products.check_attribute_value_defined(
|
394
|
+
config,
|
395
|
+
mapped_attributes_obj
|
396
|
+
)
|
397
|
+
|
398
|
+
def test_check_required_raises_exception_when_required_attribute_missing(self):
|
399
|
+
product = Product()
|
400
|
+
product.sku = "sku"
|
401
|
+
self.get_mapped_products.integration = MagicMock()
|
402
|
+
self.get_mapped_products.integration.channel_id = 1
|
403
|
+
mapped_attributes = {}
|
404
|
+
config = ChannelAttributeConfig()
|
405
|
+
config.attribute = {"name": "name"}
|
406
|
+
config.is_required = True
|
407
|
+
with self.assertRaises(Exception):
|
408
|
+
self.get_mapped_products.check_required(
|
409
|
+
product,
|
410
|
+
config,
|
411
|
+
mapped_attributes
|
412
|
+
)
|
413
|
+
|
414
|
+
@patch.object(GetMappedProducts, 'get_mapping')
|
415
|
+
def test_get_mapping_returns_mapped_products(self, mock_get_mapping):
|
416
|
+
product = Product()
|
417
|
+
mock_get_mapping.return_value = [product]
|
418
|
+
result = self.get_mapped_products.get_mapping([product])
|
419
|
+
self.assertEqual(result, [product])
|
420
|
+
|
421
|
+
@patch.object(GetMappedProducts, 'get_mapping')
|
422
|
+
def test_get_mapping_returns_empty_list_when_no_products(self, mock_get_mapping):
|
423
|
+
mock_get_mapping.return_value = []
|
424
|
+
result = self.get_mapped_products.get_mapping([])
|
425
|
+
self.assertEqual(result, [])
|
426
|
+
|
427
|
+
|
428
|
+
class TestGetMappedProductsWithOutCommit(TestGetMappedProducts):
|
429
|
+
pass
|
430
|
+
|
431
|
+
|
432
|
+
class TestGetProductPrices(BaseTestCaseMixin):
|
433
|
+
"""
|
434
|
+
Test case for GetProductPrices
|
435
|
+
run: python -m unittest channel_app.omnitron.commands.tests.test_products.TestGetProductPrices
|
436
|
+
"""
|
437
|
+
|
438
|
+
def setUp(self) -> None:
|
439
|
+
self.get_product_prices = GetProductPrices(
|
440
|
+
integration=self.mock_integration
|
441
|
+
)
|
442
|
+
|
443
|
+
@patch.object(BaseClient, 'get_instance')
|
444
|
+
@patch.object(GetProductPrices, 'get_prices')
|
445
|
+
def test_successful_product_price_retrieval(
|
446
|
+
self,
|
447
|
+
mock_get_instance,
|
448
|
+
mock_get_prices
|
449
|
+
):
|
450
|
+
products = [Product(pk=i, productprice=10) for i in range(1, 6)]
|
451
|
+
self.get_product_prices.objects = products
|
452
|
+
|
453
|
+
result = self.get_product_prices.get_data()
|
454
|
+
self.assertEqual(result, products)
|
455
|
+
|
456
|
+
@patch.object(GetProductPrices, 'get_prices')
|
457
|
+
@patch.object(BaseClient, 'get_instance')
|
458
|
+
def test_product_price_retrieval_with_successful_get_product_price(
|
459
|
+
self,
|
460
|
+
mock_get_instance,
|
461
|
+
mock_get_prices
|
462
|
+
):
|
463
|
+
products = [Product(pk=i) for i in range(1, 6)]
|
464
|
+
|
465
|
+
price_list = []
|
466
|
+
for product in products:
|
467
|
+
price = MagicMock()
|
468
|
+
price.product = product.pk
|
469
|
+
price_list.append(price)
|
470
|
+
|
471
|
+
mock_get_prices.return_value = price_list
|
472
|
+
result = self.get_product_prices.get_product_price(products)
|
473
|
+
self.assertEqual(result, products)
|
474
|
+
|
475
|
+
@patch.object(GetProductPrices, 'get_prices')
|
476
|
+
@patch.object(BaseClient, 'get_instance')
|
477
|
+
def test_product_price_retrieval_with_failed_get_product_price(
|
478
|
+
self,
|
479
|
+
mock_get_instance,
|
480
|
+
mock_get_prices
|
481
|
+
):
|
482
|
+
products = [Product(pk=i, product_price=0) for i in range(1, 6)]
|
483
|
+
|
484
|
+
price_list = []
|
485
|
+
for product in products:
|
486
|
+
price = MagicMock()
|
487
|
+
price.product = product.pk
|
488
|
+
|
489
|
+
if len(price_list) < len(products) - 1:
|
490
|
+
price_list.append(price)
|
491
|
+
|
492
|
+
mock_get_prices.return_value = price_list
|
493
|
+
result = self.get_product_prices.get_product_price(products)
|
494
|
+
self.assertFalse(hasattr(result[-1], 'productprice'))
|
@@ -53,8 +53,8 @@ channel_app/omnitron/commands/orders/cargo_companies.py,sha256=pTyOgsoIBLHUIj7F2
|
|
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=
|
57
|
-
channel_app-0.0.
|
58
|
-
channel_app-0.0.
|
59
|
-
channel_app-0.0.
|
60
|
-
channel_app-0.0.
|
56
|
+
channel_app/omnitron/commands/tests/test_products.py,sha256=fHw4APDAoeCZ26eodk_xDTMfLpTXBG95MTDnkfD22KI,17220
|
57
|
+
channel_app-0.0.135.dist-info/METADATA,sha256=st1fMGE1L-XPVYRLJ7QlALqLl9Za6jtepbrQENRQ2is,353
|
58
|
+
channel_app-0.0.135.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
59
|
+
channel_app-0.0.135.dist-info/top_level.txt,sha256=JT-gM6L5Cwxr1xEoN7NHrREDs-d6iGFGfRnK-NrJ3tU,12
|
60
|
+
channel_app-0.0.135.dist-info/RECORD,,
|
File without changes
|
File without changes
|