Esempio n. 1
0
def dump_customers(api_url, api_key, account_id, output_file, silent, output_path=None):  # noqa: CCR001
    if not output_path:
        output_path = os.path.join(os.getcwd(), account_id)
    else:
        if not os.path.exists(output_path):
            raise ClickException(
                "Output Path does not exist",
            )
        output_path = os.path.join(output_path, account_id)

    if not output_file:
        output_file = os.path.join(output_path, 'customers.xlsx')
    else:
        output_file = os.path.join(output_path, output_file)

    if not os.path.exists(output_path):
        os.mkdir(output_path)
    elif not os.path.isdir(output_path):
        raise ClickException(
            "Exists a file with account id as name but a directory is expected, please rename it",
        )
    try:
        client = ConnectClient(
            max_retries=3,
            api_key=api_key,
            endpoint=api_url,
            use_specs=False,
            default_limit=1000,
        )
        wb = Workbook()
        _prepare_worksheet(wb.create_sheet('Customers'))
        _add_countries(wb.create_sheet('Countries'))

        customers = client.ns('tier').accounts.all()
        row_idx = 2
        count = customers.count()
        progress = trange(0, count, disable=silent, leave=True, bar_format=DEFAULT_BAR_FORMAT)
        for customer in customers:
            progress.set_description(f'Processing customer {customer["id"]}')
            progress.update(1)
            _fill_customer_row(wb['Customers'], row_idx, customer)
            row_idx += 1
    except ClientError as error:
        handle_http_error(error)

    default_sheet = wb['Sheet']
    wb.remove(default_sheet)
    wb.save(output_file)

    return output_file
Esempio n. 2
0
def test_skip_create_if_action_id_exists_but_update_if_differs_from_source(
    fs,
    get_sync_actions_env,
    mocked_responses,
    mocked_actions_response,
):
    get_sync_actions_env['Actions']['A2'] = None
    get_sync_actions_env['Actions']['C2'] = 'create'
    get_sync_actions_env['Actions']['F2'] = 'New Test Description'

    get_sync_actions_env.save(f'{fs.root_path}/test.xlsx')

    response = mocked_actions_response[0]

    stats = SynchronizerStats()
    synchronizer = ActionsSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
        stats=stats,
    )

    mocked_responses.add(
        method='GET',
        url='https://localhost/public/v1/products/PRD-276-377-545/actions',
        headers={
            'Content-Range': 'items 0-3/4',
        },
        json=mocked_actions_response,
    )
    mocked_responses.add(
        method='PUT',
        url=
        'https://localhost/public/v1/products/PRD-276-377-545/actions/ACT-276-377-545-001',
        json=response,
    )
    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Actions')
    synchronizer.sync()

    assert stats['Actions'].get_counts_as_dict() == {
        'processed': 1,
        'created': 0,
        'updated': 1,
        'deleted': 0,
        'skipped': 0,
        'errors': 0,
    }
Esempio n. 3
0
def test_create_item_custom_uom(
    fs,
    get_sync_items_env,
    mocked_responses,
    mocked_items_response,
):
    get_sync_items_env['Items']['A2'].value = None
    get_sync_items_env['Items']['C2'].value = 'create'
    get_sync_items_env['Items']['H2'].value = 'unitary tests'

    get_sync_items_env.save(f'{fs.root_path}/test.xlsx')
    mocked_responses.add(
        method='GET',
        url='https://localhost/public/v1/products/PRD-276-377-545/items?eq(mpn,'
            'MPN-R-001)&limit=1&offset=0',
        json=[],
    )

    mocked_responses.add(
        method='POST',
        url='https://localhost/public/v1/products/PRD-276-377-545/items',
        json=mocked_items_response[0],
    )

    mocked_responses.add(
        method='POST',
        url='https://localhost/public/v1/settings/units',
        json={
            'id': '123',
        },
    )

    stats = SynchronizerStats()
    synchronizer = ItemSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
        stats=stats,
    )

    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Items')
    synchronizer.sync()

    assert stats['Items'].get_counts_as_dict() == {
        'processed': 1, 'created': 1, 'updated': 0,
        'deleted': 0, 'skipped': 0, 'errors': 0,
    }
