def test_list_bundles(stdout): with HTTMock(service_mock): tool = tool_repo.get_tool("search") server = Server("localhost") tool.execute(server, ["search", "--path=/content", "--limit=3", "foo=bar"]) eq_(EXPECTED_LIST, stdout.getvalue())
def test_bad_command(stderr, stdout): tool = tool_repo.get_tool('bundle') server = Server('localhost') ret = tool.execute(server, ['bundle', 'foobar']) eq_('', stdout.getvalue()) eq_('error: Unknown bundle action foobar\n', stderr.getvalue()) eq_(-2, ret)
def test_list_tools(stderr, stdout): tool = tool_repo.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_('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_missing_file_param(stderr, stdout): tool = tool_repo.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 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 = tool_repo.get_tool(arg) _module = tool_repo.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_list_tools(stderr, stdout): tool = tool_repo.get_tool('help') server = Server('localhost') status = tool.execute(server, ['help', '--compact']) eq_('', stderr.getvalue()) lines = [x for x in stdout.getvalue().split('\n')] ok_(len(lines) > 5) ok_('bundle' in lines) ok_('cat' in lines) ok_('cp' in lines) ok_('find' in lines) ok_('groovy' in lines) ok_('group' in lines) ok_('help' in lines) ok_('install_bash_completion' in lines) ok_('ls' in lines) ok_('mv' in lines) ok_('package' in lines) ok_('rm' in lines) ok_('rmprop' in lines) ok_('search' in lines) ok_('setprop' in lines) ok_('storage' in lines) ok_('user' in lines) ok_('workflow' in lines) eq_(OK, status)
def test_print_help(stdout, stderr): tool = tool_repo.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 test_bad_command(stderr, stdout): tool = tool_repo.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_rm_stdin(stderr, stdout): with HTTMock(service_rm): tool = tool_repo.get_tool("rm") server = Server("localhost") status = tool.execute(server, ["rm"]) eq_(0, status) eq_("/content/path/node\n", stdout.getvalue())
def test_rmprop_stdin(stderr, stdout): with HTTMock(service_mock): tool = tool_repo.get_tool('rmprop') server = Server('localhost') status = tool.execute(server, ['rmprop', 'prop0,prop1']) eq_(0, status) eq_('/path0\n/path1\n', stdout.getvalue())
def test_rmprop(stderr, stdout): with HTTMock(service_mock): tool = tool_repo.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_list_bundles(stdout): with HTTMock(service_mock): tool = tool_repo.get_tool('search') server = Server('localhost') tool.execute(server, ['search', '--path=/content', '--limit=3', 'foo=bar']) eq_(EXPECTED_LIST, unordered_list(stdout.getvalue()))
def test_rm_stdin(stderr, stdout): with HTTMock(service_rm): tool = tool_repo.get_tool('rm') server = Server('localhost') status = tool.execute(server, ['rm']) eq_(0, status) eq_('/content/path/node\n', stdout.getvalue())
def test_run_tool(_, load_proj): _tool = tool_repo.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 = tool_repo.get_tool('mock_tool') eq_(True, _tool.did_run)
def test_list_users_compact(stderr, stdout): tool = tool_repo.get_tool('users') server = Server('localhost') with HTTMock(list_users_mock): status = tool.execute(server, ['users', 'list', '--compact']) eq_(OK, status) eq_(COMPACT_RESPONSE, stdout.getvalue()) eq_('', stderr.getvalue())
def test_create_group(stderr, stdout): tool = tool_repo.get_tool('group') server = Server('localhost') with HTTMock(service_mock): status = tool.execute(server, ['group', 'create', 'mynewgroup1711']) eq_(OK, status) eq_('/home/groups/m/mynewgroup1711\n', stdout.getvalue()) eq_('', stderr.getvalue())
def test_groups_users_compact(stderr, stdout): tool = tool_repo.get_tool('group') server = Server('localhost') with HTTMock(list_groups_mock): status = tool.execute(server, ['group', 'list', '--compact']) eq_(OK, status) eq_(COMPACT_GROUPS, unordered_list(stdout.getvalue())) eq_('', stderr.getvalue())
def test_ls_stdin(stderr, stdout): with HTTMock(service_mock): tool = tool_repo.get_tool('ls') server = Server('localhost') status = tool.execute(server, ['ls']) eq_(0, status) eq_({'node', 'directory'}, unordered_list(stdout.getvalue())) eq_('', stderr.getvalue())
def test_set_property(stderr, stdout): tool = tool_repo.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_ls_stdin(stderr, stdout): with HTTMock(service_mock): tool = tool_repo.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_create_user(stderr, stdout): tool = tool_repo.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_list_users(stderr, stdout): tool = tool_repo.get_tool('user') server = Server('localhost') with HTTMock(list_users_mock): status = tool.execute(server, ['user', 'list']) eq_(OK, status) eq_(EXPECTED_RESPONSE, unordered_list(stdout.getvalue())) eq_('', stderr.getvalue())
def test_add_user(stderr, stdout): tool = tool_repo.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_groups_users(stderr, stdout): tool = tool_repo.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_ls(stderr, stdout): with HTTMock(service_mock): tool = tool_repo.get_tool('ls') server = Server('localhost') status = tool.execute(server, ['ls', '/content/path']) eq_(0, status) eq_({'node', 'directory', ''}, set(stdout.getvalue().split('\n'))) eq_('', stderr.getvalue())
def test_script_error(stderr, stdout): with HTTMock(script_error_service): tool = tool_repo.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_file_does_not_exist(stderr, stdout): tool = tool_repo.get_tool('config') server = Server('localhost') ret = tool.execute(server, ['config', 'encrypt', '-f', 'thisisnotafile', 'localhost']) eq_(USER_ERROR, ret) eq_('error: Requested file thisisnotafile does not exist\n', stderr.getvalue()) eq_('', stdout.getvalue())
def test_create_group(stderr, stdout): tool = tool_repo.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_find_stdin(stderr, stdout): with HTTMock(service_mock): tool = tool_repo.get_tool('find') server = Server('localhost') status = tool.execute(server, ['find']) eq_(0, status) eq_({'/content', '/content/path', '/content/path/node', '/content/path/directory'}, unordered_list(stdout.getvalue())) eq_('', stderr.getvalue())
def test_cat_stdin(stderr, stdout): with HTTMock(service_mock): tool = tool_repo.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 test_find_stdin(stderr, stdout): with HTTMock(service_mock): tool = tool_repo.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_execute(stderr, stdout): with HTTMock(service_mock): tool = tool_repo.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_execute_raw_output(stderr, stdout): with HTTMock(service_mock): tool = tool_repo.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_add_user(stderr, stdout): tool = tool_repo.get_tool('group') server = Server('localhost') with HTTMock(adduser_mock): status = tool.execute(server, ['group', 'adduser', 'mynewgroup1711', 'jdoe']) eq_(OK, status) eq_('/home/groups/m/mynewgroup1711\n', stdout.getvalue()) eq_('', stderr.getvalue())
def test_execute_raw_output(stderr, stdout): with HTTMock(service_mock): tool = tool_repo.get_tool('groovy') server = Server('localhost') status = tool.execute( server, ['groovy', '--raw', 'tests/test_data/script.groovy']) eq_(0, status) eq_(EXPECTED_OUT, json.loads(stdout.getvalue())) eq_('', stderr.getvalue())
def test_create_user(stderr, stdout): tool = tool_repo.get_tool('user') server = Server('localhost') with HTTMock(create_service_mock): status = tool.execute(server, ['user', 'create', '--password=passwd', 'jdoe']) eq_(OK, status) eq_('/home/users/j/jdoe\n', stdout.getvalue()) eq_('', stderr.getvalue())
def test_error_response(stderr, stdout): with HTTMock(broken_service): tool = tool_repo.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_no_server_argument(stderr, stdout): _, tmp_filepath = tempfile.mkstemp(".rc") tool = tool_repo.get_tool('config') server = Server('localhost') ret = tool.execute(server, ['config', 'encrypt', '-f', tmp_filepath]) eq_(USER_ERROR, ret) eq_('', stdout.getvalue()) eq_('error: Missing server name argument\n', stderr.getvalue())
def test_print_help(stderr, stdout): tool = tool_repo.get_tool('groups') server = Server('localhost') try: status = tool.execute(server, ['groups', '--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 = tool_repo.get_tool('user') server = Server('localhost') with HTTMock(setprop_service_mock): status = tool.execute( server, ['user', 'setprop', 'jdoe', 'prop0=val0,prop1="Quoted value"']) eq_(OK, status) eq_('/home/users/j/jdoe\n', stdout.getvalue()) eq_('', stderr.getvalue())
def test_print_help(stderr, stdout): tool = tool_repo.get_tool('user') server = Server('localhost') try: status = tool.execute(server, ['user', '--help']) except SystemExit as e: status = e.code eq_(0, status) ok_(len(stdout.getvalue()) > 0) eq_('', stderr.getvalue())
def test_download(stderr, stdout): with HTTMock(packages_mock): tool = tool_repo.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_download(stderr, stdout): with HTTMock(packages_mock): tool = tool_repo.get_tool('package') server = Server('localhost') status = tool.execute(server, ['package', '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_command_does_not_exist(stderr, stdout): _, tmp_filepath = tempfile.mkstemp(".rc") tool = tool_repo.get_tool('config') server = Server('localhost') ret = tool.execute(server, ['config', 'somethingelse', '-f', tmp_filepath]) eq_(USER_ERROR, ret) eq_("error: Unknown command 'somethingelse'\n", stderr.getvalue()) eq_('', stdout.getvalue()) os.remove(tmp_filepath)
def test_build_package(stderr, stdout): with HTTMock(packages_mock): tool = tool_repo.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 test_error_response(stderr, stdout): with HTTMock(broken_service): tool = tool_repo.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_format_config(): tmp_filepath = create_config() tool = tool_repo.get_tool('config') server = Server('localhost') ret = tool.execute(server, ['config', 'format', '-f', tmp_filepath]) eq_(OK, ret) new_config = load_config(tmp_filepath) eq_(PLAINTEXT_CONFIG, new_config) os.remove(tmp_filepath)
def test_mv(stderr, stdout): service_mock = MockHttpService() with HTTMock(service_mock): tool = tool_repo.get_tool('mv') server = Server('localhost') status = tool.execute(server, ['mv', '/content/src_node', '/content/dst_node']) eq_(0, status) eq_('/content/dst_node\n', stdout.getvalue()) eq_(1, len(service_mock.req_log)) eq_('/content/src_node', service_mock.url_log[0].path) eq_('%3Aoperation=move&%3Adest=%2Fcontent%2Fdst_node', service_mock.req_log[0].body)
def test_setprop_stdin(_, stdout): service_mock = MockHttpService() with HTTMock(service_mock): tool = tool_repo.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()) eq_(2, len(service_mock.req_log)) eq_({('prop1', 'value1'), ('prop0', 'value0')}, set(service_mock.req_log[0].body.fields))
def test_start_workflow(stderr, stdout): wf_service = MockWorkflowsService() service = MockHttpService(wf_service) with HTTMock(service): tool = tool_repo.get_tool('workflows') server = Server('localhost') status = tool.execute(server, ['workflows', 'start', '/dam/update_asset', '/content/dam/something/image.png']) eq_('', stderr.getvalue()) eq_(stdout.getvalue().startswith('/dam/update_asset-'), True) eq_(0, status)
def test_stop_bundle(stderr, stdout): global _expected_action _expected_action = 'stop' with HTTMock(mock_bundle): tool = tool_repo.get_tool('bundles') server = Server('localhost') ret = tool.execute(server, ['bundles', 'stop', 'mock_bundle']) eq_('', stdout.getvalue()) eq_('', stderr.getvalue()) eq_(None, ret) ret = tool.execute(server, ['bundles', 'stop', '--raw', 'mock_bundle']) eq_('{"fragment":false,"stateRaw":4}\n', stdout.getvalue()) eq_('', stderr.getvalue()) eq_(None, ret)
def test_list_servers(stderr, stdout): config = acmd.config.Config() config.servers['server1'] = Server('server1') config.servers['server2'] = Server('server2') config.servers['server3'] = Server('server3') acmd.config._current_config = config tool = tool_repo.get_tool('help') server = Server('localhost') status = tool.execute(server, ['help', '_servers']) lines = [x.strip() for x in stdout.getvalue().split('\n')] eq_('server1', lines[0]) eq_('server2', lines[1]) eq_('server3', lines[2]) eq_(OK, status)
def test_list_workflows(stderr, stdout): task_service = MockWorkflowsService() task_service.add_workflow('dam/update_asset') task_service.add_workflow('dam/update_asset') task_service.add_workflow('something_else') service = MockHttpService(task_service) with HTTMock(service): tool = tool_repo.get_tool('workflows') server = Server('localhost') status = tool.execute(server, ['workflows', 'ls']) lines = [ ['dam/update_asset'], ['dam/update_asset'], ['something_else'], ] eq_('', stderr.getvalue()) eq_(tabbed(lines), stdout.getvalue()) eq_(0, status)
def test_tool_registration(): tool = tool_repo.get_tool('bundles') assert tool is not None
def test_bad_command(stderr, stdout): tool = tool_repo.get_tool('packages') server = Server('localhost') status = tool.execute(server, ['packages', 'nonexisting', 'mock_package']) eq_(USER_ERROR, status)