summaryrefslogtreecommitdiff
path: root/tests/user_commands
diff options
context:
space:
mode:
Diffstat (limited to 'tests/user_commands')
-rw-r--r--tests/user_commands/management/commands/subparser.py12
-rw-r--r--tests/user_commands/tests.py10
2 files changed, 22 insertions, 0 deletions
diff --git a/tests/user_commands/management/commands/subparser.py b/tests/user_commands/management/commands/subparser.py
new file mode 100644
index 0000000000..d3006bd3e8
--- /dev/null
+++ b/tests/user_commands/management/commands/subparser.py
@@ -0,0 +1,12 @@
+from django.core.management.base import BaseCommand
+
+
+class Command(BaseCommand):
+
+ def add_arguments(self, parser):
+ subparsers = parser.add_subparsers()
+ parser_foo = subparsers.add_parser('foo')
+ parser_foo.add_argument('bar', type=int)
+
+ def handle(self, *args, **options):
+ self.stdout.write(','.join(options))
diff --git a/tests/user_commands/tests.py b/tests/user_commands/tests.py
index ae05bcfe25..61e649c75a 100644
--- a/tests/user_commands/tests.py
+++ b/tests/user_commands/tests.py
@@ -206,6 +206,16 @@ class CommandTests(SimpleTestCase):
self.assertIn('need_me', out.getvalue())
self.assertIn('needme2', out.getvalue())
+ def test_subparser(self):
+ out = StringIO()
+ management.call_command('subparser', 'foo', 12, stdout=out)
+ self.assertIn('bar', out.getvalue())
+
+ def test_subparser_invalid_option(self):
+ msg = "Error: invalid choice: 'test' (choose from 'foo')"
+ with self.assertRaisesMessage(CommandError, msg):
+ management.call_command('subparser', 'test', 12)
+
class CommandRunTests(AdminScriptTestCase):
"""