Esempio n. 4
0
def test_init(get_sync_items_env):

    synchronizer = ItemSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
    )

    product_id = synchronizer.open('./tests/fixtures/items_sync.xlsx', 'Items')

    assert product_id == 'PRD-276-377-545'
Esempio n. 5
0
def test_invalid_zip_open(fs, mocked_responses, mocked_product_response):
    synchronizer = ProductSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
    )

    with pytest.raises(ClickException) as e:
        synchronizer.open('./tests/fixtures/configurations_response.json',
                          'Items')

    assert 'openpyxl does not support .json' in str(e.value)
Esempio n. 6
0
def test_open(fs, get_general_env):
    get_general_env.save(f'{fs.root_path}/test.xlsx')
    synchronizer = GeneralSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
    )
    product_id = synchronizer.open(
        f'{fs.root_path}/test.xlsx', 'General Information',
    )

    assert product_id == 'PRD-276-377-545'
Esempio n. 7
0
def dump_customers(api_url,
                   api_key,
                   account_id,
                   output_file,
                   silent,
                   verbose=False,
                   output_path=None):  # noqa: CCR001
    output_file = validate_output_options(
        output_path,
        output_file,
        default_dir_name=account_id,
        default_file_name='customers',
    )
    try:
        client = ConnectClient(
            max_retries=3,
            api_key=api_key,
            endpoint=api_url,
            use_specs=False,
            default_limit=1000,
            logger=RequestLogger() if verbose else None,
        )
        wb = Workbook()
        _prepare_worksheet(wb.create_sheet('Customers'))
        _add_countries(wb.create_sheet('Countries'))

        customers = client.ns('tier').accounts.all()
        row_idx = 2
        count = customers.count()
        progress = trange(0,
                          count,
                          disable=silent,
                          leave=True,
                          bar_format=DEFAULT_BAR_FORMAT)
        for customer in customers:
            progress.set_description(f'Processing customer {customer["id"]}')
            progress.update(1)
            _fill_customer_row(wb['Customers'], row_idx, customer)
            row_idx += 1
    except ClientError as error:
        handle_http_error(error)

    default_sheet = wb['Sheet']
    wb.remove(default_sheet)
    wb.save(output_file)

    return output_file
Esempio n. 8
0
def test_update_item_draft_connect_exception(
    fs,
    get_sync_items_env,
    mocked_responses,
    mocked_items_response,
):
    get_sync_items_env['Items']['A2'].value = None
    get_sync_items_env['Items']['C2'].value = 'update'

    item = mocked_items_response[0]
    item['status'] = 'draft'

    get_sync_items_env.save(f'{fs.root_path}/test.xlsx')
    mocked_responses.add(
        method='GET',
        url='https://localhost/public/v1/products/PRD-276-377-545/items?eq(mpn,'
            'MPN-R-001)&limit=1&offset=0',
        json=[item],
    )

    mocked_responses.add(
        method='PUT',
        url='https://localhost/public/v1/products/PRD-276-377-545/items/PRD-276-377-545-0001',
        status=500,
    )

    stats = SynchronizerStats()
    synchronizer = ItemSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
        stats=stats,
    )

    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Items')
    synchronizer.sync()

    assert stats['Items'].get_counts_as_dict() == {
        'processed': 1, 'created': 0, 'updated': 0,
        'deleted': 0, 'skipped': 0, 'errors': 1,
    }
    assert stats['Items']._row_errors == {
        2: ['500 - Internal Server Error: unexpected error.'],
    }
Esempio n. 9
0
def test_validate_update(
    fs,
    get_sync_params_env,
    mocked_responses,
    mocked_ordering_params_response,
):
    get_sync_params_env['Ordering Parameters']['C2'] = 'update'

    response = mocked_ordering_params_response[0]

    get_sync_params_env.save(f'{fs.root_path}/test.xlsx')

    stats = SynchronizerStats()
    synchronizer = ParamsSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
        stats=stats,
    )

    mocked_responses.add(
        method='GET',
        url='https://localhost/public/v1/products/PRD-276-377-545/parameters',
        json=mocked_ordering_params_response,
    )

    mocked_responses.add(
        method='PUT',
        url=
        'https://localhost/public/v1/products/PRD-276-377-545/parameters/PRM-276-377-545-0008',
        json=response,
    )

    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Ordering Parameters')
    synchronizer.sync()

    assert stats['Ordering Parameters'].get_counts_as_dict() == {
        'processed': 1,
        'created': 0,
        'updated': 1,
        'deleted': 0,
        'skipped': 0,
        'errors': 0,
    }
