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.
- channel_app/app/product/service.py +16 -0
- channel_app/core/commands.py +3 -1
- channel_app/core/tests.py +15 -164
- channel_app/omnitron/commands/tests/test_products.py +494 -0
- {channel_app-0.0.131.dist-info → channel_app-0.0.135.dist-info}/METADATA +1 -1
- channel_app-0.0.135.dist-info/RECORD +60 -0
- {channel_app-0.0.131.dist-info → channel_app-0.0.135.dist-info}/WHEEL +1 -1
- channel_app/channel_app/app/__init__.py +0 -0
- channel_app/channel_app/app/order/__init__.py +0 -0
- channel_app/channel_app/app/order/service.py +0 -230
- channel_app/channel_app/app/product/__init__.py +0 -0
- channel_app/channel_app/app/product/service.py +0 -237
- channel_app/channel_app/app/product_price/__init__.py +0 -0
- channel_app/channel_app/app/product_price/service.py +0 -254
- channel_app/channel_app/app/product_stock/__init__.py +0 -0
- channel_app/channel_app/app/product_stock/service.py +0 -258
- channel_app/channel_app/app/setup/__init__.py +0 -0
- channel_app/channel_app/app/setup/service.py +0 -61
- channel_app/channel_app/channel/__init__.py +0 -0
- channel_app/channel_app/channel/commands/__init__.py +0 -0
- channel_app/channel_app/channel/commands/orders/__init__.py +0 -0
- channel_app/channel_app/channel/commands/orders/orders.py +0 -329
- channel_app/channel_app/channel/commands/product_categories.py +0 -1
- channel_app/channel_app/channel/commands/product_images.py +0 -1
- channel_app/channel_app/channel/commands/product_prices.py +0 -148
- channel_app/channel_app/channel/commands/product_stocks.py +0 -220
- channel_app/channel_app/channel/commands/products.py +0 -161
- channel_app/channel_app/channel/commands/setup.py +0 -948
- channel_app/channel_app/channel/integration.py +0 -84
- channel_app/channel_app/core/__init__.py +0 -0
- channel_app/channel_app/core/clients.py +0 -12
- channel_app/channel_app/core/commands.py +0 -364
- channel_app/channel_app/core/data.py +0 -227
- channel_app/channel_app/core/integration.py +0 -74
- channel_app/channel_app/core/products.py +0 -64
- channel_app/channel_app/core/settings.py +0 -28
- channel_app/channel_app/core/utilities.py +0 -99
- channel_app/channel_app/omnitron/__init__.py +0 -0
- channel_app/channel_app/omnitron/batch_request.py +0 -82
- channel_app/channel_app/omnitron/commands/__init__.py +0 -0
- channel_app/channel_app/omnitron/commands/batch_requests.py +0 -281
- channel_app/channel_app/omnitron/commands/error_reports.py +0 -86
- channel_app/channel_app/omnitron/commands/integration_actions.py +0 -200
- channel_app/channel_app/omnitron/commands/orders/__init__.py +0 -0
- channel_app/channel_app/omnitron/commands/orders/addresses.py +0 -242
- channel_app/channel_app/omnitron/commands/orders/cargo_companies.py +0 -40
- channel_app/channel_app/omnitron/commands/orders/customers.py +0 -72
- channel_app/channel_app/omnitron/commands/orders/orders.py +0 -450
- channel_app/channel_app/omnitron/commands/product_categories.py +0 -1
- channel_app/channel_app/omnitron/commands/product_images.py +0 -1
- channel_app/channel_app/omnitron/commands/product_prices.py +0 -192
- channel_app/channel_app/omnitron/commands/product_stocks.py +0 -229
- channel_app/channel_app/omnitron/commands/products.py +0 -735
- channel_app/channel_app/omnitron/commands/setup.py +0 -839
- channel_app/channel_app/omnitron/constants.py +0 -98
- channel_app/channel_app/omnitron/exceptions.py +0 -42
- channel_app/channel_app/omnitron/integration.py +0 -159
- channel_app/setup.py +0 -21
- channel_app-0.0.131.dist-info/RECORD +0 -110
- /channel_app/{channel_app → omnitron/commands/tests}/__init__.py +0 -0
- {channel_app-0.0.131.dist-info → channel_app-0.0.135.dist-info}/top_level.txt +0 -0
@@ -1,161 +0,0 @@
|
|
1
|
-
import random
|
2
|
-
import uuid
|
3
|
-
from typing import List, Any, Tuple
|
4
|
-
|
5
|
-
from omnisdk.omnitron.models import Product, BatchRequest
|
6
|
-
|
7
|
-
from channel_app.core.commands import CommandInterface, ChannelCommandInterface
|
8
|
-
from channel_app.core.data import ProductBatchRequestResponseDto, ErrorReportDto
|
9
|
-
from channel_app.omnitron.constants import ResponseStatus
|
10
|
-
|
11
|
-
|
12
|
-
class SendInsertedProducts(ChannelCommandInterface):
|
13
|
-
param_sync = True
|
14
|
-
|
15
|
-
def get_data(self) -> List[Product]:
|
16
|
-
data = self.objects
|
17
|
-
return data
|
18
|
-
|
19
|
-
def validated_data(self, data) -> object:
|
20
|
-
return data
|
21
|
-
|
22
|
-
def transform_data(self, data) -> object:
|
23
|
-
return data
|
24
|
-
|
25
|
-
def send_request(self, transformed_data) -> object:
|
26
|
-
response = self.__mocked_request(data=transformed_data)
|
27
|
-
return response
|
28
|
-
|
29
|
-
def normalize_response(self, data, validated_data, transformed_data,
|
30
|
-
response) -> Tuple[
|
31
|
-
List[ProductBatchRequestResponseDto], List[ErrorReportDto], Any]:
|
32
|
-
report: List[ErrorReportDto] = self.create_report(response)
|
33
|
-
if not self.param_sync:
|
34
|
-
remote_batch_id = response.get("remote_batch_request_id")
|
35
|
-
self.batch_request.remote_batch_id = remote_batch_id
|
36
|
-
return "", report, data
|
37
|
-
else:
|
38
|
-
response_data = []
|
39
|
-
for row in response:
|
40
|
-
response_data.append(ProductBatchRequestResponseDto(
|
41
|
-
sku=row["sku"],
|
42
|
-
message=row["message"],
|
43
|
-
remote_id=row["remote_id"],
|
44
|
-
status=row["status"]
|
45
|
-
))
|
46
|
-
|
47
|
-
response_data: List[ProductBatchRequestResponseDto]
|
48
|
-
return response_data, report, data
|
49
|
-
|
50
|
-
def __mocked_request(self, data):
|
51
|
-
"""
|
52
|
-
Mock a request and response for the send operation to mimic actual channel data
|
53
|
-
:param data:
|
54
|
-
"""
|
55
|
-
batch_id = str(uuid.uuid4())
|
56
|
-
self.integration._sent_data[batch_id] = data
|
57
|
-
return {"remote_batch_request_id": batch_id}
|
58
|
-
|
59
|
-
def __mock_request_sync(self, data):
|
60
|
-
result = []
|
61
|
-
for row in data:
|
62
|
-
obj = dict(
|
63
|
-
sku=row["sku"],
|
64
|
-
message=row["message"],
|
65
|
-
remote_id=row["remote_id"],
|
66
|
-
status=row["status"])
|
67
|
-
result.append(obj)
|
68
|
-
return result
|
69
|
-
|
70
|
-
|
71
|
-
class SendUpdatedProducts(SendInsertedProducts):
|
72
|
-
pass
|
73
|
-
|
74
|
-
|
75
|
-
class SendDeletedProducts(SendInsertedProducts):
|
76
|
-
def __mocked_request(self, data):
|
77
|
-
"""
|
78
|
-
Mock a request and response for the send operation to mimic actual channel data
|
79
|
-
:param data:
|
80
|
-
"""
|
81
|
-
batch_id = str(uuid.uuid4())
|
82
|
-
self.integration._sent_data[batch_id] = data
|
83
|
-
return {"remote_batch_request_id": batch_id}
|
84
|
-
|
85
|
-
|
86
|
-
class CheckProducts(ChannelCommandInterface):
|
87
|
-
|
88
|
-
def get_data(self) -> BatchRequest:
|
89
|
-
batch_request = self.objects
|
90
|
-
return batch_request
|
91
|
-
|
92
|
-
def validated_data(self, data) -> object:
|
93
|
-
return data
|
94
|
-
|
95
|
-
def transform_data(self, data) -> object:
|
96
|
-
return data
|
97
|
-
|
98
|
-
def send_request(self, transformed_data: BatchRequest) -> object:
|
99
|
-
"""
|
100
|
-
Sends a post request to the channel client to insert the products
|
101
|
-
:param transformed_data:
|
102
|
-
:return: list
|
103
|
-
[{ remote_data},]
|
104
|
-
"""
|
105
|
-
|
106
|
-
response = self.__mocked_request(
|
107
|
-
data=self.integration._sent_data[transformed_data.remote_batch_id],
|
108
|
-
remote_batch_id=transformed_data.remote_batch_id)
|
109
|
-
return response
|
110
|
-
|
111
|
-
def normalize_response(self, data, validated_data, transformed_data,
|
112
|
-
response) -> Tuple[List[ProductBatchRequestResponseDto],
|
113
|
-
List[ErrorReportDto], Any]:
|
114
|
-
response_data = []
|
115
|
-
for row in response:
|
116
|
-
obj = ProductBatchRequestResponseDto(
|
117
|
-
sku=row["sku"],
|
118
|
-
message=row["message"],
|
119
|
-
remote_id=row["remote_id"],
|
120
|
-
status=row["status"])
|
121
|
-
response_data.append(obj)
|
122
|
-
report = self.create_report(response)
|
123
|
-
return response_data, report, data
|
124
|
-
|
125
|
-
def __mocked_request(self, data, remote_batch_id):
|
126
|
-
"""
|
127
|
-
Mock a request and response for the send operation to mimic actual channel data
|
128
|
-
:param data:
|
129
|
-
:return: list
|
130
|
-
|
131
|
-
[{
|
132
|
-
"status": "SUCCESS",
|
133
|
-
"remote_id": "123a1",
|
134
|
-
"sku": "1KBATC0197",
|
135
|
-
"message": ""
|
136
|
-
},]
|
137
|
-
"""
|
138
|
-
|
139
|
-
response_data = []
|
140
|
-
prefix = remote_batch_id[-8:]
|
141
|
-
for index, item in enumerate(data):
|
142
|
-
if random.random() < 0.8:
|
143
|
-
response_item = {
|
144
|
-
'sku': item.sku,
|
145
|
-
'message': "",
|
146
|
-
'remote_id': "{}_{}".format(prefix, index),
|
147
|
-
'status': ResponseStatus.success
|
148
|
-
}
|
149
|
-
else:
|
150
|
-
response_item = {
|
151
|
-
"status": ResponseStatus.fail,
|
152
|
-
"remote_id": None,
|
153
|
-
"sku": item.sku,
|
154
|
-
"message": "exception message"
|
155
|
-
}
|
156
|
-
response_data.append(response_item)
|
157
|
-
return response_data
|
158
|
-
|
159
|
-
|
160
|
-
class CheckDeletedProducts(CheckProducts):
|
161
|
-
pass
|