Skip to content

Commit

Permalink
Merge pull request #142 from cloudblue/fix-product-clone
Browse files Browse the repository at this point in the history
Fix product clone
  • Loading branch information
Francesco Faraone authored Jun 27, 2022
2 parents 0e17549 + 95316ae commit 00672f0
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 72 deletions.
2 changes: 1 addition & 1 deletion connect/cli/plugins/product/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def clean_wb(self):
for sheetname in get_translation_attributes_sheets(self.wb):
ws = self.wb[sheetname]
value = 'update'
if sheetname.split()[0] == self.wb['General Information']['B14'].value[0:2]:
if sheetname.split()[0] == self.wb['General Information']['B14'].value.split()[0]:
value = '-'
for row in range(2, ws.max_row + 1):
ws[f'C{row}'].value = value
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ def mocked_locales_response():


@pytest.fixture(scope='function')
def mocked_primary_translation_response():
with open('./tests/fixtures/primary_translation_response.json') as response:
def mocked_product_translations_response():
with open('./tests/fixtures/product_translations_response.json') as response:
return json.load(response)


Expand Down
Binary file modified tests/fixtures/comparation_product.xlsx
Binary file not shown.
46 changes: 0 additions & 46 deletions tests/fixtures/primary_translation_response.json

This file was deleted.

