diff --git a/fuelclient/cli/arguments.py b/fuelclient/cli/arguments.py index 8ee8b07..e106bc6 100644 --- a/fuelclient/cli/arguments.py +++ b/fuelclient/cli/arguments.py @@ -44,6 +44,15 @@ def group(*args, **kwargs): return (required, ) + args +class TaskAction(argparse.Action): + """Custom argparse.Action subclass to store task ids + + :returns: list of ids + """ + def __call__(self, parser, namespace, values, option_string=None): + setattr(namespace, self.dest, map(int, chain(*values))) + + class NodeAction(argparse.Action): """Custom argparse.Action subclass to store node identity @@ -102,20 +111,6 @@ class SetAction(argparse.Action): setattr(namespace, self.dest, set(values)) -def parse_ids(x): - """Parse arguments with commas and spaces - - :returns: list of lists with numbers - """ - filtered = [y for y in x.split(",") if y.strip() != ''] - if len(filtered) > 1: - return map(int, filtered) - elif len(filtered) == 1: - return [int(filtered[0])] - else: - return None - - def get_serializer_arg(serialization_method): return { "args": ["--{0}".format(serialization_method)], @@ -218,17 +213,6 @@ def get_int_arg(name, **kwargs): return get_arg(name, **default_kwargs) -def get_multinum_arg(name, **kwargs): - default_kwargs = { - "action": "store", - "type": parse_ids, - "nargs": '+', - "default": None - } - default_kwargs.update(kwargs) - return get_arg(name, **default_kwargs) - - def get_set_type_arg(name, **kwargs): default_kwargs = { "type": lambda v: v.split(','), @@ -362,10 +346,15 @@ def get_node_arg(help_msg): def get_task_arg(help_msg): - return get_multinum_arg( - "task", - flags=("--tid", "--task-id"), - help=help_msg) + default_kwargs = { + "action": TaskAction, + "flags": ("--tid", "--task-id"), + "nargs": '+', + "type": lambda v: v.split(","), + "default": None, + "help": help_msg + } + return get_arg("task", **default_kwargs) def get_config_arg(help_msg): diff --git a/tests/base.py b/tests/base.py index 68d2493..a800d99 100644 --- a/tests/base.py +++ b/tests/base.py @@ -84,7 +84,7 @@ class BaseTestCase(TestCase): print("Running " + " ".join(args)) handle.wait() - def run_cli_command(self, command_line, with_erros=False): + def run_cli_command(self, command_line, check_errors=False): modified_env = os.environ.copy() modified_env["LISTEN_PORT"] = "8003" command_args = [" ".join((self.fuel_path, command_line))] @@ -100,17 +100,17 @@ class BaseTestCase(TestCase): result = CliExectutionResult(process_handle) log.debug("command_args: '%s',stdout: '%s', stderr: '%s'", command_args[0], result.stdout, result.stderr) - if not with_erros: + if not check_errors: if not result.is_return_code_zero or result.has_errors: self.fail() return result - def run_cli_commands(self, command_lines, with_erros=False): + def run_cli_commands(self, command_lines, **kwargs): for command in command_lines: - self.run_cli_command(command, with_erros=with_erros) + self.run_cli_command(command, **kwargs) def check_if_required(self, command): - call = self.run_cli_command(command, with_erros=True) + call = self.run_cli_command(command, check_errors=True) #should not work without env id self.assertIn("required", call.stderr) @@ -118,10 +118,10 @@ class BaseTestCase(TestCase): call = self.run_cli_command(command) self.assertEqual(call.stdout, msg) - def check_all_in_msg(self, command, substrs): - output = self.run_cli_command(command) - for substr in substrs: - self.assertIn(substr, output.stdout) + def check_all_in_msg(self, command, substrings, **kwargs): + output = self.run_cli_command(command, **kwargs) + for substring in substrings: + self.assertIn(substring, output.stdout) def check_for_rows_in_table(self, command): output = self.run_cli_command(command) diff --git a/tests/test_client.py b/tests/test_client.py index 9ec3fae..89ca51b 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -100,6 +100,32 @@ class TestHandlers(BaseTestCase): for action in actions: self.check_all_in_msg("{0} -h".format(action), ("Examples",)) + def test_task_action_urls(self): + self.check_all_in_msg( + "task --task-id 1 --debug", + [ + "GET http://127.0.0.1", + "/api/v1/tasks/1/" + ], + check_errors=True + ) + self.check_all_in_msg( + "task --task-id 1 --delete --debug", + [ + "DELETE http://127.0.0.1", + "/api/v1/tasks/1/?force=0" + ], + check_errors=True + ) + self.check_all_in_msg( + "task --task-id 1 --delete --force --debug", + [ + "DELETE http://127.0.0.1", + "/api/v1/tasks/1/?force=1" + ], + check_errors=True + ) + class TestFiles(BaseTestCase):