mirror of https://github.com/django/django.git
Refs #32047 -- Added test for using call_command() with constant required options.
This commit is contained in:
parent
0ef04fdd7a
commit
efe74fff25
|
@ -0,0 +1,20 @@
|
|||
from django.core.management.base import BaseCommand
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument(
|
||||
'--append_const',
|
||||
action='append_const',
|
||||
const=42,
|
||||
required=True,
|
||||
)
|
||||
parser.add_argument('--const', action='store_const', const=31, required=True)
|
||||
parser.add_argument('--count', action='count', required=True)
|
||||
parser.add_argument('--flag_false', action='store_false', required=True)
|
||||
parser.add_argument('--flag_true', action='store_true', required=True)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
for option, value in options.items():
|
||||
if value is not None:
|
||||
self.stdout.write('%s=%s' % (option, value))
|
|
@ -275,6 +275,32 @@ class CommandTests(SimpleTestCase):
|
|||
)
|
||||
self.assertIn(expected_output, out.getvalue())
|
||||
|
||||
def test_required_const_options(self):
|
||||
args = {
|
||||
'append_const': [42],
|
||||
'const': 31,
|
||||
'count': 1,
|
||||
'flag_false': False,
|
||||
'flag_true': True,
|
||||
}
|
||||
expected_output = '\n'.join(
|
||||
'%s=%s' % (arg, value) for arg, value in args.items()
|
||||
)
|
||||
out = StringIO()
|
||||
management.call_command(
|
||||
'required_constant_option',
|
||||
'--append_const',
|
||||
'--const',
|
||||
'--count',
|
||||
'--flag_false',
|
||||
'--flag_true',
|
||||
stdout=out,
|
||||
)
|
||||
self.assertIn(expected_output, out.getvalue())
|
||||
out.truncate(0)
|
||||
management.call_command('required_constant_option', **{**args, 'stdout': out})
|
||||
self.assertIn(expected_output, out.getvalue())
|
||||
|
||||
def test_subparser(self):
|
||||
out = StringIO()
|
||||
management.call_command('subparser', 'foo', 12, stdout=out)
|
||||
|
|
Loading…
Reference in New Issue