Esempio n. 1
0
def test_create_account_connect_parent_external_uid_more_than_one(
    fs,
    customers_workbook,
    mocked_responses,
    mocked_reseller,
):
    customers_workbook['Customers']['D3'] = 'create'
    customers_workbook['Customers']['A3'] = None
    customers_workbook['Customers']['C3'] = None
    customers_workbook['Customers']['F3'] = 'external_uid'
    customers_workbook.save(f'{fs.root_path}/test.xlsx')
    client = get_client()

    mocked_responses.add(
        method='GET',
        url=
        f'https://localhost/public/v1/tier/accounts?eq(external_uid,{mocked_reseller["id"]})&limit=0&offset=0',
        json=[],
        headers={
            'Content-Range': 'items 0-2/2',
        },
    )
    synchronizer = CustomerSynchronizer(
        account_id='VA-123',
        client=client,
        silent=True,
    )
    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Customers')
    synchronizer.sync()
    assert synchronizer.stats._row_errors == {
        3: ['More than one Parent with external_uid TA-7374-0753-1907']
    }
Esempio n. 2
0
def test_create_account_connect_parent_id_not_found(
    fs,
    customers_workbook,
    mocked_responses,
    mocked_reseller,
):
    customers_workbook['Customers']['D3'] = 'create'
    customers_workbook['Customers']['A3'] = None
    customers_workbook['Customers']['C3'] = None
    customers_workbook.save(f'{fs.root_path}/test.xlsx')
    client = get_client()

    mocked_responses.add(
        method='GET',
        url=
        f'https://localhost/public/v1/tier/accounts/{mocked_reseller["id"]}',
        status=404,
    )
    synchronizer = CustomerSynchronizer(
        account_id='VA-123',
        client=client,
        silent=True,
    )
    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Customers')
    synchronizer.sync()
    assert synchronizer.stats._row_errors == {
        3: [f'Parent with id {mocked_reseller["id"]} does not exist']
    }
Esempio n. 3
0
def cmd_sync_customers(config, input_file, yes):
    config.validate()
    acc_id = config.active.id
    acc_name = config.active.name

    if '.xlsx' not in input_file:
        input_file = f'{input_file}/{input_file}.xlsx'

    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,
    )

    synchronizer = CustomerSynchronizer(
        client=client,
        silent=config.silent,
        account_id=acc_id,
    )
    warnings.filterwarnings("ignore", category=UserWarning)
    synchronizer.open(input_file, 'Customers')
    skipped, created, updated, errors = synchronizer.sync()
    synchronizer.save(input_file)
    if not config.silent:
        print_sync_result(skipped, created, updated, errors)
Esempio n. 4
0
def test_create_account_connect_parent_id(
    fs,
    customers_workbook,
    mocked_responses,
    mocked_reseller,
):
    customers_workbook['Customers']['D3'] = 'create'
    customers_workbook['Customers']['A3'] = None
    customers_workbook['Customers']['C3'] = None
    customers_workbook.save(f'{fs.root_path}/test.xlsx')
    client = get_client()

    mocked_responses.add(
        method='POST',
        url='https://localhost/public/v1/tier/accounts',
        json=mocked_reseller,
    )
    mocked_responses.add(
        method='GET',
        url=
        f'https://localhost/public/v1/tier/accounts/{mocked_reseller["id"]}',
        json=mocked_reseller,
    )
    synchronizer = CustomerSynchronizer(
        account_id='VA-123',
        client=client,
        silent=True,
    )
    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Customers')
    synchronizer.sync()
    assert synchronizer.stats._created == 1
Esempio n. 5
0
def cmd_sync_customers(config, input_file, yes):
    acc_id = config.active.id
    acc_name = config.active.name

    if '.xlsx' not in input_file:
        input_file = f'{input_file}/{input_file}.xlsx'

    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,
    )

    synchronizer = CustomerSynchronizer(
        client=client,
        silent=config.silent,
        account_id=acc_id,
    )
    warnings.filterwarnings("ignore", category=UserWarning)
    synchronizer.open(input_file, 'Customers')
    synchronizer.sync()
    synchronizer.save(input_file)
    if not config.silent:
        synchronizer.stats.print()
Esempio n. 6
0
def test_create_account_connect_uuid(
    fs,
    customers_workbook,
    mocked_responses,
    mocked_reseller,
):
    customers_workbook['Customers']['D2'] = 'create'
    customers_workbook['Customers']['A2'] = None
    customers_workbook['Customers']['C2'] = None
    customers_workbook.save(f'{fs.root_path}/test.xlsx')
    client = get_client()

    mocked_responses.add(
        method='POST',
        url='https://localhost/public/v1/tier/accounts',
        json=mocked_reseller,
    )
    synchronizer = CustomerSynchronizer(
        account_id='VA-123',
        client=client,
        silent=True,
    )
    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Customers')
    skipped, created, updated, errors = synchronizer.sync()
    assert created == 1
Esempio n. 7
0
def test_bad_action(fs, customers_workbook):
    customers_workbook['Customers']['D2'] = 'wrong'
    customers_workbook.save(f'{fs.root_path}/test.xlsx')
    client = get_client()

    synchronizer = CustomerSynchronizer(
        account_id='VA-123',
        client=client,
        silent=True,
    )
    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Customers')
    skipped, created, updated, errors = synchronizer.sync()
    assert errors == {2: ['Action wrong is not supported']}
