Pass on all unhandled options 27/35227/4
authorTaseer Ahmed <taseer94@gmail.com>
Tue, 23 May 2017 16:42:40 +0000 (21:42 +0500)
committerTaseer Ahmed <taseer94@gmail.com>
Mon, 29 May 2017 16:58:20 +0000 (21:58 +0500)
Change-Id: Ic86002732c87d3b4ac5b5b3b664f116354d4bf9d
Signed-off-by: Taseer Ahmed <taseer94@gmail.com>
qtip/cli/commands/cmd_project.py
qtip/runner/project.py
tests/unit/cli/cmd_project_test.py [new file with mode: 0644]

index 42fd000..740fb1c 100644 (file)
@@ -15,6 +15,9 @@ from qtip.cli import utils
 from qtip.runner import project
 
 
+CONTEXT_SETTINGS = dict(ignore_unknown_options=True, allow_extra_args=True, )
+
+
 class AliasedGroup(click.Group):
 
     def get_command(self, ctx, cmd_name):
@@ -60,16 +63,19 @@ def create(pod, installer, master_host, scenario, name):
                         extra_vars=utils.join_vars(**extra_vars)))
 
 
-@cli.command(help='Setup testing environment')
-def setup():
-    project.setup()
+@cli.command(context_settings=CONTEXT_SETTINGS, help='Setup testing environment')
+@click.pass_context
+def setup(ctx):
+    project.setup(ctx.args)
 
 
-@cli.command(help='Execute testing plan')
-def run():
-    project.run()
+@cli.command(context_settings=CONTEXT_SETTINGS, help='Execute testing plan')
+@click.pass_context
+def run(ctx):
+    project.run(ctx.args)
 
 
-@cli.command(help='Teardown testing environment')
-def teardown():
-    project.teardown()
+@cli.command(context_settings=CONTEXT_SETTINGS, help='Teardown testing environment')
+@click.pass_context
+def teardown(ctx):
+    project.teardown(ctx.args)
index 9eadc9d..90d1e07 100644 (file)
 import os
 
 
-def setup():
-    os.system('ansible-playbook setup.yml')
+def convert(vals):
+    if vals:
+        return " ".join(vals)
 
 
-def run():
-    os.system('ansible-playbook run.yml')
+def setup(extra_val=None):
+    os.system('ansible-playbook setup.yml {}'.format(convert(extra_val)))
 
 
-def teardown():
-    os.system('ansible-playbook teardown.yml')
+def run(extra_val=None):
+    os.system('ansible-playbook run.yml {}'.format(convert(extra_val)))
+
+
+def teardown(extra_val=None):
+    os.system('ansible-playbook teardown.yml {}'.format(convert(extra_val)))
diff --git a/tests/unit/cli/cmd_project_test.py b/tests/unit/cli/cmd_project_test.py
new file mode 100644 (file)
index 0000000..8b9216f
--- /dev/null
@@ -0,0 +1,37 @@
+###############################################################
+# Copyright (c) 2017 taseer94@gmail.com and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+from click.testing import CliRunner
+import os
+import pytest
+
+from qtip.cli.entry import cli
+
+
+@pytest.fixture(scope='module')
+def runner():
+    return CliRunner()
+
+
+def test_run(mocker, runner):
+    mocker.patch('os.system')
+    runner.invoke(cli, ['run', '-vvv'])
+    os.system.assert_called_once_with('ansible-playbook run.yml -vvv')
+
+
+def test_setup(mocker, runner):
+    mocker.patch('os.system')
+    runner.invoke(cli, ['setup', '-vvv'])
+    os.system.assert_called_once_with('ansible-playbook setup.yml -vvv')
+
+
+def test_teardown(mocker, runner):
+    mocker.patch('os.system')
+    runner.invoke(cli, ['teardown', '-vvv'])
+    os.system.assert_called_once_with('ansible-playbook teardown.yml -vvv')