Skip to content

Commit 8db9969

Browse files
author
Francesco Faraone
authored
Merge pull request #143 from cloudblue/hotfix/fix-product-clone
[HF] LITE-24191: Fix product clone
2 parents 988b290 + 7018c2e commit 8db9969

File tree

7 files changed

+143
-72
lines changed

7 files changed

+143
-72
lines changed

connect/cli/plugins/product/clone.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def clean_wb(self):
245245
for sheetname in get_translation_attributes_sheets(self.wb):
246246
ws = self.wb[sheetname]
247247
value = 'update'
248-
if sheetname.split()[0] == self.wb['General Information']['B14'].value[0:2]:
248+
if sheetname.split()[0] == self.wb['General Information']['B14'].value.split()[0]:
249249
value = '-'
250250
for row in range(2, ws.max_row + 1):
251251
ws[f'C{row}'].value = value

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ def mocked_locales_response():
136136

137137

138138
@pytest.fixture(scope='function')
139-
def mocked_primary_translation_response():
140-
with open('./tests/fixtures/primary_translation_response.json') as response:
139+
def mocked_product_translations_response():
140+
with open('./tests/fixtures/product_translations_response.json') as response:
141141
return json.load(response)
142142

143143

1.93 KB
Binary file not shown.

tests/fixtures/primary_translation_response.json

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
[
2+
{
3+
"id": "TRN-1079-0833-9890",
4+
"context": {
5+
"id": "LCX-1278-0537-9908",
6+
"instance_id": "PRD-276-377-545",
7+
"name": "My Product",
8+
"icon": "/media/VA-392-495/PRD-276-377-545/media/PRD-276-377-545-logo_aJD74iQ.png",
9+
"type": "product"
10+
},
11+
"owner": {
12+
"id": "VA-392-495",
13+
"name": "Adrian Inc Oct 12"
14+
},
15+
"locale": {
16+
"id": "FA",
17+
"name": "Persian"
18+
},
19+
"stats": {
20+
"total": 30,
21+
"translated": 30
22+
},
23+
"auto": {
24+
"enabled": false,
25+
"status": "off"
26+
},
27+
"status": "inactive",
28+
"events": {
29+
"updated": {
30+
"at": "2020-10-15T01:19:20+00:00",
31+
"by": {
32+
"id": "UR-539-008-555",
33+
"name": "Robert Balboa Oct 12"
34+
}
35+
},
36+
"created": {
37+
"at": "2020-10-14T12:11:24+00:00",
38+
"by": {
39+
"id": "UR-539-008-555",
40+
"name": "Robert Balboa Oct 12"
41+
}
42+
}
43+
},
44+
"primary": true
45+
},
46+
{
47+
"id": "TRN-1079-0833-9891",
48+
"context": {
49+
"id": "LCX-1278-0537-9908",
50+
"instance_id": "PRD-276-377-545",
51+
"name": "My Product",
52+
"icon": "/media/VA-392-495/PRD-276-377-545/media/PRD-276-377-545-logo_aJD74iQ.png",
53+
"type": "product"
54+
},
55+
"owner": {
56+
"id": "VA-392-495",
57+
"name": "Adrian Inc Oct 12"
58+
},
59+
"locale": {
60+
"id": "ES-AR",
61+
"name": "Argentinian Spanish"
62+
},
63+
"stats": {
64+
"total": 30,
65+
"translated": 30
66+
},
67+
"auto": {
68+
"enabled": false,
69+
"status": "off"
70+
},
71+
"status": "inactive",
72+
"events": {
73+
"updated": {
74+
"at": "2020-10-15T01:19:20+00:00",
75+
"by": {
76+
"id": "UR-539-008-555",
77+
"name": "Robert Balboa Oct 12"
78+
}
79+
},
80+
"created": {
81+
"at": "2020-10-14T12:11:24+00:00",
82+
"by": {
83+
"id": "UR-539-008-555",
84+
"name": "Robert Balboa Oct 12"
85+
}
86+
}
87+
},
88+
"primary": false
89+
}
90+
]

