Exemplo n.º 1
0
def test_rcp_create_flags(stderr, stdout):

    service = MockHttpService()

    with HTTMock(service):
        tool = get_tool('rcp')
        server = Server('localhost')
        status = tool.execute(server, [
            'rcp', 'create', '-s', 'other-host:4502', '-c', 'user:pass',
            '--new-only', '/content/dam/data'
        ])

        eq_(0, status)
        eq_(False, service.data_log[0]['update'])
        eq_(True, service.data_log[0]['onlyNewer'])
        eq_(2048, service.data_log[0]['batchsize'])
        eq_(1, service.data_log[0]['throttle'])

    service = MockHttpService()

    with HTTMock(service):
        tool = get_tool('rcp')
        server = Server('localhost')
        status = tool.execute(server, [
            'rcp', 'create', '-s', 'other-host:4502', '-c', 'user:pass',
            '--ignore-modified', '--throttle=7', '--batch-size=4711',
            '/content/dam/data'
        ])

        eq_(0, status)
        eq_(True, service.data_log[0]['update'])
        eq_(False, service.data_log[0]['onlyNewer'])
        eq_(4711, service.data_log[0]['batchsize'])
        eq_(7, service.data_log[0]['throttle'])
Exemplo n.º 2
0
def test_bad_command(stderr, stdout):
    tool = get_tool('bundles')
    server = Server('localhost')
    ret = tool.execute(server, ['bundles', 'foobar'])
    eq_('', stdout.getvalue())
    eq_('error: Unknown bundles action foobar\n', stderr.getvalue())
    eq_(-2, ret)
Exemplo n.º 3
0
def test_activate(stderr, stdout):
    with HTTMock(mock_replication_service):
        tool = get_tool('replication')
        server = Server('localhost')
        tool.execute(server, ['replication', 'activate', '/content/catalog'])
        eq_(EXPECTED, stdout.getvalue())
        eq_('', stderr.getvalue())
Exemplo n.º 4
0
def test_rm_stdin(stderr, stdout):
    with HTTMock(service_rm):
        tool = get_tool('rm')
        server = Server('localhost')
        status = tool.execute(server, ['rm'])
        eq_(0, status)
        eq_('/content/path/node\n', stdout.getvalue())
Exemplo n.º 5
0
def test_bad_command(stderr, stdout):
    tool = get_tool('bundles')
    server = Server('localhost')
    ret = tool.execute(server, ['bundles', 'foobar'])
    eq_('', stdout.getvalue())
    eq_('error: Unknown bundles action foobar\n', stderr.getvalue())
    eq_(-2, ret)
Exemplo n.º 6
0
def test_missing_file_param(stderr, stdout):
    tool = get_tool('groovy')
    server = Server('localhost')
    status = tool.execute(server, ['groovy'])
    eq_(USER_ERROR, status)
    ok_(stdout.getvalue().startswith('Usage: acmd groups'))
    eq_('', stderr.getvalue())
Exemplo n.º 7
0
def test_clear_cache_with_broken_service(stderr, stdout):
    tool = get_tool('dispatcher')
    server = Server('localhost', host='aslkadlkjasd', dispatcher="http://localhost")
    with HTTMock(broken_service):
        tool.execute(server, ['dispatcher', 'clear'])
    eq_('', stdout.getvalue())
    eq_("error: Failed to validate response 'Something went wrong'\n", stderr.getvalue())
Exemplo n.º 8
0
def test_activate(stderr, stdout):
    with HTTMock(mock_replication_service):
        tool = get_tool('replication')
        server = Server('localhost')
        tool.execute(server, ['replication', 'activate', '/content/catalog'])
        eq_(EXPECTED, stdout.getvalue())
        eq_('', stderr.getvalue())
Exemplo n.º 9
0
def test_clear_cache_with_explicit_dispatcher(stderr, stdout):
    tool = get_tool('dispatcher')
    server = Server('localhost', host='http://doesntexist', dispatcher="http://localhost")
    with HTTMock(service_mock):
        tool.execute(server, ['dispatcher', 'clear'])
    eq_("OK\n", stdout.getvalue())
    eq_('', stderr.getvalue())
Exemplo n.º 10
0
def test_clear_cache_with_raw_output(stderr, stdout):
    tool = get_tool('dispatcher')
    server = Server('localhost', host='aslkadlkjasd', dispatcher="http://localhost")
    with HTTMock(service_mock):
        tool.execute(server, ['dispatcher', 'clear', '--raw'])
    eq_("<H1>OK</H1>\n\n", stdout.getvalue())
    eq_('', stderr.getvalue())
