channel-app 0.0.131__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.
Files changed (61) hide show
  1. channel_app/app/product/service.py +16 -0
  2. channel_app/core/commands.py +3 -1
  3. channel_app/core/tests.py +15 -164
  4. channel_app/omnitron/commands/tests/test_products.py +494 -0
  5. {channel_app-0.0.131.dist-info → channel_app-0.0.135.dist-info}/METADATA +1 -1
  6. channel_app-0.0.135.dist-info/RECORD +60 -0
  7. {channel_app-0.0.131.dist-info → channel_app-0.0.135.dist-info}/WHEEL +1 -1
  8. channel_app/channel_app/app/__init__.py +0 -0
  9. channel_app/channel_app/app/order/__init__.py +0 -0
  10. channel_app/channel_app/app/order/service.py +0 -230
  11. channel_app/channel_app/app/product/__init__.py +0 -0
  12. channel_app/channel_app/app/product/service.py +0 -237
  13. channel_app/channel_app/app/product_price/__init__.py +0 -0
  14. channel_app/channel_app/app/product_price/service.py +0 -254
  15. channel_app/channel_app/app/product_stock/__init__.py +0 -0
  16. channel_app/channel_app/app/product_stock/service.py +0 -258
  17. channel_app/channel_app/app/setup/__init__.py +0 -0
  18. channel_app/channel_app/app/setup/service.py +0 -61
  19. channel_app/channel_app/channel/__init__.py +0 -0
  20. channel_app/channel_app/channel/commands/__init__.py +0 -0
  21. channel_app/channel_app/channel/commands/orders/__init__.py +0 -0
  22. channel_app/channel_app/channel/commands/orders/orders.py +0 -329
  23. channel_app/channel_app/channel/commands/product_categories.py +0 -1
  24. channel_app/channel_app/channel/commands/product_images.py +0 -1
  25. channel_app/channel_app/channel/commands/product_prices.py +0 -148
  26. channel_app/channel_app/channel/commands/product_stocks.py +0 -220
  27. channel_app/channel_app/channel/commands/products.py +0 -161
  28. channel_app/channel_app/channel/commands/setup.py +0 -948
  29. channel_app/channel_app/channel/integration.py +0 -84
  30. channel_app/channel_app/core/__init__.py +0 -0
  31. channel_app/channel_app/core/clients.py +0 -12
  32. channel_app/channel_app/core/commands.py +0 -364
  33. channel_app/channel_app/core/data.py +0 -227
  34. channel_app/channel_app/core/integration.py +0 -74
  35. channel_app/channel_app/core/products.py +0 -64
  36. channel_app/channel_app/core/settings.py +0 -28
  37. channel_app/channel_app/core/utilities.py +0 -99
  38. channel_app/channel_app/omnitron/__init__.py +0 -0
  39. channel_app/channel_app/omnitron/batch_request.py +0 -82
  40. channel_app/channel_app/omnitron/commands/__init__.py +0 -0
  41. channel_app/channel_app/omnitron/commands/batch_requests.py +0 -281
  42. channel_app/channel_app/omnitron/commands/error_reports.py +0 -86
  43. channel_app/channel_app/omnitron/commands/integration_actions.py +0 -200
  44. channel_app/channel_app/omnitron/commands/orders/__init__.py +0 -0
  45. channel_app/channel_app/omnitron/commands/orders/addresses.py +0 -242
  46. channel_app/channel_app/omnitron/commands/orders/cargo_companies.py +0 -40
  47. channel_app/channel_app/omnitron/commands/orders/customers.py +0 -72
  48. channel_app/channel_app/omnitron/commands/orders/orders.py +0 -450
  49. channel_app/channel_app/omnitron/commands/product_categories.py +0 -1
  50. channel_app/channel_app/omnitron/commands/product_images.py +0 -1
  51. channel_app/channel_app/omnitron/commands/product_prices.py +0 -192
  52. channel_app/channel_app/omnitron/commands/product_stocks.py +0 -229
  53. channel_app/channel_app/omnitron/commands/products.py +0 -735
  54. channel_app/channel_app/omnitron/commands/setup.py +0 -839
  55. channel_app/channel_app/omnitron/constants.py +0 -98
  56. channel_app/channel_app/omnitron/exceptions.py +0 -42
  57. channel_app/channel_app/omnitron/integration.py +0 -159
  58. channel_app/setup.py +0 -21
  59. channel_app-0.0.131.dist-info/RECORD +0 -110
  60. /channel_app/{channel_app → omnitron/commands/tests}/__init__.py +0 -0
  61. {channel_app-0.0.131.dist-info → channel_app-0.0.135.dist-info}/top_level.txt +0 -0