Esempio n. 10
0
def test_validate_invalid_prod_category(fs, get_general_env):
    get_general_env['General Information']['B8'] = 'invalid'
    get_general_env.save(f'{fs.root_path}/test.xlsx')
    synchronizer = GeneralSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
    )

    with pytest.raises(ClickException) as e:
        synchronizer.open(
            f'{fs.root_path}/test.xlsx', 'General Information',
        )
    assert str(e.value) == f'{GENERAL_ERROR} Product category invalid is a not known category'
Esempio n. 11
0
def test_update_template_exception(
    fs,
    get_sync_templates_env,
    mocked_templates_response,
    mocked_responses,
):
    get_sync_templates_env['Templates']['C2'] = 'update'
    get_sync_templates_env.save(f'{fs.root_path}/test.xlsx')

    stats = SynchronizerStats()
    synchronizer = TemplatesSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
        stats=stats,
    )

    mocked_responses.add(
        method='GET',
        url=
        'https://localhost/public/v1/products/PRD-276-377-545/templates/TL-551-876-782',
        json=mocked_templates_response[0],
    )

    mocked_responses.add(
        method='PUT',
        url=
        'https://localhost/public/v1/products/PRD-276-377-545/templates/TL-551-876-782',
        status=500,
    )

    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Templates')
    synchronizer.sync()

    assert stats['Templates'].get_counts_as_dict() == {
        'processed': 1,
        'created': 0,
        'updated': 0,
        'deleted': 0,
        'skipped': 0,
        'errors': 1,
    }
    assert stats['Templates']._row_errors == {2: ['500 Internal Server Error']}
Esempio n. 12
0
def test_update_item_draft_ppu(
    fs,
    get_sync_items_env,
    mocked_responses,
    mocked_items_response,
):
    get_sync_items_env['Items']['A2'].value = None
    get_sync_items_env['Items']['C2'].value = 'update'
    get_sync_items_env['Items']['F2'].value = 'ppu'

    item = mocked_items_response[0]
    item['status'] = 'draft'
    item['type'] = 'ppu'

    get_sync_items_env.save(f'{fs.root_path}/test.xlsx')
    mocked_responses.add(
        method='GET',
        url='https://localhost/public/v1/products/PRD-276-377-545/items?eq(mpn,'
        'MPN-R-001)&limit=100&offset=0',
        json=[item],
    )

    mocked_responses.add(
        method='PUT',
        url=
        'https://localhost/public/v1/products/PRD-276-377-545/items/PRD-276-377-545-0001',
        json=mocked_items_response[0],
    )

    synchronizer = ItemSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
    )

    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Items')

    skipped, created, updated, deleted, errors = synchronizer.sync()

    assert skipped == 0
    assert created == 0
    assert updated == 1
    assert errors == {}
Esempio n. 13
0
def test_validate_embedding_long_description(fs, get_general_env):
    get_general_env['General Information']['A13'] = 'invalid'
    get_general_env.save(f'{fs.root_path}/test.xlsx')
    synchronizer = GeneralSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
    )

    with pytest.raises(ClickException) as e:
        synchronizer.open(
            f'{fs.root_path}/test.xlsx', 'General Information',
        )
    assert str(e.value) == f'{GENERAL_ERROR} Embedding getting started is required'
def test_no_action(get_sync_capabilities_env):
    synchronizer = CapabilitiesSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
    )

    synchronizer.open('./tests/fixtures/capabilities_sync.xlsx',
                      'Capabilities')
    skipped, updated, errors = synchronizer.sync()

    assert skipped == 9
    assert updated == 0
    assert errors == {}
Esempio n. 15
0
def test_invalid_file_open(fs, mocked_responses, mocked_product_response):
    copy2('./tests/fixtures/configurations_response.json',
          f'{fs.root_path}/fake.xlsx')

    synchronizer = ProductSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
    )

    with pytest.raises(ClickException) as e:
        synchronizer.open(f'{fs.root_path}/fake.xlsx', 'Items')

    assert 'is not a valid xlsx file' in str(e.value)
