def test_update_fail(fs, mocked_responses, sample_translation_workbook): sample_translation_workbook['Attributes']['C2'].value = 'update' sample_translation_workbook['Attributes']['C5'].value = 'update' sample_translation_workbook['Attributes']['C8'].value = 'update' sample_translation_workbook['Attributes']['C10'].value = 'update' sample_translation_workbook['Attributes']['C18'].value = 'update' sample_translation_workbook.save(f'{fs.root_path}/test.xlsx') mocked_responses.add( method='PUT', url= 'https://localhost/public/v1/localization/translations/TRN-8100-3865-4869/attributes', status=500, ) client = get_client() synchronizer = TranslationAttributesSynchronizer(client=client, silent=True) synchronizer.open(f'{fs.root_path}/test.xlsx', 'Attributes') synchronizer.sync(translation='TRN-8100-3865-4869') assert synchronizer._mstats.get_counts_as_dict() == { 'processed': 30, 'created': 0, 'updated': 0, 'deleted': 0, 'skipped': 25, 'errors': 5, } assert len(synchronizer._mstats._row_errors) == 5
def test_update_for_clone_ok( fs, mocked_responses, mocked_translation_response, mocked_translation_attributes_response, sample_translation_workbook, ): sample_translation_workbook['Attributes']['C2'].value = 'update' sample_translation_workbook['Attributes']['C5'].value = 'update' sample_translation_workbook['Attributes']['C8'].value = 'update' sample_translation_workbook['Attributes']['C10'].value = 'update' sample_translation_workbook['Attributes']['C18'].value = 'update' sample_translation_workbook['Attributes'][ 'D2'].value = 'test value that differs from source' sample_translation_workbook.save(f'{fs.root_path}/test.xlsx') mocked_responses.add( method='GET', url= 'https://localhost/public/v1/localization/translations/TRN-8100-3865-4869/attributes', status=200, json=mocked_translation_attributes_response, ) mocked_responses.add( method='PUT', url= 'https://localhost/public/v1/localization/translations/TRN-8100-3865-4869/attributes', status=200, ) client = get_client() synchronizer = TranslationAttributesSynchronizer( client=client, silent=True, ) synchronizer.open(f'{fs.root_path}/test.xlsx', 'Attributes') synchronizer.sync(translation=mocked_translation_response, is_clone=True) assert synchronizer._mstats.get_counts_as_dict() == { 'processed': 30, 'created': 0, 'updated': 5, 'deleted': 0, 'skipped': 25, 'errors': 0, }
def test_nothing_to_update(fs, sample_translation_workbook): sample_translation_workbook.save(f'{fs.root_path}/test.xlsx') client = get_client() synchronizer = TranslationAttributesSynchronizer(client=client, silent=True) synchronizer.open(f'{fs.root_path}/test.xlsx', 'Attributes') synchronizer.sync(translation='TRN-8100-3865-4869') assert synchronizer._mstats.get_counts_as_dict() == { 'processed': 30, 'created': 0, 'updated': 0, 'deleted': 0, 'skipped': 30, 'errors': 0, }
def cmd_sync_translation(config, input_file, yes): acc_id = config.active.id acc_name = config.active.name if not config.silent: click.secho(f'Current active account: {acc_id} - {acc_name}\n', fg='blue') if '.xlsx' not in input_file: input_file = f'{input_file}/{input_file}.xlsx' client = ConnectClient( api_key=config.active.api_key, endpoint=config.active.endpoint, use_specs=False, max_retries=3, logger=RequestLogger() if config.verbose else None, ) stats = SynchronizerStats() translation_sync = TranslationSynchronizer(client, config.silent, acc_id, stats) translation_sync.open(input_file) translation_id, should_wait_for_autotranslation = translation_sync.sync( yes) translation_sync.save(input_file) if translation_id: if should_wait_for_autotranslation: wait_for_autotranslation(client, translation_id, silent=config.silent) attributes_sync = TranslationAttributesSynchronizer( client, config.silent, stats) attributes_sync.open(input_file, 'Attributes') attributes_sync.sync(translation_id) attributes_sync.save(input_file) if not config.silent: stats.print()
def translation_attributes_sync(worksheet, translation, client, config, input_file, stats, save, is_clone): synchronizer = TranslationAttributesSynchronizer(client, config.silent, stats) synchronizer.open(input_file, worksheet) synchronizer.sync(translation, is_clone) if save: synchronizer.save(input_file)