@@ -20,6 +20,8 @@ class ProductService(object):
20
20
  content_type=ContentType.product.value) as omnitron_integration:
21
21
  products = omnitron_integration.do_action(
22
22
  key='get_inserted_products')
23
+
24
+ first_product_count = len(products)
23
25
 
24
26
  if add_mapped:
25
27
  products = products and omnitron_integration.do_action(
@@ -38,6 +40,12 @@ class ProductService(object):
38
40
  key='get_product_categories', objects=products)
39
41
 
40
42
  if not products:
43
+ if first_product_count:
44
+ omnitron_integration.batch_request.objects = None
45
+ self.batch_service(omnitron_integration.channel_id).to_fail(
46
+ omnitron_integration.batch_request
47
+ )
48
+
41
49
  return
42
50
 
43
51
  products: List[Product]
@@ -78,6 +86,8 @@ class ProductService(object):
78
86
  content_type=ContentType.product.value) as omnitron_integration:
79
87
  products = omnitron_integration.do_action(
80
88
  key='get_updated_products')
89
+
90
+ first_product_count = len(products)
81
91
 
82
92
  if add_mapped:
83
93
  products = products and omnitron_integration.do_action(
@@ -96,6 +106,12 @@ class ProductService(object):
96
106
  key='get_product_categories', objects=products)
97
107
 
98
108
  if not products:
109
+ if first_product_count:
110
+ omnitron_integration.batch_request.objects = None
111
+ self.batch_service(omnitron_integration.channel_id).to_fail(
112
+ omnitron_integration.batch_request
113
+ )
114
+
99
115
  return
100
116
 
101
117
  products: List[Product]
@@ -238,7 +238,9 @@ class OmnitronCommandInterface(CommandInterface):
238
238
  return formatted_data
239
239
 
240
240
  def check_run(self, is_ok, formatted_data):
241
- if is_ok and not formatted_data and self.is_batch_request:
241
+ if is_ok and not \
242
+ (formatted_data or self.failed_object_list) and \
243
+ self.is_batch_request:
242
244
  self.batch_service(self.integration.channel_id).to_done(
243
245
  self.integration.batch_request)
244
246
  return False
channel_app/core/tests.py CHANGED
@@ -1,165 +1,16 @@
1
- from redis import Redis
2
1
  import unittest