Esempio n. 16
0
def test_update_template_switch_type(
    fs,
    get_sync_templates_env,
    mocked_templates_response,
    mocked_responses,
):
    get_sync_templates_env['Templates']['C2'] = 'update'
    response = mocked_templates_response[0]
    response['type'] = 'tier1'
    get_sync_templates_env.save(f'{fs.root_path}/test.xlsx')

    stats = SynchronizerStats()
    synchronizer = TemplatesSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
        stats=stats,
    )

    mocked_responses.add(
        method='GET',
        url=
        'https://localhost/public/v1/products/PRD-276-377-545/templates/TL-551-876-782',
        json=response,
    )

    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Templates')
    synchronizer.sync()

    assert stats['Templates'].get_counts_as_dict() == {
        'processed': 1,
        'created': 0,
        'updated': 0,
        'deleted': 0,
        'skipped': 0,
        'errors': 1,
    }
    assert stats['Templates']._row_errors == {
        2: [
            'Switching scope or type is not supported. Original scope asset, requested scope '
            'asset. Original type tier1, requested type fulfillment'
        ],
    }
Esempio n. 17
0
def test_create_500(fs, get_sync_actions_env, mocked_responses,
                    mocked_actions_response):
    get_sync_actions_env['Actions']['A2'] = None
    get_sync_actions_env['Actions']['C2'] = 'create'
    get_sync_actions_env['Actions']['B2'] = 'test_id'

    get_sync_actions_env.save(f'{fs.root_path}/test.xlsx')

    stats = SynchronizerStats()
    synchronizer = ActionsSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
        stats=stats,
    )

    mocked_responses.add(
        method='GET',
        url='https://localhost/public/v1/products/PRD-276-377-545/actions',
        headers={
            'Content-Range': 'items 0-3/4',
        },
        json=mocked_actions_response,
    )
    mocked_responses.add(
        method='POST',
        url='https://localhost/public/v1/products/PRD-276-377-545/actions',
        status=500,
    )

    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Actions')
    synchronizer.sync()

    assert stats['Actions'].get_counts_as_dict() == {
        'processed': 1,
        'created': 0,
        'updated': 0,
        'deleted': 0,
        'skipped': 0,
        'errors': 1,
    }
    assert stats['Actions']._row_errors == {2: ['500 Internal Server Error']}
Esempio n. 18
0
def test_ppu_disable_future(
    fs,
    get_sync_capabilities_env_ppu_enabled,
    mocked_responses,
    mocked_product_response,
):
    get_sync_capabilities_env_ppu_enabled['Capabilities'][
        'B4'].value = 'update'
    get_sync_capabilities_env_ppu_enabled['Capabilities'][
        'C4'].value = 'Disabled'
    get_sync_capabilities_env_ppu_enabled.save(f'{fs.root_path}/test.xlsx')

    stats = SynchronizerStats()
    synchronizer = CapabilitiesSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
        stats=stats,
    )

    response = deepcopy(mocked_product_response)
    response['capabilities']['ppu'] = {
        'schema': 'QT',
    }

    mocked_responses.add(
        method='PUT',
        url='https://localhost/public/v1/products/PRD-276-377-545',
        json=response,
    )

    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Capabilities')
    synchronizer.sync()

    assert stats['Capabilities'].get_counts_as_dict() == {
        'processed': 9,
        'created': 0,
        'updated': 1,
        'deleted': 0,
        'skipped': 8,
        'errors': 0,
    }
Esempio n. 19
0
def test_update_template_not_exists(
    fs,
    get_sync_templates_env,
    mocked_templates_response,
    mocked_responses,
):
    get_sync_templates_env['Templates']['C2'] = 'update'

    get_sync_templates_env.save(f'{fs.root_path}/test.xlsx')

    stats = SynchronizerStats()
    synchronizer = TemplatesSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
        stats=stats,
    )

    mocked_responses.add(
        method='GET',
        url=
        'https://localhost/public/v1/products/PRD-276-377-545/templates/TL-551-876-782',
        status=404,
    )

    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Templates')
    synchronizer.sync()

    assert stats['Templates'].get_counts_as_dict() == {
        'processed': 1,
        'created': 0,
        'updated': 0,
        'deleted': 0,
        'skipped': 0,
        'errors': 1,
    }
    assert stats['Templates']._row_errors == {
        2: [
            'Cannot update template TL-551-876-782 since does not exist in the product. Create it '
            'instead'
        ],
    }