Esempio n. 8
0
def test_empty_address(fs, customers_workbook):
    customers_workbook['Customers']['D2'] = 'create'
    customers_workbook['Customers']['K2'] = ''
    customers_workbook.save(f'{fs.root_path}/test.xlsx')
    client = get_client()

    synchronizer = CustomerSynchronizer(
        account_id='VA-123',
        client=client,
        silent=True,
    )
    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Customers')
    skipped, created, updated, errors = synchronizer.sync()
    assert errors == {2: ['Address line 1, city, state and zip are mandatory']}
Esempio n. 9
0
def test_update_customer_no_id(fs, customers_workbook):
    customers_workbook['Customers']['D2'] = 'update'
    customers_workbook['Customers']['A2'] = 'KA-'
    customers_workbook.save(f'{fs.root_path}/test.xlsx')
    client = get_client()

    synchronizer = CustomerSynchronizer(
        account_id='VA-123',
        client=client,
        silent=True,
    )
    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Customers')
    skipped, created, updated, errors = synchronizer.sync()
    assert errors == {2: ['Update operation requires account ID to be set']}
Esempio n. 10
0
def test_create_customer_no_parent(fs, customers_workbook):
    customers_workbook['Customers']['D2'] = 'create'
    customers_workbook['Customers']['H2'] = 'customer'
    customers_workbook['Customers']['A2'] = None
    customers_workbook.save(f'{fs.root_path}/test.xlsx')
    client = get_client()

    synchronizer = CustomerSynchronizer(
        account_id='VA-123',
        client=client,
        silent=True,
    )
    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Customers')
    skipped, created, updated, errors = synchronizer.sync()
    assert errors == {2: ['Customers requires a parent account']}
Esempio n. 11
0
def test_sync_all_skip(fs, customers_workbook):
    customers_workbook.save(f'{fs.root_path}/test.xlsx')
    client = get_client()

    synchronizer = CustomerSynchronizer(
        account_id='VA-123',
        client=client,
        silent=True,
    )
    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Customers')
    skipped, created, updated, errors = synchronizer.sync()
    assert skipped == 2
    assert created == 0
    assert updated == 0
    assert len(errors) == 0
Esempio n. 12
0
def test_bad_account(fs, customers_workbook):
    customers_workbook['Customers']['D2'] = 'create'
    customers_workbook['Customers']['H2'] = 'robot'
    customers_workbook.save(f'{fs.root_path}/test.xlsx')
    client = get_client()

    synchronizer = CustomerSynchronizer(
        account_id='VA-123',
        client=client,
        silent=True,
    )
    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Customers')
    synchronizer.sync()
    assert synchronizer.stats._row_errors == {
        2: ['Customer type must be customer or reseller, not robot']
    }
Esempio n. 13
0
def test_create_existing(fs, customers_workbook):
    customers_workbook['Customers']['D2'] = 'create'
    customers_workbook.save(f'{fs.root_path}/test.xlsx')
    client = get_client()

    synchronizer = CustomerSynchronizer(
        account_id='VA-123',
        client=client,
        silent=True,
    )
    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Customers')
    synchronizer.sync()
    assert synchronizer.stats._row_errors == {
        2: [
            'Create action must not have account id, is set to TA-7374-0753-1907'
        ],
    }
Esempio n. 14
0
def test_create_account_connect_parent_external_uid(
    fs,
    customers_workbook,
    mocked_responses,
    mocked_reseller,
):
    customers_workbook['Customers']['D3'] = 'create'
    customers_workbook['Customers']['A3'] = None
    customers_workbook['Customers']['C3'] = None
    customers_workbook['Customers']['F3'] = 'external_uid'
    customers_workbook.save(f'{fs.root_path}/test.xlsx')
    client = get_client()

    mocked_responses.add(
        method='GET',
        url=
        f'https://localhost/public/v1/tier/accounts?eq(external_uid,{mocked_reseller["id"]})&limit=0&offset=0',
        json=[mocked_reseller],
        headers={
            'Content-Range': 'items 0-1/1',
        },
    )
    mocked_responses.add(
        method='GET',
        url=
        f'https://localhost/public/v1/tier/accounts?eq(external_uid,{mocked_reseller["id"]})&limit=1&offset=0',
        json=[mocked_reseller],
        headers={
            'Content-Range': 'items 0-1/1',
        },
    )
    mocked_responses.add(
        method='POST',
        url='https://localhost/public/v1/tier/accounts',
        json=mocked_reseller,
    )
    synchronizer = CustomerSynchronizer(
        account_id='VA-123',
        client=client,
        silent=True,
    )
    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Customers')
    synchronizer.sync()
    assert synchronizer.stats._created == 1
Esempio n. 15
0
def test_sync_all_skip(fs, customers_workbook):
    customers_workbook.save(f'{fs.root_path}/test.xlsx')
    client = get_client()

    synchronizer = CustomerSynchronizer(
        account_id='VA-123',
        client=client,
        silent=True,
    )
    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Customers')
    synchronizer.sync()
    assert synchronizer.stats.get_counts_as_dict() == {
        'processed': 2,
        'created': 0,
        'updated': 0,
        'deleted': 0,
        'skipped': 2,
        'errors': 0,
    }
Esempio n. 16
0
def test_update_customer_no_account_connect(fs, customers_workbook,
                                            mocked_responses):
    customers_workbook['Customers']['D2'] = 'update'
    customers_workbook.save(f'{fs.root_path}/test.xlsx')
    client = get_client()

    mocked_responses.add(
        method='GET',
        url='https://localhost/public/v1/tier/accounts/TA-7374-0753-1907',
        status=404,
    )
    synchronizer = CustomerSynchronizer(
        account_id='VA-123',
        client=client,
        silent=True,
    )
    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Customers')
    skipped, created, updated, errors = synchronizer.sync()
    assert errors == {2: ['Account with id TA-7374-0753-1907 does not exist']}