Exemplo n.º 1
0
def test_validate_delete_not_found(fs, get_sync_params_env, mocked_responses):
    get_sync_params_env['Ordering Parameters']['C2'] = 'delete'
    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='DELETE',
        url='https://localhost/public/v1/products/PRD-276-377-545/parameters/PRM-276-377-545-0008',
        status=404,
    )

    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 == 0
    assert deleted == 1
    assert errors == {}
Exemplo n.º 2
0
def test_validate_update_invalid_switch(
    fs,
    get_sync_params_env,
    mocked_responses,
    mocked_ordering_params_response,
):
    get_sync_params_env['Ordering Parameters']['C2'] = 'update'
    get_sync_params_env['Ordering Parameters']['H2'] = 'text'

    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=mocked_ordering_params_response[0],
    )

    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 == 0
    assert deleted == 0
    assert errors == {2: ['Switching parameter type is not supported']}
Exemplo n.º 3
0
def test_validate_create_connect_error(
    fs,
    get_sync_params_env,
    mocked_responses,
    mocked_ordering_params_response,
):
    get_sync_params_env['Ordering Parameters']['C2'] = 'create'

    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='POST',
        url='https://localhost/public/v1/products/PRD-276-377-545/parameters',
        status=500,
    )

    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 == 0
    assert deleted == 0
    assert errors == {2: ['500 Internal Server Error']}
Exemplo n.º 4
0
def test_validate_invalid_param_type(fs, get_sync_params_env):
    get_sync_params_env['Ordering Parameters']['C2'] = 'create'
    get_sync_params_env['Ordering Parameters']['H2'] = 'rocket'
    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,
    )

    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 == 0
    assert deleted == 0
    assert errors == {
        2: ['Parameter type rocket is not one of the supported ones:email,address,checkbox,'
            'choice,domain,subdomain,url,dropdown,object,password,phone,text'],
    }
Exemplo n.º 5
0
def test_validate_invalid_scope_config(fs, get_sync_params_env):
    get_sync_params_env['Configuration Parameters']['C2'] = 'create'
    get_sync_params_env['Configuration Parameters']['G2'] = 'rocket'
    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,
    )

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

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

    assert skipped == 0
    assert created == 0
    assert updated == 0
    assert deleted == 0
    assert errors == {
        2: ['Only item, item_marketplace, marketplace and product scopes are supported for '
            'Configuration Parameters'],
    }
Exemplo n.º 6
0
def test_validate_invalid_switch(fs, get_sync_params_env):
    get_sync_params_env['Ordering Parameters']['C2'] = 'create'
    get_sync_params_env['Ordering Parameters']['F2'] = 'fulfillment'
    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,
    )

    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 == 0
    assert deleted == 0
    assert errors == {
        2: ['Parameters of type ordering are only supported when processing Ordering Parameters. '
            'Has been provided fulfillment.'],
    }
Exemplo n.º 7
0
def test_skipped(get_sync_params_env):

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

    synchronizer.open('./tests/fixtures/params_sync.xlsx', 'Ordering Parameters')

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

    assert skipped == 1
    assert created == 0
    assert updated == 0
    assert deleted == 0
    assert errors == {}
Exemplo n.º 8
0
def test_validate_invalid_id(fs, get_sync_params_env):
    get_sync_params_env['Ordering Parameters']['B2'] = 'XKL#'
    get_sync_params_env['Ordering Parameters']['C2'] = 'update'
    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,
    )

    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': 0,
        'deleted': 0,
        'skipped': 0,
        'errors': 1,
    }
    assert stats['Ordering Parameters']._row_errors == {
        2: [
            'Parameter ID must contain only letters, numbers and `_`, provided XKL#'
        ],
    }
Exemplo n.º 9
0
def test_validate_delete_not_found(fs, get_sync_params_env, mocked_responses):
    get_sync_params_env['Ordering Parameters']['C2'] = 'delete'
    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='DELETE',
        url=
        'https://localhost/public/v1/products/PRD-276-377-545/parameters/PRM-276-377-545-0008',
        status=404,
    )

    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': 0,
        'deleted': 1,
        'skipped': 0,
        'errors': 0,
    }
Exemplo n.º 10
0
def test_skipped(get_sync_params_env):

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

    synchronizer.open('./tests/fixtures/params_sync.xlsx',
                      'Ordering Parameters')
    synchronizer.sync()

    assert stats['Ordering Parameters'].get_counts_as_dict() == {
        'processed': 1,
        'created': 0,
        'updated': 0,
        'deleted': 0,
        'skipped': 1,
        'errors': 0,
    }