tests/plugins/product/test_clone.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,28 @@ def test_clean_wb(
7575

7676
for row in range(2, 11):
7777
assert cloned_wb['Capabilities'][f'B{row}'].value == 'update'
78+
for row in range(2, 7):
79+
assert cloned_wb['Embedding Static Resources'][f'C{row}'].value == 'create'
80+
for row in range(2, 5):
81+
assert cloned_wb['Media'][f'C{row}'].value == 'create'
82+
for row in range(2, 8):
83+
assert cloned_wb['Templates'][f'C{row}'].value == 'create'
84+
for row in range(2, 20):
85+
assert cloned_wb['Items'][f'C{row}'].value == 'create'
86+
for row in range(2, 14):
87+
assert cloned_wb['Ordering Parameters'][f'C{row}'].value == 'create'
88+
for row in range(2, 4):
89+
assert cloned_wb['Fulfillment Parameters'][f'C{row}'].value == 'create'
90+
for row in range(2, 3):
91+
assert cloned_wb['Configuration Parameters'][f'C{row}'].value == 'create'
92+
for row in range(2, 4):
93+
assert cloned_wb['Actions'][f'C{row}'].value == 'create'
94+
for row in range(2, 4):
95+
assert cloned_wb['Translations'][f'B{row}'].value == 'create'
96+
for row in range(2, 32):
97+
assert cloned_wb['FA (TRN-1079-0833-9890)'][f'C{row}'].value == '-'
98+
for row in range(2, 32):
99+
assert cloned_wb['ES-AR (TRN-1079-0833-9891)'][f'C{row}'].value == 'update'
78100

79101

80102
@freeze_time('2022-04-05 20:15:00')

tests/plugins/product/test_commands.py

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from click import ClickException
88
from click.testing import CliRunner
99
from openpyxl import load_workbook
10+
from responses import matchers
1011

1112
from connect.cli.core.config import Config
1213
from connect.cli.plugins.product.export import dump_product
@@ -168,7 +169,7 @@ def test_export_product(
168169
mocked_actions_response,
169170
mocked_configurations_response,
170171
mocked_locales_response,
171-
mocked_primary_translation_response,
172+
mocked_product_translations_response,
172173
mocked_translation_attributes_xlsx_response,
173174
sample_product_workbook,
174175
):
@@ -243,14 +244,6 @@ def test_export_product(
243244
r'https:\/\/localhost\/public\/v1\/products\/PRD-276-377-545\/parameters\?eq\(phase,'
244245
r'configuration\)&limit\=(100|[1-9]?[0-9])\&offset\=0',
245246
)
246-
translation_query = re.compile(
247-
r'https:\/\/localhost\/public\/v1\/localization\/translations\?eq\(context.instance_id,'
248-
r'PRD-276-377-545\)&limit\=(100|[1-9]?[0-9])\&offset\=0',
249-
)
250-
translation_query2 = re.compile(
251-
r'https:\/\/localhost\/public\/v1\/localization\/translations\?and\(eq\(context.instance_id,'
252-
r'PRD-276-377-545\),eq\(primary,true\)\)&limit\=(100|[1-9]?[0-9])\&offset\=0',
253-
)
254247
mocked_responses.add(
255248
method='GET',
256249
url=ordering_query,
@@ -298,34 +291,46 @@ def test_export_product(
298291
)
299292
mocked_responses.add(
300293
method='GET',
301-
url=(
302-
'https://localhost/public/v1/localization/translations?'
303-
'and(eq(context.instance_id,PRD-457-715-047),eq(primary,true))&limit=100&offset=0'
304-
),
305-
json=mocked_primary_translation_response,
294+
url='https://localhost/public/v1/localization/translations',
295+
match=[
296+
matchers.query_string_matcher(
297+
'and(eq(context.instance_id,PRD-276-377-545),eq(primary,true))&limit=1&offset=0',
298+
),
299+
],
300+
json=mocked_product_translations_response[0:1],
306301
)
307302
mocked_responses.add(
308303
method='GET',
309-
url=translation_query,
310-
json=mocked_primary_translation_response,
304+
url='https://localhost/public/v1/localization/translations',
305+
match=[
306+
matchers.query_string_matcher(
307+
'eq(context.instance_id,PRD-276-377-545)&limit=0&offset=0',
308+
),
309+
],
310+
json=mocked_product_translations_response,
311311
headers={
312-
'Content-Range': 'items 0-0/1',
312+
'Content-Range': 'items 0-1/1',
313313
},
314314
)
315315
mocked_responses.add(
316316
method='GET',
317-
url=translation_query2,
318-
json=mocked_primary_translation_response,
317+
url='https://localhost/public/v1/localization/translations',
318+
match=[
319+
matchers.query_string_matcher(
320+
'eq(context.instance_id,PRD-276-377-545)&limit=100&offset=0',
321+
),
322+
],
323+
json=mocked_product_translations_response,
319324
headers={
320-
'Content-Range': 'items 0-0/1',
325+
'Content-Range': 'items 0-1/1',
321326
},
322327
)
323328
mocked_responses.add(
324329
method='GET',
325-
url='https://localhost/public/v1/localization/translations/TRN-1079-0833-9890/attributes',
326-
body=mocked_translation_attributes_xlsx_response,
330+
url=re.compile('https://localhost/public/v1/localization/translations/TRN-1079-0833-989(0|1)/attributes'),
331+
body=mocked_translation_attributes_xlsx_response.read(),
327332
headers={
328-
'Contet-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
333+
'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
329334
},
330335
)
331336
output_file = dump_product(

0 commit comments

Comments
 (0)