diff options
| author | Hasan Ramezani <hasan.r67@gmail.com> | 2019-06-26 22:04:58 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-06-28 12:51:26 +0200 |
| commit | 2b03e8e9e8205ae3a3aa128764277e70b7c30803 (patch) | |
| tree | 95f21a900a1a0eab7ebb819023c9e1c2d2375608 /tests/user_commands/tests.py | |
| parent | f03b7bd11461e8b525c27d5344f8cd3a21c9565e (diff) | |
Fixed #30584 -- Fixed management command when using subparsers with dest parameter.
Diffstat (limited to 'tests/user_commands/tests.py')
| -rw-r--r-- | tests/user_commands/tests.py | 25 |
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.""" |
