You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2013/05/24 20:18:21 UTC

[45/50] git commit: [#6270] ticket:359 Change task state to error on invalid args to paster command

[#6270] ticket:359 Change task state to error on invalid args to paster command


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/1e9c2510
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/1e9c2510
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/1e9c2510

Branch: refs/heads/db/6007
Commit: 1e9c25102172da3c112cf00944e8039216ba5ea9
Parents: 6686bcf
Author: Igor Bondarenko <je...@gmail.com>
Authored: Fri May 24 08:07:07 2013 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Fri May 24 13:22:14 2013 +0000

----------------------------------------------------------------------
 Allura/allura/command/base.py        |    8 +++++++-
 Allura/allura/tests/test_commands.py |    9 +++++++++
 2 files changed, 16 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1e9c2510/Allura/allura/command/base.py
----------------------------------------------------------------------
diff --git a/Allura/allura/command/base.py b/Allura/allura/command/base.py
index d433643..536159d 100644
--- a/Allura/allura/command/base.py
+++ b/Allura/allura/command/base.py
@@ -40,7 +40,13 @@ def run_command(command, args):
     mod, cls = command.rsplit('.', 1)
     mod = __import__(mod, fromlist=[str(cls)])
     command = getattr(mod, cls)
-    return command(command.__name__).run(shlex.split(args or ''))
+    command = command(command.__name__)
+    arg_list = shlex.split(args or '')
+    try:
+        command.parser.parse_args(arg_list)
+    except SystemExit:
+        raise Exception("Error parsing args: '%s'" % args)
+    return command.run(arg_list)
 
 class EmptyClass(object): pass
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1e9c2510/Allura/allura/tests/test_commands.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_commands.py b/Allura/allura/tests/test_commands.py
index 5f4963c..fee6e21 100644
--- a/Allura/allura/tests/test_commands.py
+++ b/Allura/allura/tests/test_commands.py
@@ -341,6 +341,15 @@ class TestBackgroundCommand(object):
         base.run_command(self.cmd, 'dev.ini -p "project 3"')
         command(command.__name__).run.assert_called_with(['dev.ini', '-p', 'project 3'])
 
+    def test_invalid_args(self):
+        M.MonQTask.query.remove()
+        show_models.ReindexCommand.post('--invalid-option')
+        with td.raises(Exception):
+            M.MonQTask.run_ready()
+        task = M.MonQTask.query.get(task_name=self.task_name)
+        assert_equal(task.state, 'error')
+        assert_in('Error parsing args', task.result)
+
 
 class TestReindexCommand(object):