summaryrefslogtreecommitdiff
path: root/tests/user_commands/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/user_commands/tests.py')
-rw-r--r--tests/user_commands/tests.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/user_commands/tests.py b/tests/user_commands/tests.py
index 76991b1122..a53c781ac6 100644
--- a/tests/user_commands/tests.py
+++ b/tests/user_commands/tests.py
@@ -15,6 +15,7 @@ from django.db import connection
from django.test import SimpleTestCase, override_settings
from django.test.utils import captured_stderr, extend_sys_path
from django.utils import translation
+from django.utils.version import PY37
from .management.commands import dance
@@ -218,10 +219,34 @@ class CommandTests(SimpleTestCase):
management.call_command('subparser', 'foo', 12, stdout=out)
self.assertIn('bar', out.getvalue())
+ def test_subparser_dest_args(self):
+ out = StringIO()
+ management.call_command('subparser_dest', 'foo', bar=12, stdout=out)
+ self.assertIn('bar', out.getvalue())
+
+ def test_subparser_dest_required_args(self):
+ out = StringIO()
+ management.call_command('subparser_required', 'foo_1', 'foo_2', bar=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)
+ if PY37:
+ # "required" option requires Python 3.7 and later.
+ msg = 'Error: the following arguments are required: subcommand'
+ with self.assertRaisesMessage(CommandError, msg):
+ management.call_command('subparser_dest', subcommand='foo', bar=12)
+ else:
+ msg = (
+ 'Unknown option(s) for subparser_dest command: subcommand. '
+ 'Valid options are: bar, force_color, help, no_color, '
+ 'pythonpath, settings, skip_checks, stderr, stdout, '
+ 'traceback, verbosity, version.'
+ )
+ with self.assertRaisesMessage(TypeError, msg):
+ management.call_command('subparser_dest', subcommand='foo', bar=12)
def test_create_parser_kwargs(self):
"""BaseCommand.create_parser() passes kwargs to CommandParser."""