Esempio n. 20
0
def test_no_action(get_sync_media_env):
    synchronizer = MediaSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
    )

    synchronizer.open('./tests/fixtures/media_sync.xlsx', 'Media')
    skipped, created, updated, deleted, errors = synchronizer.sync()

    assert skipped == 1
    assert created == 0
    assert updated == 0
    assert deleted == 0
    assert errors == {}
Esempio n. 21
0
    def _create_sync_client(connect_responses):
        response_iterator = iter(connect_responses)

        def _execute_http_call(self, method, url, kwargs):
            mock_kwargs = _mock_kwargs_generator(response_iterator, url)
            with responses.RequestsMock() as rsps:
                rsps.add(
                    method.upper(),
                    url,
                    **mock_kwargs,
                )
                self.response = requests.request(method, url, **kwargs)
                if self.response.status_code >= 400:
                    self.response.raise_for_status()

        client = ConnectClient('Key', use_specs=False)
        client._execute_http_call = MethodType(_execute_http_call, client)
        return client
Esempio n. 22
0
def cmd_list_translations(config, query, page_size, always_continue):
    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,
    )

    default_query = client.ns('localization').translations.all()
    query_translations = default_query.filter(
        query) if query else default_query

    translation_list = [TRANSLATION_TABLE_HEADER]
    count_of_translations = query_translations.count()

    for paging, resource in enumerate(query_translations, 1):
        owner = field_to_check_mark(acc_id == resource["owner"]["id"])
        primary = field_to_check_mark(resource["primary"])
        row = row_format_resource(
            resource["id"],
            resource["context"]["instance_id"],
            resource["context"]["type"],
            resource["context"]["name"],
            resource["locale"]["name"],
            resource["auto"]["status"],
            resource["status"],
            primary,
            owner,
        )
        translation_list.append(row)
        table_formater_resource(translation_list, count_of_translations,
                                paging, page_size)
        if paging % page_size == 0 and paging != count_of_translations and not always_continue:
            if not continue_or_quit():
                return
Esempio n. 23
0
def test_validate_invalid_icon_file(fs, get_general_env):
    get_general_env['General Information']['B9'] = 'invalid.png'
    get_general_env.save(f'{fs.root_path}/test.xlsx')
    synchronizer = GeneralSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
    )

    with pytest.raises(ClickException) as e:
        synchronizer.open(
            f'{fs.root_path}/test.xlsx', 'General Information',
        )
    assert str(e.value) == (
        f'{GENERAL_ERROR} File invalid.png does not exist in the media folder'
    )
Esempio n. 24
0
def test_validate_invalid_icon(fs, get_general_env):
    get_general_env['General Information']['A9'] = 'invalid'
    get_general_env.save(f'{fs.root_path}/test.xlsx')
    synchronizer = GeneralSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
    )

    with pytest.raises(ClickException) as e:
        synchronizer.open(
            f'{fs.root_path}/test.xlsx', 'General Information',
        )
    assert str(e.value) == (
        f'{GENERAL_ERROR} A9 must be `Product Icon file name` and B9 contain the value'
    )
Esempio n. 25
0
def test_delete_item_connect_error(
    fs,
    get_sync_items_env,
    mocked_responses,
    mocked_items_response,
):
    get_sync_items_env['Items']['A2'].value = None
    get_sync_items_env['Items']['C2'].value = 'delete'
    get_sync_items_env['Items']['k2'].value = 'draft'

    get_sync_items_env.save(f'{fs.root_path}/test.xlsx')
    mocked_responses.add(
        method='GET',
        url='https://localhost/public/v1/products/PRD-276-377-545/items?eq(mpn,'
        'MPN-R-001)&limit=100&offset=0',
        json=[mocked_items_response[0]],
    )

    mocked_responses.add(
        method='DELETE',
        url=
        'https://localhost/public/v1/products/PRD-276-377-545/items/PRD-276-377-545-0001',
        status=500,
    )

    synchronizer = ItemSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
    )

    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Items')

    skipped, created, updated, deleted, errors = synchronizer.sync()

    assert skipped == 0
    assert created == 0
    assert updated == 0
    assert deleted == 0
    assert errors == {2: ['500 - Internal Server Error: unexpected error.']}