Exemplo n.º 11
0
def test_validate_invalid_scope_config(fs, get_sync_params_env):
    get_sync_params_env['Configuration Parameters']['C2'] = 'create'
    get_sync_params_env['Configuration Parameters']['G2'] = 'rocket'
    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,
    )

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

    assert stats['Configuration Parameters'].get_counts_as_dict() == {
        'processed': 1,
        'created': 0,
        'updated': 0,
        'deleted': 0,
        'skipped': 0,
        'errors': 1,
    }
    assert stats['Configuration Parameters']._row_errors == {
        2: [
            'Only item, item_marketplace, marketplace and product scopes are supported for '
            'Configuration Parameters'
        ],
    }
Exemplo n.º 12
0
def test_validate_invalid_json(fs, get_sync_params_env):
    get_sync_params_env['Ordering Parameters']['C2'] = 'create'
    get_sync_params_env['Ordering Parameters']['L2'] = 'nojson'
    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,
    )

    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': 0,
        'deleted': 0,
        'skipped': 0,
        'errors': 1,
    }
    assert stats['Ordering Parameters']._row_errors == {
        2: ['JSON properties must have json format']
    }
Exemplo n.º 13
0
def test_validate_invalid_action(fs, get_sync_params_env):
    get_sync_params_env['Ordering Parameters']['C2'] = 'update'
    get_sync_params_env['Ordering Parameters']['A2'] = None
    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,
    )

    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': 0,
        'deleted': 0,
        'skipped': 0,
        'errors': 1,
    }
    assert stats['Ordering Parameters']._row_errors == {
        2: ['Verbose ID is required on update and delete actions.'],
    }
Exemplo n.º 14
0
def test_validate_invalid_switch(fs, get_sync_params_env):
    get_sync_params_env['Ordering Parameters']['C2'] = 'create'
    get_sync_params_env['Ordering Parameters']['F2'] = 'fulfillment'
    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,
    )

    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': 0,
        'deleted': 0,
        'skipped': 0,
        'errors': 1,
    }
    assert stats['Ordering Parameters']._row_errors == {
        2: [
            'Parameters of type ordering are only supported when processing Ordering Parameters. '
            'Has been provided fulfillment.'
        ],
    }
Exemplo n.º 15
0
def test_validate_invalid_action(fs, get_sync_params_env):
    get_sync_params_env['Ordering Parameters']['C2'] = 'update'
    get_sync_params_env['Ordering Parameters']['A2'] = None
    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,
    )

    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 == 0
    assert deleted == 0
    assert errors == {2: ['Verbose ID is required on update and delete actions.']}
Exemplo n.º 16
0
def test_validate_invalid_required3(fs, get_sync_params_env):
    get_sync_params_env['Ordering Parameters']['C2'] = 'create'
    get_sync_params_env['Ordering Parameters']['K2'] = 'rocket'
    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,
    )

    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 == 0
    assert deleted == 0
    assert errors == {2: ['Hidden must be either True or `-`']}
Exemplo n.º 17
0
def test_validate_invalid_id(fs, get_sync_params_env):
    get_sync_params_env['Ordering Parameters']['B2'] = 'XKL#'
    get_sync_params_env['Ordering Parameters']['C2'] = 'update'
    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,
    )

    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 == 0
    assert deleted == 0
    assert errors == {2: ['Parameter ID must contain only letters, numbers and `_`, provided XKL#']}
Exemplo n.º 18
0
def test_validate_invalid_json(fs, get_sync_params_env):
    get_sync_params_env['Ordering Parameters']['C2'] = 'create'
    get_sync_params_env['Ordering Parameters']['L2'] = 'nojson'
    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,
    )

    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 == 0
    assert deleted == 0
    assert errors == {2: ['JSON properties must have json format']}
Exemplo n.º 19
0
def test_validate_create_no_constrains(
    fs,
    get_sync_params_env,
    mocked_responses,
    mocked_ordering_params_response,
):
    get_sync_params_env['Ordering Parameters']['C2'] = 'create'
    get_sync_params_env['Ordering Parameters']['L2'] = None

    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_responses.add(
        method='POST',
        url='https://localhost/public/v1/products/PRD-276-377-545/parameters',
        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': 1,
        'updated': 0,
        'deleted': 0,
        'skipped': 0,
        'errors': 0,
    }
Exemplo n.º 20
0
def test_validate_update_invalid_switch_scope(
    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]
    response['scope'] = 'tier2'

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

    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': 0,
        'deleted': 0,
        'skipped': 0,
        'errors': 1,
    }
    assert stats['Ordering Parameters']._row_errors == {
        2: ['switching scope is not supported']
    }