Esempio n. 1
0
def test_import_asset_directory(stderr, stdout):
    http_service = MockHttpService()

    lock_dir = tempfile.mkdtemp()
    with HTTMock(http_service):
        tool = AssetsTool()
        server = Server('localhost')
        status = tool.execute(server, ['assets', 'import', 'tests/test_data/assets'])

    eq_('', stderr.getvalue())

    lines = stdout.getvalue().split('\n')
    eq_(4, len(lines))
    eq_(lines[0], 'tests/test_data/assets/logo.jpg -> /content/dam/assets')
    eq_(lines[1], 'tests/test_data/assets/subdir/graph.jpg -> /content/dam/assets/subdir')
    eq_(lines[2], 'tests/test_data/assets/subdir/graph2.jpg -> /content/dam/assets/subdir')
    eq_(OK, status)

    eq_(5, len(http_service.req_log))
    eq_(http_service.req_log[0].url, 'http://localhost:4502/content/dam/assets')
    eq_(http_service.req_log[1].url, 'http://localhost:4502/content/dam/assets.createasset.html')
    eq_(http_service.req_log[2].url, 'http://localhost:4502/content/dam/assets/subdir')
    eq_(http_service.req_log[3].url, 'http://localhost:4502/content/dam/assets/subdir.createasset.html')
    # Skipped creating subdir for the second file
    eq_(http_service.req_log[4].url, 'http://localhost:4502/content/dam/assets/subdir.createasset.html')

    shutil.rmtree(lock_dir)
Esempio n. 2
0
def test_import_asset_file(stderr, stdout):
    http_service = MockHttpService()

    lock_dir = tempfile.mkdtemp()
    with HTTMock(http_service):
        tool = AssetsTool()
        server = Server('localhost')
        status = tool.execute(server, [
            'assets', '--lock-dir={}'.format(lock_dir), 'import',
            'tests/test_data/assets/logo.jpg'
        ])

    eq_('', stderr.getvalue())
    _is_valid_upload_line(stdout.getvalue(), [
        '2016-11-25 13:12:01', '1/1',
        'tests/test_data/assets/logo.jpg -> /content/dam/assets', '0.0192'
    ])
    eq_(OK, status)

    eq_(2, len(http_service.req_log))
    eq_(http_service.req_log[0].url,
        'http://localhost:4502/content/dam/assets')
    eq_(http_service.req_log[1].url,
        'http://localhost:4502/content/dam/assets.createasset.html')

    shutil.rmtree(lock_dir)
Esempio n. 3
0
def test_dry_run_import_asset_directory(stderr, stdout):
    http_service = MockHttpService()
    eq_(0, len(http_service.req_log))

    lock_dir = tempfile.mkdtemp()
    with HTTMock(http_service):
        tool = AssetsTool()
        server = Server('localhost')
        status = tool.execute(server, [
            'assets', '--dry-run', '--lock-dir={}'.format(lock_dir), 'import',
            'tests/test_data/assets'
        ])

    eq_('', stderr.getvalue())

    lines = stdout.getvalue().split('\n')
    eq_(4, len(lines))
    eq_(lines[0], '1/3 tests/test_data/assets/logo.jpg -> /content/dam/assets')
    eq_(
        lines[1],
        '2/3 tests/test_data/assets/subdir/graph.jpg -> /content/dam/assets/subdir'
    )
    eq_(
        lines[2],
        '3/3 tests/test_data/assets/subdir/graph2.jpg -> /content/dam/assets/subdir'
    )
    eq_(OK, status)

    eq_(0, len(http_service.req_log))
    shutil.rmtree(lock_dir)
Esempio n. 4
0
def test_import_asset_directory(stderr, stdout):
    http_service = MockHttpService()

    lock_dir = tempfile.mkdtemp()
    with HTTMock(http_service):
        tool = AssetsTool()
        server = Server('localhost')
        status = tool.execute(server, [
            'assets', '--lock-dir={}'.format(lock_dir), 'import',
            'tests/test_data/assets'
        ])

    eq_('', stderr.getvalue())

    lines = stdout.getvalue().split('\n')
    eq_(4, len(lines))
    _is_valid_upload_line(lines[0], [
        '2016-11-25 13:12:01', '1/3',
        'tests/test_data/assets/logo.jpg -> /content/dam/assets', '0.0192'
    ])
    _is_valid_upload_line(lines[1], [
        '2016-11-25 13:12:01', '2/3',
        'tests/test_data/assets/subdir/graph.jpg -> /content/dam/assets/subdir',
        '0.0192'
    ])
    _is_valid_upload_line(lines[2], [
        '2016-11-25 13:12:01', '3/3',
        'tests/test_data/assets/subdir/graph2.jpg -> /content/dam/assets/subdir',
        '0.0192'
    ])

    eq_(OK, status)

    eq_(5, len(http_service.req_log))
    eq_(http_service.req_log[0].url,
        'http://localhost:4502/content/dam/assets')
    eq_(http_service.req_log[1].url,
        'http://localhost:4502/content/dam/assets.createasset.html')
    eq_(http_service.req_log[2].url,
        'http://localhost:4502/content/dam/assets/subdir')
    eq_(http_service.req_log[3].url,
        'http://localhost:4502/content/dam/assets/subdir.createasset.html')
    # Skipped creating subdir for the second file
    eq_(http_service.req_log[4].url,
        'http://localhost:4502/content/dam/assets/subdir.createasset.html')

    shutil.rmtree(lock_dir)
Esempio n. 5
0
def test_import_asset_file(stderr, stdout):
    http_service = MockHttpService()

    lock_dir = tempfile.mkdtemp()
    with HTTMock(http_service):
        tool = AssetsTool()
        server = Server('localhost')
        status = tool.execute(server, ['assets', 'import', 'tests/test_data/assets/logo.jpg'])

    eq_('', stderr.getvalue())
    eq_(stdout.getvalue(), 'tests/test_data/assets/logo.jpg -> /content/dam/assets\n')
    eq_(OK, status)

    eq_(2, len(http_service.req_log))
    eq_(http_service.req_log[0].url, 'http://localhost:4502/content/dam/assets')
    eq_(http_service.req_log[1].url, 'http://localhost:4502/content/dam/assets.createasset.html')

    shutil.rmtree(lock_dir)
Esempio n. 6
0
def test_dry_run_import_asset_directory(stderr, stdout):
    http_service = MockHttpService()
    eq_([], http_service.req_log)

    lock_dir = tempfile.mkdtemp()
    with HTTMock(http_service):
        tool = AssetsTool()
        server = Server('localhost')
        status = tool.execute(server, ['assets', '--dry-run', 'import',
                                       'tests/test_data/assets'])

    eq_('', stderr.getvalue())

    lines = stdout.getvalue().split('\n')
    eq_(4, len(lines))
    eq_(lines[0], 'tests/test_data/assets/logo.jpg -> /content/dam/assets')
    eq_(lines[1], 'tests/test_data/assets/subdir/graph.jpg -> /content/dam/assets/subdir')
    eq_(lines[2], 'tests/test_data/assets/subdir/graph2.jpg -> /content/dam/assets/subdir')

    eq_(OK, status)

    eq_([], http_service.req_log)
    shutil.rmtree(lock_dir)