Exemplo n.º 11
0
def test_clear_cache(stderr, stdout):
    tool = get_tool('dispatcher')
    server = Server('localhost')
    with HTTMock(service_mock):
        tool.execute(server, ['dispatcher', 'clear'])
    eq_("OK\n", stdout.getvalue())
    eq_('', stderr.getvalue())
Exemplo n.º 12
0
def test_print_help(stdout, stderr):
    tool = get_tool('storage')
    server = Server('localhost')
    tool.execute(server, ['storage'])
    eq_('', stdout.getvalue())
    eq_('Usage: acmd storage [options] optimize|gc',
        stderr.getvalue().split('\n')[0])
Exemplo n.º 13
0
    def execute(_, argv):
        (options, args) = parser.parse_args(argv)

        arg = get_command(args, '_tools')
        if arg == '_tools':
            print_tools(sys.stdout, options.compact)
        elif arg == '_servers':
            print_servers(sys.stdout)
        else:
            _tool = get_tool(arg)
            _module = get_module(arg)
            if _tool is None:
                error("No tool named {} found".format(arg))
                print_tools(sys.stderr, options.compact)
                return USER_ERROR
            if options.compact:
                for cmd in _tool.commands:
                    sys.stdout.write("{}\n".format(cmd))
            else:
                if hasattr(_module, 'parser'):
                    _module.parser.print_help()
                else:
                    sys.stdout.write("Available commands:\n")
                    for cmd in _tool.commands:
                        sys.stdout.write("\t{}\n".format(cmd))
        return OK
Exemplo n.º 14
0
def test_setprop_stdin(stderr, stdout):
    with HTTMock(service_mock):
        tool = get_tool('setprop')
        server = Server('localhost')
        status = tool.execute(server, ['setprop', 'prop0=value0,prop1=value1'])
        eq_(0, status)
        eq_('/path0\n/path1\n', stdout.getvalue())
Exemplo n.º 15
0
def test_rcp_ls(stderr, stdout):
    task_service = MockTaskService()
    task_service.create_task('task_id_4711', '/content/dam/something')
    task_service.create_task('task_id_4712', '/content/dam/something_else',
                             '/content/dam/new target')
    task_service.start_task('task_id_4711')

    service = MockHttpService(task_service)

    with HTTMock(service):
        tool = get_tool('rcp')
        server = Server('localhost')
        status = tool.execute(server, ['ls'])
        eq_(0, status)
        lines = [[
            'task_id_4711', 'localhost:4503/content/dam/something',
            '/content/dam/something', 'FINISHED'
        ],
                 [
                     'task_id_4712',
                     'localhost:4503/content/dam/something_else',
                     '/content/dam/new target', 'NEW'
                 ]]
        eq_(tabbed(lines), stdout.getvalue())
        eq_('', stderr.getvalue())
Exemplo n.º 16
0
def test_setprop_stdin(stderr, stdout):
    with HTTMock(service_mock):
        tool = get_tool('setprop')
        server = Server('localhost')
        status = tool.execute(server, ['setprop', 'prop0=value0,prop1=value1'])
        eq_(0, status)
        eq_('/path0\n/path1\n', stdout.getvalue())
Exemplo n.º 17
0
def test_missing_file_param(stderr, stdout):
    tool = get_tool('groovy')
    server = Server('localhost')
    status = tool.execute(server, ['groovy'])
    eq_(USER_ERROR, status)
    ok_(stdout.getvalue().startswith('Usage: acmd groups'))
    eq_('', stderr.getvalue())
Exemplo n.º 18
0
def test_list_tools(stderr, stdout):
    tool = get_tool('help')
    server = Server('localhost')
    status = tool.execute(server, ['help', '--compact'])

    lines = [x for x in stdout.getvalue().split('\n')]
    ok_(len(lines) > 5)
    ok_('bundles' in lines)
    ok_('cat' in lines)
    ok_('cp' in lines)
    ok_('dispatcher' in lines)
    ok_('find' in lines)
    ok_('groovy' in lines)
    ok_('groups' in lines)
    ok_('help' in lines)
    ok_('install_bash_completion' in lines)
    ok_('jobs' in lines)
    ok_('ls' in lines)
    ok_('mv' in lines)
    ok_('packages' in lines)
    ok_('rcp' in lines)
    ok_('rm' in lines)
    ok_('rmprop' in lines)
    ok_('search' in lines)
    ok_('setprop' in lines)
    ok_('storage' in lines)
    ok_('users' in lines)
    ok_('workflows' in lines)
    eq_(OK, status)
