summaryrefslogtreecommitdiff
path: root/tests/admin_scripts/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/admin_scripts/tests.py')
-rw-r--r--tests/admin_scripts/tests.py39
1 files changed, 30 insertions, 9 deletions
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py
index c8986770f3..9e6b1f557b 100644
--- a/tests/admin_scripts/tests.py
+++ b/tests/admin_scripts/tests.py
@@ -1305,13 +1305,15 @@ class CommandTypes(AdminScriptTestCase):
sys.stderr = err = StringIO()
try:
command.execute = lambda args: args # This will trigger TypeError
- with self.assertRaises(SystemExit):
+
+ # If the Exception is not CommandError it should always
+ # raise the original exception.
+ with self.assertRaises(TypeError):
command.run_from_argv(['', ''])
- err_message = err.getvalue()
- # Exceptions other than CommandError automatically output the traceback
- self.assertIn("Traceback", err_message)
- self.assertIn("TypeError", err_message)
+ # If the Exception is CommandError and --traceback is not present
+ # this command should raise a SystemExit and don't print any
+ # traceback to the stderr.
command.execute = raise_command_error
err.truncate(0)
with self.assertRaises(SystemExit):
@@ -1320,12 +1322,12 @@ class CommandTypes(AdminScriptTestCase):
self.assertNotIn("Traceback", err_message)
self.assertIn("CommandError", err_message)
+ # If the Exception is CommandError and --traceback is present
+ # this command should raise the original CommandError as if it
+ # were not a CommandError.
err.truncate(0)
- with self.assertRaises(SystemExit):
+ with self.assertRaises(CommandError):
command.run_from_argv(['', '', '--traceback'])
- err_message = err.getvalue()
- self.assertIn("Traceback (most recent call last)", err_message)
- self.assertIn("CommandError", err_message)
finally:
sys.stderr = old_stderr
@@ -1680,3 +1682,22 @@ class DiffSettings(AdminScriptTestCase):
out, err = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, "### STATIC_URL = None")
+
+class Dumpdata(AdminScriptTestCase):
+ """Tests for dumpdata management command."""
+
+ def setUp(self):
+ self.write_settings('settings.py')
+
+ def tearDown(self):
+ self.remove_settings('settings.py')
+
+ def test_pks_parsing(self):
+ """Regression for #20509
+
+ Test would raise an exception rather than printing an error message.
+ """
+ args = ['dumpdata', '--pks=1']
+ out, err = self.run_manage(args)
+ self.assertOutput(err, "You can only use --pks option with one model")
+ self.assertNoOutput(out)