def test_clean_wb( config_mocker, fs, ): config = Config() config.load('/tmp') stats = SynchronizerStats() cloner = ProductCloner( config=config, source_account='VA-000', destination_account='VA-000', product_id='PRD-123', stats=stats, ) os.mkdir( os.path.join( cloner.fs.root_path, 'PRD-123', ), ) wb = load_workbook('./tests/fixtures/comparation_product.xlsx') wb.save( os.path.join( cloner.fs.root_path, 'PRD-123', 'PRD-123.xlsx', ), ) cloner.load_wb() cloner.clean_wb() cloned_wb = load_workbook( os.path.join( cloner.fs.root_path, 'PRD-123', 'PRD-123.xlsx', ), ) for row in range(2, 11): assert cloned_wb['Capabilities'][f'B{row}'].value == 'update'
def cmd_clone_products(config, source_product_id, source_account, destination_account, name, yes): if name and len(name) > 32: click.echo( click.style( f'New product name can not exceed 32 chracters, provided as name{name}', fg='red', ), ) exit(-1) if destination_account: config.activate(destination_account) config.validate() else: destination_account = config.active.id if source_account: config.activate(source_account) config.validate() else: source_account = config.active.id config.validate() acc_id = config.active.id acc_name = config.active.name if not config.silent: click.echo( click.style( f'Current active account: {acc_id} - {acc_name}\n', fg='blue', ), ) client = ConnectClient( api_key=config.active.api_key, endpoint=config.active.endpoint, use_specs=False, max_retries=3, ) if not yes: click.confirm( 'Are you sure you want to Clone ' f'the product {source_product_id} ?', abort=True, ) click.echo('') try: client.products[source_product_id].get() except ClientError: click.echo( click.style( f'Product {source_product_id} does not exist', fg='red', ), ) exit(-1) synchronizer = ProductCloner( config=config, source_account=source_account, destination_account=destination_account, product_id=source_product_id, ) if not config.silent: click.echo( click.style( f'Dumping Product {synchronizer.product_id} from account ' f'{synchronizer.source_account}\n', fg='blue', ), ) synchronizer.dump() synchronizer.load_wb() if not config.silent: click.echo( click.style( f'Creating new Product on account {synchronizer.destination_account}', fg='blue', ), ) synchronizer.create_product(name=name) synchronizer.clean_wb() if not config.silent: click.echo(click.style( 'Injecting Product information', fg='blue', ), ) synchronizer.inject() if not config.silent: click.echo( click.style( f'Finished cloning product {source_product_id} from account ' f'{synchronizer.source_account} to {synchronizer.destination_account}\n', fg='green', ), ) click.echo( click.style( f'New product id {synchronizer.destination_product}', fg='green', ), )
def cmd_clone_products(config, source_product_id, source_account, destination_account, name, yes): if not config.active.is_vendor(): raise ClickException( 'The clone command is only available for vendor accounts.', ) if name and len(name) > 32: click.secho( f'New product name can not exceed 32 chracters, provided as name {name}', fg='red', ) exit(-1) if destination_account: config.activate(destination_account) else: destination_account = config.active.id if source_account: config.activate(source_account) else: source_account = config.active.id 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', ) 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, ) if not yes: click.confirm( 'Are you sure you want to Clone ' f'the product {source_product_id} ?', abort=True, ) click.echo('') try: client.products[source_product_id].get() except ClientError: click.secho( f'Product {source_product_id} does not exist', fg='red', ) exit(-1) stats = SynchronizerStats(operation='Clone') stats.RESULTS_HEADER = stats.RESULTS_HEADER.replace( "synchronization", f"cloning {source_product_id}", ) synchronizer = ProductCloner( config=config, source_account=source_account, destination_account=destination_account, product_id=source_product_id, stats=stats, ) if not config.silent: click.secho( f'Dumping Product {synchronizer.product_id} from account ' f'{synchronizer.source_account}\n', fg='blue', ) synchronizer.dump() synchronizer.load_wb() if not config.silent: click.secho( f'Creating new Product on account {synchronizer.destination_account}', fg='blue', ) synchronizer.create_product(name=name) synchronizer.clean_wb() if not config.silent: click.secho( 'Injecting Product information', fg='blue', ) synchronizer.inject() if not config.silent: click.secho( f'Finished cloning product {source_product_id} from account ' f'{synchronizer.source_account} to {synchronizer.destination_account}\n', fg='green', ) click.secho( f'New product id {synchronizer.destination_product}', fg='green', ) stats.print()