Exemplo n.º 19
0
def test_run_tool(deploy_bash, load_proj):
    _tool = get_tool('mock_tool')
    eq_(False, _tool.did_run)

    args = ['acmd', 'mock_tool']
    try:
        exit_code = 0
        main(args)
    except SystemExit as e:
        exit_code = e.code
    eq_(1147, exit_code)

    eq_(True, load_proj.called)

    _tool = get_tool('mock_tool')
    eq_(True, _tool.did_run)
Exemplo n.º 20
0
def test_list_bundles(stdout):
    with HTTMock(service_mock):
        tool = get_tool('search')
        server = Server('localhost')

        tool.execute(server, ['search', '--path=/content', '--limit=3', 'foo=bar'])
        eq_(EXPECTED_LIST, stdout.getvalue())
Exemplo n.º 21
0
def test_rm_stdin(stderr, stdout):
    with HTTMock(service_rm):
        tool = get_tool('rm')
        server = Server('localhost')
        status = tool.execute(server, ['rm'])
        eq_(0, status)
        eq_('/content/path/node\n', stdout.getvalue())
Exemplo n.º 22
0
def test_rmprop(stderr, stdout):
    with HTTMock(service_mock):
        tool = get_tool('rmprop')
        server = Server('localhost')
        status = tool.execute(server, ['rmprop', 'prop0,prop1', '/content/path/node'])
        eq_(0, status)
        eq_('/content/path/node\n', stdout.getvalue())
Exemplo n.º 23
0
def test_run_tool(deploy_bash, load_proj):
    _tool = get_tool('mock_tool')
    eq_(False, _tool.did_run)

    args = ['acmd', 'mock_tool']
    try:
        exit_code = 0
        main(args)
    except SystemExit as e:
        exit_code = e.code
    eq_(1147, exit_code)

    eq_(True, load_proj.called)
    
    _tool = get_tool('mock_tool')
    eq_(True, _tool.did_run)
Exemplo n.º 24
0
def test_groups_users(stderr, stdout):
    tool = get_tool('groups')
    server = Server('localhost')
    with HTTMock(list_groups_mock):
        status = tool.execute(server, ['groups', 'list'])
    eq_(OK, status)
    eq_(EXPECTED_GROUPS, stdout.getvalue())
    eq_('', stderr.getvalue())
Exemplo n.º 25
0
def test_add_user(stderr, stdout):
    tool = get_tool('groups')
    server = Server('localhost')
    with HTTMock(adduser_mock):
        status = tool.execute(server, ['groups', 'adduser', 'mynewgroup1711', 'jdoe'])
    eq_(OK, status)
    eq_('/home/groups/m/mynewgroup1711\n', stdout.getvalue())
    eq_('', stderr.getvalue())
Exemplo n.º 26
0
def test_ls_stdin(stderr, stdout):
    with HTTMock(service_mock):
        tool = get_tool("ls")
        server = Server("localhost")
        status = tool.execute(server, ["ls"])
        eq_(0, status)
        eq_("node\ndirectory\n", stdout.getvalue())
        eq_("", stderr.getvalue())
Exemplo n.º 27
0
def test_script_error(stderr, stdout):
    with HTTMock(script_error_service):
        tool = get_tool('groovy')
        server = Server('localhost')
        status = tool.execute(server, ['groovy', 'tests/test_data/script.groovy'])
        eq_(SERVER_ERROR, status)
        eq_('', stdout.getvalue())
        eq_('Stacktrace Message', stderr.getvalue())
Exemplo n.º 28
0
def test_create_group(stderr, stdout):
    tool = get_tool('groups')
    server = Server('localhost')
    with HTTMock(service_mock):
        status = tool.execute(server, ['groups', 'create', 'mynewgroup1711'])
    eq_(OK, status)
    eq_('/home/groups/m/mynewgroup1711\n', stdout.getvalue())
    eq_('', stderr.getvalue())
Exemplo n.º 29
0
def test_create_user(stderr, stdout):
    tool = get_tool('users')
    server = Server('localhost')
    with HTTMock(create_service_mock):
        status = tool.execute(server, ['users', 'create', '--password=passwd', 'jdoe'])
    eq_(OK, status)
    eq_('/home/users/j/jdoe\n', stdout.getvalue())
    eq_('', stderr.getvalue())
