Exemplo n.º 1
0
def test_create_item_validate_commitment(
    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']['I2'].value = 'yearly'
    get_sync_items_env['Items']['J2'].value = 'commitment'

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

    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: ['the item `Commitment` must be one between `-`, `1 year`, `2 years`, `3 years`, '
            '`4 years`, `5 years`, not `commitment`.'],
    }
Exemplo n.º 2
0
def test_create_item_validate_commitment_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 = 'create'
    get_sync_items_env['Items']['F2'].value = 'ppu'
    get_sync_items_env['Items']['I2'].value = 'monthly'
    get_sync_items_env['Items']['J2'].value = '1 year'

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

    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: ['the commitment `1 year` is invalid for `ppu` items.'],
    }
Exemplo n.º 3
0
def test_validate_wrong_period_reservation(fs, get_sync_items_env):
    get_sync_items_env['Items']['A2'].value = None
    get_sync_items_env['Items']['I2'].value = 'century'
    get_sync_items_env['Items']['C2'].value = 'create'
    get_sync_items_env.save(f'{fs.root_path}/test.xlsx')
    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: ['the item `Billing period` must be one between `onetime`, `monthly`, `yearly`, '
            '`2 years`, `3 years`, `4 years`, `5 years`, not `century`.'],
    }
Exemplo n.º 4
0
def test_validate_row_errors_no_row_id(fs, get_sync_items_env, row_action):
    get_sync_items_env['Items']['A2'].value = None
    get_sync_items_env['Items']['B2'].value = None
    get_sync_items_env['Items']['C2'].value = row_action
    get_sync_items_env.save(f'{fs.root_path}/test.xlsx')
    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: [f'one between the item `ID` or `MPN` is required for the `{row_action}` action.'],
    }
Exemplo n.º 5
0
def test_validate_wrong_precision_ppu(fs, get_sync_items_env):
    get_sync_items_env['Items']['A2'].value = None
    get_sync_items_env['Items']['F2'].value = 'ppu'
    get_sync_items_env['Items']['G2'].value = 'decimal(12)'
    get_sync_items_env['Items']['C2'].value = 'create'
    get_sync_items_env.save(f'{fs.root_path}/test.xlsx')
    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: ['the item `Precision` must be one between `integer`, `decimal(1)`, `decimal(2)`, '
            '`decimal(4)`, `decimal(8)`, not `decimal(12)`.'],
    }
Exemplo n.º 6
0
def test_validate_create_strange_type(fs, get_sync_items_env):
    get_sync_items_env['Items']['A2'].value = None
    get_sync_items_env['Items']['F2'].value = 'license'
    get_sync_items_env['Items']['C2'].value = 'create'
    get_sync_items_env.save(f'{fs.root_path}/test.xlsx')
    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: ['the item `Type` must be one between `reservation` or `ppu`, not `license`.'],
    }
Exemplo n.º 7
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,
    }
Exemplo n.º 8
0
def test_validate_create_strange_type(fs, get_sync_items_env):
    get_sync_items_env['Items']['A2'].value = None
    get_sync_items_env['Items']['F2'].value = 'license'
    get_sync_items_env['Items']['C2'].value = 'create'
    get_sync_items_env.save(f'{fs.root_path}/test.xlsx')
    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 errors == {
        2: [
            'the item `Type` must be one between `reservation` or `ppu`, not `license`.'
        ],
    }
Exemplo n.º 9
0
def test_validate_wrong_precision_ppu(fs, get_sync_items_env):
    get_sync_items_env['Items']['A2'].value = None
    get_sync_items_env['Items']['F2'].value = 'ppu'
    get_sync_items_env['Items']['G2'].value = 'decimal(12)'
    get_sync_items_env['Items']['C2'].value = 'create'
    get_sync_items_env.save(f'{fs.root_path}/test.xlsx')
    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 errors == {
        2: [
            'the item `Precision` must be one between `integer`, `decimal(1)`, `decimal(2)`, '
            '`decimal(4)`, `decimal(8)`, not `decimal(12)`.'
        ],
    }
