Пример #1
0
def test_validate_wrong_action(fs, get_sync_media_env):
    get_sync_media_env['Media']['C2'] = 'XYZ'
    get_sync_media_env.save(f'{fs.root_path}/test.xlsx')

    synchronizer = MediaSynchronizer(
        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', 'Media')

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

    assert skipped == 0
    assert created == 0
    assert updated == 0
    assert deleted == 0
    assert errors == {
        2: [
            'Supported actions are `-`, `create`, `update` or `delete`. Provided XYZ'
        ],
    }
Пример #2
0
def test_validate_invalid_video_url(fs, get_sync_media_env, video_domain):
    get_sync_media_env['Media']['C2'] = 'create'
    get_sync_media_env['Media']['D2'] = 'video'
    get_sync_media_env['Media']['E2'] = 'image.png'
    get_sync_media_env['Media']['F2'] = f'http://{video_domain}/video.mov'
    get_sync_media_env.save(f'{fs.root_path}/test.xlsx')

    synchronizer = MediaSynchronizer(
        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', 'Media')

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

    assert skipped == 0
    assert created == 0
    assert updated == 0
    assert deleted == 0
    assert errors == {
        2: [
            'Videos can be hosted on youtube or vimeo, please also ensure to provide https url. '
            f'Invalid url provided is http://{video_domain}/video.mov'
        ],
    }
Пример #3
0
def test_validate_invalid_no_video_url(fs, get_sync_media_env):
    get_sync_media_env['Media']['C2'] = 'create'
    get_sync_media_env['Media']['D2'] = 'video'
    get_sync_media_env['Media']['E2'] = 'image.png'
    get_sync_media_env['Media']['F2'] = None
    get_sync_media_env.save(f'{fs.root_path}/test.xlsx')

    synchronizer = MediaSynchronizer(
        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', 'Media')

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

    assert skipped == 0
    assert created == 0
    assert updated == 0
    assert deleted == 0
    assert errors == {
        2: ['Video URL location is required for video type'],
    }
Пример #4
0
def test_validate_no_position(fs, get_sync_media_env):
    get_sync_media_env['Media']['A2'] = None
    get_sync_media_env['Media']['C2'] = 'create'
    get_sync_media_env.save(f'{fs.root_path}/test.xlsx')

    synchronizer = MediaSynchronizer(
        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', 'Media')

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

    assert skipped == 0
    assert created == 0
    assert updated == 0
    assert deleted == 0
    assert errors == {
        2: ['Position is required and must be an integer between 1 and 8']
    }
Пример #5
0
def test_update_image_404(fs, get_sync_media_env, mocked_responses,
                          mocked_media_response):
    get_sync_media_env['Media']['C2'] = 'update'
    get_sync_media_env.save(f'{fs.root_path}/test.xlsx')

    synchronizer = MediaSynchronizer(
        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', 'Media')

    mocked_responses.add(
        method='PUT',
        url=
        'https://localhost/public/v1/products/PRD-276-377-545/media/PRDM-276-377-545-67072',
        status=404,
    )

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

    assert skipped == 0
    assert created == 0
    assert updated == 0
    assert deleted == 0
    assert errors == {2: ['404 Not Found']}
Пример #6
0
def test_create_video(fs, get_sync_media_env, mocked_responses,
                      mocked_media_response, domain):
    get_sync_media_env['Media']['C2'] = 'create'
    get_sync_media_env['Media']['D2'] = 'video'
    get_sync_media_env['Media']['E2'] = 'image.png'
    get_sync_media_env['Media']['F2'] = f'https://{domain}/test'

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

    synchronizer = MediaSynchronizer(
        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', 'Media')

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

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

    assert skipped == 0
    assert created == 1
    assert updated == 0
    assert deleted == 0
    assert errors == {}
Пример #7
0
def test_validate_wrong_file(fs, get_sync_media_env):
    get_sync_media_env['Media']['C2'] = 'create'
    get_sync_media_env['Media']['E2'] = 'wrong.png'
    get_sync_media_env.save(f'{fs.root_path}/test.xlsx')

    synchronizer = MediaSynchronizer(
        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', 'Media')

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

    assert skipped == 0
    assert created == 0
    assert updated == 0
    assert deleted == 0
    assert errors == {
        2: [
            'Image file is not found, please check that file wrong.png exists in media folder'
        ],
    }
Пример #8
0
def test_validate_wrong_type(fs, get_sync_media_env):
    get_sync_media_env['Media']['C2'] = 'create'
    get_sync_media_env['Media']['D2'] = 'wrong'
    get_sync_media_env.save(f'{fs.root_path}/test.xlsx')

    synchronizer = MediaSynchronizer(
        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', 'Media')

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

    assert skipped == 0
    assert created == 0
    assert updated == 0
    assert deleted == 0
    assert errors == {
        2: ['Media can be either image or video type, provided wrong'],
    }
Пример #9
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 == {}
Пример #10
0
def test_validate_wrong_action(fs, get_sync_media_env):
    get_sync_media_env['Media']['C2'] = 'XYZ'
    get_sync_media_env.save(f'{fs.root_path}/test.xlsx')

    stats = SynchronizerStats()
    synchronizer = MediaSynchronizer(
        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', 'Media')
    synchronizer.sync()

    assert stats['Media'].get_counts_as_dict() == {
        'processed': 1,
        'created': 0,
        'updated': 0,
        'deleted': 0,
        'skipped': 0,
        'errors': 1,
    }
    assert stats['Media']._row_errors == {
        2: [
            'Supported actions are `-`, `create`, `update` or `delete`. Provided XYZ'
        ],
    }
Пример #11
0
def test_validate_invalid_video_url(fs, get_sync_media_env, video_domain):
    get_sync_media_env['Media']['C2'] = 'create'
    get_sync_media_env['Media']['D2'] = 'video'
    get_sync_media_env['Media']['E2'] = 'image.png'
    get_sync_media_env['Media']['F2'] = f'http://{video_domain}/video.mov'
    get_sync_media_env.save(f'{fs.root_path}/test.xlsx')

    stats = SynchronizerStats()
    synchronizer = MediaSynchronizer(
        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', 'Media')
    synchronizer.sync()

    assert stats['Media'].get_counts_as_dict() == {
        'processed': 1,
        'created': 0,
        'updated': 0,
        'deleted': 0,
        'skipped': 0,
        'errors': 1,
    }
    assert stats['Media']._row_errors == {
        2: [
            'Videos can be hosted on youtube or vimeo, please also ensure to provide https url. '
            f'Invalid url provided is http://{video_domain}/video.mov'
        ],
    }
Пример #12
0
def test_update_image_404(fs, get_sync_media_env, mocked_responses,
                          mocked_media_response):
    get_sync_media_env['Media']['C2'] = 'update'
    get_sync_media_env.save(f'{fs.root_path}/test.xlsx')

    stats = SynchronizerStats()
    synchronizer = MediaSynchronizer(
        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', 'Media')

    mocked_responses.add(
        method='PUT',
        url=
        'https://localhost/public/v1/products/PRD-276-377-545/media/PRDM-276-377-545-67072',
        status=404,
    )
    synchronizer.sync()

    assert stats['Media'].get_counts_as_dict() == {
        'processed': 1,
        'created': 0,
        'updated': 0,
        'deleted': 0,
        'skipped': 0,
        'errors': 1,
    }
    assert stats['Media']._row_errors == {2: ['404 Not Found']}
Пример #13
0
def test_validate_no_image_file(fs, get_sync_media_env):
    get_sync_media_env['Media']['C2'] = 'update'
    get_sync_media_env['Media']['E2'] = None
    get_sync_media_env.save(f'{fs.root_path}/test.xlsx')

    stats = SynchronizerStats()
    synchronizer = MediaSynchronizer(
        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', 'Media')
    synchronizer.sync()

    assert stats['Media'].get_counts_as_dict() == {
        'processed': 1,
        'created': 0,
        'updated': 0,
        'deleted': 0,
        'skipped': 0,
        'errors': 1,
    }
    assert stats['Media']._row_errors == {2: ['Image file is required']}
Пример #14
0
def test_validate_wrong_type(fs, get_sync_media_env):
    get_sync_media_env['Media']['C2'] = 'create'
    get_sync_media_env['Media']['D2'] = 'wrong'
    get_sync_media_env.save(f'{fs.root_path}/test.xlsx')

    stats = SynchronizerStats()
    synchronizer = MediaSynchronizer(
        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', 'Media')
    synchronizer.sync()

    assert stats['Media'].get_counts_as_dict() == {
        'processed': 1,
        'created': 0,
        'updated': 0,
        'deleted': 0,
        'skipped': 0,
        'errors': 1,
    }
    assert stats['Media']._row_errors == {
        2: ['Media can be either image or video type, provided wrong'],
    }
Пример #15
0
def test_validate_no_valid_id(fs, get_sync_media_env):
    get_sync_media_env['Media']['C2'] = 'update'
    get_sync_media_env['Media']['B2'] = 'wrong'
    get_sync_media_env.save(f'{fs.root_path}/test.xlsx')

    synchronizer = MediaSynchronizer(
        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', 'Media')

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

    assert skipped == 0
    assert created == 0
    assert updated == 0
    assert deleted == 0
    assert errors == {2: ['ID does not seam to be valid.']}
Пример #16
0
def test_no_action(get_sync_media_env):
    stats = SynchronizerStats()
    synchronizer = MediaSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
        stats=stats,
    )

    synchronizer.open('./tests/fixtures/media_sync.xlsx', 'Media')
    synchronizer.sync()

    assert stats['Media'].get_counts_as_dict() == {
        'processed': 1,
        'created': 0,
        'updated': 0,
        'deleted': 0,
        'skipped': 1,
        'errors': 0,
    }
Пример #17
0
def test_create_video(fs, get_sync_media_env, mocked_responses,
                      mocked_media_response, domain):
    get_sync_media_env['Media']['C2'] = 'create'
    get_sync_media_env['Media']['D2'] = 'video'
    get_sync_media_env['Media']['E2'] = 'image.png'
    get_sync_media_env['Media']['F2'] = f'https://{domain}/test'

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

    stats = SynchronizerStats()
    synchronizer = MediaSynchronizer(
        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', 'Media')

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

    assert stats['Media'].get_counts_as_dict() == {
        'processed': 1,
        'created': 1,
        'updated': 0,
        'deleted': 0,
        'skipped': 0,
        'errors': 0,
    }