diff --git a/connect/cli/plugins/product/clone.py b/connect/cli/plugins/product/clone.py index 139da3fc..3153772d 100644 --- a/connect/cli/plugins/product/clone.py +++ b/connect/cli/plugins/product/clone.py @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py index 6f7020fd..5ea97c87 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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) diff --git a/tests/fixtures/comparation_product.xlsx b/tests/fixtures/comparation_product.xlsx index 9e528a55..2372e591 100644 Binary files a/tests/fixtures/comparation_product.xlsx and b/tests/fixtures/comparation_product.xlsx differ diff --git a/tests/fixtures/primary_translation_response.json b/tests/fixtures/primary_translation_response.json deleted file mode 100644 index 94ecb4be..00000000 --- a/tests/fixtures/primary_translation_response.json +++ /dev/null @@ -1,46 +0,0 @@ -[ - { - "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 - } -] \ No newline at end of file diff --git a/tests/fixtures/product_translations_response.json b/tests/fixtures/product_translations_response.json new file mode 100644 index 00000000..f757e45e --- /dev/null +++ b/tests/fixtures/product_translations_response.json @@ -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 + } +] \ No newline at end of file diff --git a/tests/plugins/product/test_clone.py b/tests/plugins/product/test_clone.py index bc9a4f5c..2e84cdba 100644 --- a/tests/plugins/product/test_clone.py +++ b/tests/plugins/product/test_clone.py @@ -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') diff --git a/tests/plugins/product/test_commands.py b/tests/plugins/product/test_commands.py index 654253f5..51c52249 100644 --- a/tests/plugins/product/test_commands.py +++ b/tests/plugins/product/test_commands.py @@ -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 @@ -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, ): @@ -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, @@ -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(