summaryrefslogtreecommitdiff
path: root/tests/user_commands
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2014-08-09 21:03:19 +0200
committerClaude Paroz <claude@2xlibre.net>2014-08-12 21:53:29 +0200
commit2cc8ffe258008096a70791115b2daa12f0ef0192 (patch)
tree8d30f9ed8fc1c1931d35ecc5410f164a1171f3eb /tests/user_commands
parent8f9862cd4d0e9706babf947079739fd476455df7 (diff)
downloaddjango-2cc8ffe258008096a70791115b2daa12f0ef0192.tar.gz
Fixed #22985 -- Made call_command accept option name parameter
Thanks giulettamasina for the report and Tim Graham for the review.
Diffstat (limited to 'tests/user_commands')
-rw-r--r--tests/user_commands/management/commands/dance.py2
-rw-r--r--tests/user_commands/tests.py20
2 files changed, 18 insertions, 4 deletions
diff --git a/tests/user_commands/management/commands/dance.py b/tests/user_commands/management/commands/dance.py
index 0c47401c25..e27042f9d4 100644
--- a/tests/user_commands/management/commands/dance.py
+++ b/tests/user_commands/management/commands/dance.py
@@ -9,9 +9,11 @@ class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument("-s", "--style", default="Rock'n'Roll")
parser.add_argument("-x", "--example")
+ parser.add_argument("--opt-3", action='store_true', dest='option3')
def handle(self, *args, **options):
example = options["example"]
if example == "raise":
raise CommandError()
self.stdout.write("I don't feel like dancing %s." % options["style"])
+ self.stdout.write(','.join(options.keys()))
diff --git a/tests/user_commands/tests.py b/tests/user_commands/tests.py
index ac2e51c807..398e01eb6b 100644
--- a/tests/user_commands/tests.py
+++ b/tests/user_commands/tests.py
@@ -15,14 +15,15 @@ class CommandTests(SimpleTestCase):
def test_command(self):
out = StringIO()
management.call_command('dance', stdout=out)
- self.assertEqual(out.getvalue(),
- "I don't feel like dancing Rock'n'Roll.\n")
+ self.assertIn("I don't feel like dancing Rock'n'Roll.\n", out.getvalue())
def test_command_style(self):
out = StringIO()
management.call_command('dance', style='Jive', stdout=out)
- self.assertEqual(out.getvalue(),
- "I don't feel like dancing Jive.\n")
+ self.assertIn("I don't feel like dancing Jive.\n", out.getvalue())
+ # Passing options as arguments also works (thanks argparse)
+ management.call_command('dance', '--style', 'Jive', stdout=out)
+ self.assertIn("I don't feel like dancing Jive.\n", out.getvalue())
def test_language_preserved(self):
out = StringIO()
@@ -76,6 +77,17 @@ class CommandTests(SimpleTestCase):
if current_path is not None:
os.environ['PATH'] = current_path
+ def test_call_command_option_parsing(self):
+ """
+ When passing the long option name to call_command, the available option
+ key is the option dest name (#22985).
+ """
+ out = StringIO()
+ management.call_command('dance', stdout=out, opt_3=True)
+ self.assertIn("option3", out.getvalue())
+ self.assertNotIn("opt_3", out.getvalue())
+ self.assertNotIn("opt-3", out.getvalue())
+
def test_optparse_compatibility(self):
"""
optparse should be supported during Django 1.8/1.9 releases.