Esempio n. 26
0
def test_validate_update(
    fs,
    get_sync_params_env,
    mocked_responses,
    mocked_ordering_params_response,
):
    get_sync_params_env['Ordering Parameters']['C2'] = 'update'

    response = mocked_ordering_params_response[0]

    get_sync_params_env.save(f'{fs.root_path}/test.xlsx')

    synchronizer = ParamsSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
    )

    mocked_responses.add(
        method='GET',
        url='https://localhost/public/v1/products/PRD-276-377-545/parameters/PRM-276-377-545-0008',
        json=response,
    )

    mocked_responses.add(
        method='PUT',
        url='https://localhost/public/v1/products/PRD-276-377-545/parameters/PRM-276-377-545-0008',
        json=response,
    )

    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Ordering Parameters')

    skipped, created, updated, deleted, errors = synchronizer.sync()

    assert skipped == 0
    assert created == 0
    assert updated == 1
    assert deleted == 0
    assert errors == {}
Esempio n. 27
0
def test_hub_list(mocked_responses):
    param = {
        "id": "mkp",
        "type": "marketplace",
        "name": "Marketplaces",
        "description": "Select the marketplaces you want to include in report",
    }

    config = Config()
    config.load('/tmp')
    config.add_account('VA-000', 'Account 0', 'Api 0',
                       'https://localhost/public/v1')

    client = ConnectClient(
        api_key='ApiKey X',
        endpoint='https://localhost/public/v1',
        use_specs=False,
    )

    mocked_responses.add(
        url='https://localhost/public/v1/marketplaces',
        method='GET',
        json=[
            {
                "id": "MKP-1",
                "name": "Marketplace",
                "hubs": [
                    {
                        "hub": {
                            "id": "hub1",
                            "name": "my_hub",
                        },
                    },
                ],
            },
        ],
    )

    result = hub_list(config, client, param)
    assert result['type'] == 'selectmany'
    assert len(result['values']) == 1
    assert result['values'][0] == ('hub1', 'my_hub (hub1)')
def test_update_translation(
    fs,
    get_sync_translations_env,
    mocked_new_translation_response,
    mocked_responses,
):
    get_sync_translations_env['Translations']['B3'] = 'update'
    get_sync_translations_env['Translations']['H3'] = 'la nueva descripción'
    get_sync_translations_env['Translations']['I3'] = 'Disabled'
    get_sync_translations_env.save(f'{fs.root_path}/test.xlsx')

    stats = SynchronizerStats()
    synchronizer = TranslationsSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
        stats=stats,
    )
    response = deepcopy(mocked_new_translation_response)
    response['id'] = 'TRN-1079-0833-9891'
    mocked_responses.add(
        method='PUT',
        url=
        'https://localhost/public/v1/localization/translations/TRN-1079-0833-9891',
        status=200,
        json=response,
    )

    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Translations')
    synchronizer.sync()

    assert stats['Translations'].get_counts_as_dict() == {
        'processed': 2,
        'created': 0,
        'updated': 1,
        'deleted': 0,
        'skipped': 1,
        'errors': 0,
    }
Esempio n. 29
0
def test_open_product_not_found(fs, mocked_responses, mocked_product_response):
    synchronizer = GeneralSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
    )
    mocked_responses.add(
        method='GET',
        url='https://localhost/public/v1/products/PRD-276-377-545',
        json={},
        status=404,
    )
    with pytest.raises(ClickException) as e:
        synchronizer.open(
            './tests/fixtures/comparation_product.xlsx', 'General Information',
        )
    assert str(e.value) == "Product PRD-276-377-545 not found, create it first."
Esempio n. 30
0
def test_validate_long_short_description(fs, get_general_env):
    get_general_env['General Information']['B10'] = get_general_env['General Information']['B11'].value
    get_general_env.save(f'{fs.root_path}/test.xlsx')
    synchronizer = GeneralSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
    )

    with pytest.raises(ClickException) as e:
        synchronizer.open(
            f'{fs.root_path}/test.xlsx', 'General Information',
        )
    assert str(e.value) == (
        f'{GENERAL_ERROR} Short description is mandatory and must be on B10, short description '
        f'can not exceed 512 characters'
    )