3
- from unittest.mock import patch, Mock
4
-
5
- from channel_app.core.clients import OmnitronApiClient
6
- from omnisdk.exceptions import ValidationError
7
-
8
-
9
- class TestOmnitronApiClient(unittest.TestCase):
10
- """
11
- run:
12
- python -m unittest channel_app.core.tests.TestOmnitronApiClient
13
- """
14
- redis_con = Redis()
15
- omnitron_auth_url = "https://example.com/api/v1/auth/login/"
16
- test_token = "Token test_key"
17
-
18
- @patch("channel_app.core.clients.RedisClient")
19
- @patch('requests.Session')
20
- def setUp(self, mock_session, mock_redis_client):
21
- self.redis_con.flushall()
22
- mock_redis_client.return_value = self.redis_con
23
- # Create a mock session and set it as the return value of
24
- # requests.Session()
25
- self.mock_session = mock_session.return_value
26
- self.mock_session.post.return_value = Mock(
27
- status_code=200,
28
- json=Mock(return_value={"key": "test_key"})
29
- )
30
- self.base_url = "https://example.com/"
31
- self.username = "testuser"
32
- self.password = "testpassword"
33
- self.client = OmnitronApiClient(
34
- self.base_url,
35
- self.username,
36
- self.password
37
- )
38
-
39
- def test_token_property(self):
40
- # Assert that the session.post() method was called once
41
- self.mock_session.post.assert_called_once_with(
42
- self.omnitron_auth_url,
43
- json={"username": "testuser", "password": "testpassword"}
44
- )
45
- # Assert that the self.client.redis_prefix key is set to the token
46
- self.assertEqual(
47
- self.redis_con.get(self.client.redis_prefix).decode("utf-8"),
48
- self.test_token
49
- )
50
- # Call token property and assert that the token is returned
51
- for _ in range(2):
52
- token = self.client.token
53
- self.assertEqual(
54
- token,
55
- self.test_token
56
- )
57
-
58
- # Assert that the session.post() method was called only once
59
- self.mock_session.post.assert_called_once_with(
60
- self.omnitron_auth_url,
61
- json={"username": "testuser", "password": "testpassword"}
62
- )
63
-
64
- def test_refresh_key(self):
65
- self.redis_con.flushall()
66
- self.mock_session.reset_mock()
67
- self.mock_session.post.return_value = Mock(
68
- status_code=200,
69
- json=Mock(return_value={"key": "updated_key"})
70
- )
71
- self.client.refresh_key()
72
- # Assert that the session.post() method was called once
73
- self.mock_session.post.assert_called_once_with(
74
- self.omnitron_auth_url,
75
- json={"username": "testuser", "password": "testpassword"}
76
- )
77
- # Assert that the self.client.redis_prefix key is set to the token
78
- self.assertEqual(
79
- self.redis_con.get(self.client.redis_prefix).decode("utf-8"),
80
- "Token updated_key"
81
- )
82
-
83
- def test_refresh_key_with_authentication_error(self):
84
- self.redis_con.flushall()
85
- self.mock_session.reset_mock()
86
- self.mock_session.post.return_value = Mock(
87
- status_code=400,
88
- json=Mock(return_value={"error_message": "Authentication failed"})
89
- )
90
-
91
- with self.assertRaises(ValidationError) as context:
92
- self.client.refresh_key()
93
-
94
- self.assertIn("Authentication failed", str(context.exception))
95
- self.mock_session.post.assert_called_once_with(
96
- self.omnitron_auth_url,
97
- json={"username": "testuser", "password": "testpassword"}
98
- )
99
- # Assert that the self.client.redis_prefix key is not set
100
- self.assertIsNone(
101
- self.redis_con.get(self.client.redis_prefix)
102
- )
103
-
104
- def test_set_token(self):
105
- # Get token from redis which is set at initialization of the client
106
- token = self.client.token
107
- self.assertEqual(
108
- token,
109
- self.test_token
110
- )
111
- new_token = "Token test_new_key"
112
- self.client.set_token(new_token)
113
- self.assertEqual(
114
- self.client.token,
115
- new_token
116
- )
117
- # Assert that the self.client.redis_prefix key is set to the token
118
- self.assertEqual(
119
- self.redis_con.get(self.client.redis_prefix).decode("utf-8"),
120
- new_token
121
- )
122
-
123
-
124
- def test_retry_count_with(self):
125
- # Get token from redis which is set at initialization of the client
126
- token = self.client.token
127
- self.assertEqual(
128
- token,
129
- self.test_token
130
- )
131
- new_token = "Token test_new_key"
132
- self.client.set_token(new_token)
133
- self.assertEqual(
134
- self.client.token,
135
- new_token
136
- )
137
- # Assert that the self.client.redis_prefix key is set to the token
138
- self.assertEqual(
139
- self.redis_con.get(self.client.redis_prefix).decode("utf-8"),
140
- new_token
141
- )
142
- self.assertEqual(
143
- int(self.redis_con.get("retry_count").decode("utf-8")),
144
- 1
145
- )
146
-
147
- def test_retry_count(self):
148
- self.redis_con.flushall()
149
- for i in range(3):
150
- token = self.client.token
151
- self.assertEqual(
152
- token,
153
- self.test_token
154
- )
155
- self.redis_con.delete(self.client.redis_prefix)
156
- with self.assertRaises(Exception) as context:
157
- self.client.token
158
- self.assertIn(
159
- "Login attempts exceeded 3 times in 6 min.",
160
- str(context.exception)
161
- )
162
- self.assertEqual(
163
- int(self.redis_con.get("retry_count").decode("utf-8")),
164
- i + 1
165
- )
2
+ from unittest.mock import MagicMock
3
+ from channel_app.core.commands import OmnitronCommandInterface
4
+
5
+
6
+ class BaseTestCaseMixin(unittest.TestCase):
7
+ mock_integration = MagicMock()
8
+ omnitron_command_interface = OmnitronCommandInterface(
9
+ integration=mock_integration
10
+ )
11
+
12
+ def setUp(self) -> None:
13
+ return super().setUp()
14
+
15
+ def tearDown(self) -> None:
16
+ return super().tearDown()