Exemplo n.º 30
0
def test_set_property(stderr, stdout):
    tool = get_tool('users')
    server = Server('localhost')
    with HTTMock(setprop_service_mock):
        status = tool.execute(server, ['users', 'setprop', 'jdoe', 'prop0=val0,prop1="Quoted value"'])
    eq_(OK, status)
    eq_('/home/users/j/jdoe\n', stdout.getvalue())
    eq_('', stderr.getvalue())
Exemplo n.º 31
0
def test_list_users(stderr, stdout):
    tool = get_tool('users')
    server = Server('localhost')
    with HTTMock(list_users_mock):
        status = tool.execute(server, ['users', 'list'])
    eq_(OK, status)
    eq_(EXPECTED_RESPONSE, stdout.getvalue())
    eq_('', stderr.getvalue())
Exemplo n.º 32
0
def test_list_users(stderr, stdout):
    tool = get_tool('users')
    server = Server('localhost')
    with HTTMock(list_users_mock):
        status = tool.execute(server, ['users', 'list'])
    eq_(OK, status)
    eq_(EXPECTED_RESPONSE, stdout.getvalue())
    eq_('', stderr.getvalue())
Exemplo n.º 33
0
def test_rmprop(stderr, stdout):
    with HTTMock(service_mock):
        tool = get_tool('rmprop')
        server = Server('localhost')
        status = tool.execute(server,
                              ['rmprop', 'prop0,prop1', '/content/path/node'])
        eq_(0, status)
        eq_('/content/path/node\n', stdout.getvalue())
Exemplo n.º 34
0
def test_execute(stderr, stdout):
    with HTTMock(service_mock):
        tool = get_tool('groovy')
        server = Server('localhost')
        status = tool.execute(server,
                              ['groovy', 'tests/test_data/script.groovy'])
        eq_(0, status)
        eq_('foo\n', stdout.getvalue())
        eq_('', stderr.getvalue())
Exemplo n.º 35
0
def test_script_error(stderr, stdout):
    with HTTMock(script_error_service):
        tool = get_tool('groovy')
        server = Server('localhost')
        status = tool.execute(server,
                              ['groovy', 'tests/test_data/script.groovy'])
        eq_(SERVER_ERROR, status)
        eq_('', stdout.getvalue())
        eq_('Stacktrace Message', stderr.getvalue())
Exemplo n.º 36
0
def test_create_user(stderr, stdout):
    tool = get_tool('users')
    server = Server('localhost')
    with HTTMock(create_service_mock):
        status = tool.execute(server,
                              ['users', 'create', '--password=passwd', 'jdoe'])
    eq_(OK, status)
    eq_('/home/users/j/jdoe\n', stdout.getvalue())
    eq_('', stderr.getvalue())
Exemplo n.º 37
0
def test_cat_stdin(stderr, stdout):
    with HTTMock(service_mock):
        tool = get_tool('cat')
        server = Server('localhost')
        status = tool.execute(server, ['cat'])
        eq_(0, status)
        eq_('text:\tSomething something\njcr:primaryType:\tnt:unstructured\ntitle:\tTest Title\n',
            stdout.getvalue())
        eq_('', stderr.getvalue())
Exemplo n.º 38
0
def split_argv(argv):
    """ Split argument list into system arguments before the tool
        and tool arguments afterwards.
        ['foo', 'bar', 'inspect', 'bink', 'bonk']
            => (['foo', 'bar', 'inspect'], ['inspect', 'bink', 'bonk'])"""
    for i, arg in enumerate(argv):
        if acmd.get_tool(arg) is not None:
            return argv[0:i + 1], argv[i:]
    return argv, []
Exemplo n.º 39
0
def test_execute_raw_output(stderr, stdout):
    with HTTMock(service_mock):
        tool = get_tool('groovy')
        server = Server('localhost')
        status = tool.execute(
            server, ['groovy', '--raw', 'tests/test_data/script.groovy'])
        eq_(0, status)
        eq_(EXPECTED_RAW_OUTPUT, stdout.getvalue())
        eq_('', stderr.getvalue())
Exemplo n.º 40
0
def test_execute(stderr, stdout):
    with HTTMock(service_mock):
        tool = get_tool('groovy')
        server = Server('localhost')
        status = tool.execute(server, ['groovy', 'tests/test_data/script.groovy'])
        eq_(0, status)
        eq_('foo\n',
            stdout.getvalue())
        eq_('', stderr.getvalue())
