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'])
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)
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())
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())
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())
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())
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())
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())
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())
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])
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
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())
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())
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)
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)
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())
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())
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())
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())
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())
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())
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())
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())
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())
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())
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())
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())
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, []
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())
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())
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())
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())
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())
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())
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)
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)
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)