Exemplo n.º 10
0
def test_create_item_validate_commitment_onetime(
    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']['F2'].value = 'reservation'
    get_sync_items_env['Items']['I2'].value = 'onetime'
    get_sync_items_env['Items']['J2'].value = '1 year'

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

    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 errors == {
        2: ['the commitment `1 year` is invalid for `onetime` items.'],
    }
Exemplo n.º 11
0
def test_validate_wrong_period_ppu(fs, get_sync_items_env):
    get_sync_items_env['Items']['A2'].value = None
    get_sync_items_env['Items']['F2'].value = 'ppu'
    get_sync_items_env['Items']['I2'].value = 'yearly'
    get_sync_items_env['Items']['C2'].value = 'create'
    get_sync_items_env.save(f'{fs.root_path}/test.xlsx')
    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 errors == {
        2: [
            'for items of type `ppu` the `Billing period` must be `monthly`, not `yearly`.'
        ],
    }
Exemplo n.º 12
0
def test_validate_wrong_period_reservation(fs, get_sync_items_env):
    get_sync_items_env['Items']['A2'].value = None
    get_sync_items_env['Items']['I2'].value = 'century'
    get_sync_items_env['Items']['C2'].value = 'create'
    get_sync_items_env.save(f'{fs.root_path}/test.xlsx')
    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 errors == {
        2: [
            'the item `Billing period` must be one between `onetime`, `monthly`, `yearly`, '
            '`2 years`, `3 years`, `4 years`, `5 years`, not `century`.'
        ],
    }
Exemplo n.º 13
0
def test_validate_row_errors_no_row_id(fs, get_sync_items_env, row_action):
    get_sync_items_env['Items']['A2'].value = None
    get_sync_items_env['Items']['B2'].value = None
    get_sync_items_env['Items']['C2'].value = row_action
    get_sync_items_env.save(f'{fs.root_path}/test.xlsx')
    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 errors == {
        2: [
            f'one between the item `ID` or `MPN` is required for the `{row_action}` action.'
        ],
    }
Exemplo n.º 14
0
def test_create_item_validate_commitment_wrong_multiyear_vs_commitment(
    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']['F2'].value = 'reservation'
    get_sync_items_env['Items']['I2'].value = '3 years'
    get_sync_items_env['Items']['J2'].value = '5 years'

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

    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 errors == {
        2: [
            'for a billing period of `3 years` the commitment must be `-`, not 5 years.'
        ],
    }
Exemplo n.º 15
0
def test_create_item_validate_commitment(
    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']['I2'].value = 'yearly'
    get_sync_items_env['Items']['J2'].value = 'commitment'

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

    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 errors == {
        2: [
            'the item `Commitment` must be one between `-`, `1 year`, `2 years`, `3 years`, '
            '`4 years`, `5 years`, not `commitment`.'
        ],
    }
Exemplo n.º 16
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.'],
    }
Exemplo n.º 17
0
def test_skipped(get_sync_items_env):

    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('./tests/fixtures/items_sync.xlsx', 'Items')
    synchronizer.sync()

    assert stats['Items'].get_counts_as_dict() == {
        'processed': 1, 'created': 0, 'updated': 0,
        'deleted': 0, 'skipped': 1, 'errors': 0,
    }
Exemplo n.º 18
0
def test_update_item_no_item_connect(
    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.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=[],
    )

    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: ['Cannot update item: item with MPN `MPN-R-001` the item does not exist.'],
    }
Exemplo n.º 19
0
def test_create_item_validate_commitment_wrong_multiyear(
    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']['F2'].value = 'reservation'
    get_sync_items_env['Items']['I2'].value = '2 years'
    get_sync_items_env['Items']['J2'].value = '3 years'

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

    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: ['for a billing period of `2 years` the commitment must be one between `-`, `4 years`, '
            ' not 3 years.'],
    }
Exemplo n.º 20
0
def test_validate_delete_published_item(fs, get_sync_items_env):
    get_sync_items_env['Items']['C2'].value = 'delete'
    get_sync_items_env.save(f'{fs.root_path}/test.xlsx')
    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: ['the item status must be `draft` for the `delete` action.'],
    }
Exemplo n.º 21
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 == {}
Exemplo n.º 22
0
def test_skipped(get_sync_items_env):

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

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

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

    assert skipped == 1
    assert created == 0
    assert updated == 0
    assert errors == {}
Exemplo n.º 23
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.']}
Exemplo n.º 24
0
def test_delete_item_not_exists(
    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=[],
    )

    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: [
            'Cannot update item: item with MPN `MPN-R-001` the item does not exist.'
        ],
    }
Exemplo n.º 25
0
def test_validate_delete_published_item(fs, get_sync_items_env):
    get_sync_items_env['Items']['C2'].value = 'delete'
    get_sync_items_env.save(f'{fs.root_path}/test.xlsx')
    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 errors == {
        2: ['the item status must be `draft` for the `delete` action.'],
    }
Exemplo n.º 26
0
def test_validate_create_no_description(fs, get_sync_items_env):
    get_sync_items_env['Items']['A2'].value = None
    get_sync_items_env['Items']['E2'].value = None
    get_sync_items_env['Items']['C2'].value = 'create'
    get_sync_items_env.save(f'{fs.root_path}/test.xlsx')
    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 errors == {
        2: ['the item `Description` is required for the `create` action.'],
    }