90 changes: 90 additions & 0 deletions tests/fixtures/product_translations_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
[
{
"id": "TRN-1079-0833-9890",
"context": {
"id": "LCX-1278-0537-9908",
"instance_id": "PRD-276-377-545",
"name": "My Product",
"icon": "/media/VA-392-495/PRD-276-377-545/media/PRD-276-377-545-logo_aJD74iQ.png",
"type": "product"
},
"owner": {
"id": "VA-392-495",
"name": "Adrian Inc Oct 12"
},
"locale": {
"id": "FA",
"name": "Persian"
},
"stats": {
"total": 30,
"translated": 30
},
"auto": {
"enabled": false,
"status": "off"
},
"status": "inactive",
"events": {
"updated": {
"at": "2020-10-15T01:19:20+00:00",
"by": {
"id": "UR-539-008-555",
"name": "Robert Balboa Oct 12"
}
},
"created": {
"at": "2020-10-14T12:11:24+00:00",
"by": {
"id": "UR-539-008-555",
"name": "Robert Balboa Oct 12"
}
}
},
"primary": true
},
{
"id": "TRN-1079-0833-9891",
"context": {
"id": "LCX-1278-0537-9908",
"instance_id": "PRD-276-377-545",
"name": "My Product",
"icon": "/media/VA-392-495/PRD-276-377-545/media/PRD-276-377-545-logo_aJD74iQ.png",
"type": "product"
},
"owner": {
"id": "VA-392-495",
"name": "Adrian Inc Oct 12"
},
"locale": {
"id": "ES-AR",
"name": "Argentinian Spanish"
},
"stats": {
"total": 30,
"translated": 30
},
"auto": {
"enabled": false,
"status": "off"
},
"status": "inactive",
"events": {
"updated": {
"at": "2020-10-15T01:19:20+00:00",
"by": {
"id": "UR-539-008-555",
"name": "Robert Balboa Oct 12"
}
},
"created": {
"at": "2020-10-14T12:11:24+00:00",
"by": {
"id": "UR-539-008-555",
"name": "Robert Balboa Oct 12"
}
}
},
"primary": false
}
]
22 changes: 22 additions & 0 deletions tests/plugins/product/test_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,28 @@ def test_clean_wb(

for row in range(2, 11):
assert cloned_wb['Capabilities'][f'B{row}'].value == 'update'
for row in range(2, 7):
assert cloned_wb['Embedding Static Resources'][f'C{row}'].value == 'create'
for row in range(2, 5):
assert cloned_wb['Media'][f'C{row}'].value == 'create'
for row in range(2, 8):
assert cloned_wb['Templates'][f'C{row}'].value == 'create'
for row in range(2, 20):
assert cloned_wb['Items'][f'C{row}'].value == 'create'
for row in range(2, 14):
assert cloned_wb['Ordering Parameters'][f'C{row}'].value == 'create'
for row in range(2, 4):
assert cloned_wb['Fulfillment Parameters'][f'C{row}'].value == 'create'
for row in range(2, 3):
assert cloned_wb['Configuration Parameters'][f'C{row}'].value == 'create'
for row in range(2, 4):
assert cloned_wb['Actions'][f'C{row}'].value == 'create'
for row in range(2, 4):
assert cloned_wb['Translations'][f'B{row}'].value == 'create'
for row in range(2, 32):
assert cloned_wb['FA (TRN-1079-0833-9890)'][f'C{row}'].value == '-'
for row in range(2, 32):
assert cloned_wb['ES-AR (TRN-1079-0833-9891)'][f'C{row}'].value == 'update'


@freeze_time('2022-04-05 20:15:00')
Expand Down
51 changes: 28 additions & 23 deletions tests/plugins/product/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from click import ClickException
from click.testing import CliRunner
from openpyxl import load_workbook
from responses import matchers

from connect.cli.core.config import Config
from connect.cli.plugins.product.export import dump_product
Expand Down Expand Up @@ -168,7 +169,7 @@ def test_export_product(
mocked_actions_response,
mocked_configurations_response,
mocked_locales_response,
mocked_primary_translation_response,
mocked_product_translations_response,
mocked_translation_attributes_xlsx_response,
sample_product_workbook,
):
Expand Down Expand Up @@ -243,14 +244,6 @@ def test_export_product(
r'https:\/\/localhost\/public\/v1\/products\/PRD-276-377-545\/parameters\?eq\(phase,'
r'configuration\)&limit\=(100|[1-9]?[0-9])\&offset\=0',
)
translation_query = re.compile(
r'https:\/\/localhost\/public\/v1\/localization\/translations\?eq\(context.instance_id,'
r'PRD-276-377-545\)&limit\=(100|[1-9]?[0-9])\&offset\=0',
)
translation_query2 = re.compile(
r'https:\/\/localhost\/public\/v1\/localization\/translations\?and\(eq\(context.instance_id,'
r'PRD-276-377-545\),eq\(primary,true\)\)&limit\=(100|[1-9]?[0-9])\&offset\=0',
)
mocked_responses.add(
method='GET',
url=ordering_query,
Expand Down Expand Up @@ -298,34 +291,46 @@ def test_export_product(
)
mocked_responses.add(
method='GET',
url=(
'https://localhost/public/v1/localization/translations?'
'and(eq(context.instance_id,PRD-457-715-047),eq(primary,true))&limit=100&offset=0'
),
json=mocked_primary_translation_response,
url='https://localhost/public/v1/localization/translations',
match=[
matchers.query_string_matcher(
'and(eq(context.instance_id,PRD-276-377-545),eq(primary,true))&limit=1&offset=0',
),
],
json=mocked_product_translations_response[0:1],
)
mocked_responses.add(
method='GET',
url=translation_query,
json=mocked_primary_translation_response,
url='https://localhost/public/v1/localization/translations',
match=[
matchers.query_string_matcher(
'eq(context.instance_id,PRD-276-377-545)&limit=0&offset=0',
),
],
json=mocked_product_translations_response,
headers={
'Content-Range': 'items 0-0/1',
'Content-Range': 'items 0-1/1',
},
)
mocked_responses.add(
method='GET',
url=translation_query2,
json=mocked_primary_translation_response,
url='https://localhost/public/v1/localization/translations',
match=[
matchers.query_string_matcher(
'eq(context.instance_id,PRD-276-377-545)&limit=100&offset=0',
),
],
json=mocked_product_translations_response,
headers={
'Content-Range': 'items 0-0/1',
'Content-Range': 'items 0-1/1',
},
)
mocked_responses.add(
method='GET',
url='https://localhost/public/v1/localization/translations/TRN-1079-0833-9890/attributes',
body=mocked_translation_attributes_xlsx_response,
url=re.compile('https://localhost/public/v1/localization/translations/TRN-1079-0833-989(0|1)/attributes'),
body=mocked_translation_attributes_xlsx_response.read(),
headers={
'Contet-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
},
)
output_file = dump_product(
Expand Down

0 comments on commit 00672f0

Please sign in to comment.