Exemplo n.º 41
0
def test_find_stdin(stderr, stdout):
    with HTTMock(service_mock):
        tool = get_tool('find')
        server = Server('localhost')
        status = tool.execute(server, ['find'])
        eq_(0, status)
        eq_('/content\n/content/path\n/content/path/node\n/content/path/directory\n',
            stdout.getvalue())
        eq_('', stderr.getvalue())
Exemplo n.º 42
0
def test_error_response(stderr, stdout):
    with HTTMock(broken_service):
        tool = get_tool('groovy')
        server = Server('localhost')
        status = tool.execute(server, ['groovy', 'tests/test_data/script.groovy'])
        eq_(SERVER_ERROR, status)
        eq_('',
            stdout.getvalue())
        eq_('error: Failed to run script tests/test_data/script.groovy: error message\n', stderr.getvalue())
Exemplo n.º 43
0
def test_execute_raw_output(stderr, stdout):
    with HTTMock(service_mock):
        tool = get_tool('groovy')
        server = Server('localhost')
        status = tool.execute(server, ['groovy', '--raw', 'tests/test_data/script.groovy'])
        eq_(0, status)
        eq_(EXPECTED_RAW_OUTPUT,
            stdout.getvalue())
        eq_('', stderr.getvalue())
Exemplo n.º 44
0
def test_print_help(stderr, stdout):
    tool = get_tool('users')
    server = Server('localhost')
    try:
        tool.execute(server, ['users', '--help'])
    except SystemExit as e:
        status = e.code
    eq_(0, status)
    ok_(len(stdout.getvalue()) > 0)
    eq_('', stderr.getvalue())
Exemplo n.º 45
0
def test_set_property(stderr, stdout):
    tool = get_tool('users')
    server = Server('localhost')
    with HTTMock(setprop_service_mock):
        status = tool.execute(
            server,
            ['users', 'setprop', 'jdoe', 'prop0=val0,prop1="Quoted value"'])
    eq_(OK, status)
    eq_('/home/users/j/jdoe\n', stdout.getvalue())
    eq_('', stderr.getvalue())
Exemplo n.º 46
0
def test_download(stderr, stdout):
    with HTTMock(packages_mock):
        tool = get_tool('packages')
        server = Server('localhost')
        status = tool.execute(server, ['packages', 'download', 'mock_package'])
    eq_(0, status)
    eq_('mock_package-1.6.5.zip\n', stdout.getvalue())
    eq_('', stderr.getvalue())
    url, request = get_command_stack()[-1]
    eq_('/etc/packages/test_packages/mock_package-1.6.5.zip', url.path)
Exemplo n.º 47
0
def test_print_help(stderr, stdout):
    tool = get_tool('users')
    server = Server('localhost')
    try:
        tool.execute(server, ['users', '--help'])
    except SystemExit as e:
        status = e.code
    eq_(0, status)
    ok_(len(stdout.getvalue()) > 0)
    eq_('', stderr.getvalue())
Exemplo n.º 48
0
def test_download(stderr, stdout):
    with HTTMock(packages_mock):
        tool = get_tool('packages')
        server = Server('localhost')
        status = tool.execute(server, ['packages', 'download', 'mock_package'])
    eq_(0, status)
    eq_('mock_package-1.6.5.zip\n', stdout.getvalue())
    eq_('', stderr.getvalue())
    url, request = get_command_stack()[-1]
    eq_('/etc/packages/test_packages/mock_package-1.6.5.zip', url.path)
Exemplo n.º 49
0
def test_build_package(stderr, stdout):
    with HTTMock(packages_mock):
        tool = get_tool('packages')
        server = Server('localhost')
        status = tool.execute(server, ['packages', 'build', 'mock_package'])
        eq_(0, status)
        eq_('', stdout.getvalue())
        eq_('', stderr.getvalue())
        url, request = get_command_stack()[-1]
        eq_('/crx/packmgr/service/.json/etc/packages/test_packages/mock_package-1.6.5.zip', url.path)
        eq_('cmd=build', request.body)
Exemplo n.º 50
0
def run(options, config, args, cmdargs):
    tool_name, args = args[1], []
    server = config.get_server(options.server)
    if server is None:
        sys.stderr.write("error: server '{srv}' not found.\n".format(srv=options.server))
        return acmd.USER_ERROR
    acmd.log("Using server {}".format(server))
    cmd = acmd.get_tool(tool_name)
    if cmd is None:
        sys.stderr.write("error: tool '{cmd}' not found.\n".format(cmd=tool_name))
        return acmd.USER_ERROR
    else:
        return cmd.execute(server, cmdargs)