summaryrefslogtreecommitdiff
path: root/tests/admin_scripts
diff options
context:
space:
mode:
authorWilliam Schwartz <wkschwartz@gmail.com>2020-11-09 14:42:53 -0600
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-11-10 08:16:53 +0100
commitcc2269350548307e3fe31723ff4e40a879a7a173 (patch)
treed77d9c6411573bad8b7e09a5e55c3b6921867fcd /tests/admin_scripts
parent0773837e15bb632afffb6848a58c59a791008fa1 (diff)
Fixed #32177 -- Made execute_from_command_line() use program name from the argv argument.
This caused crash in environments where sys.argv[0] is incorrectly set to None.
Diffstat (limited to 'tests/admin_scripts')
-rw-r--r--tests/admin_scripts/tests.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py
index 62c6f485aa..a82f5be5ed 100644
--- a/tests/admin_scripts/tests.py
+++ b/tests/admin_scripts/tests.py
@@ -17,7 +17,7 @@ from unittest import mock
from django import conf, get_version
from django.conf import settings
from django.core.management import (
- BaseCommand, CommandError, call_command, color,
+ BaseCommand, CommandError, call_command, color, execute_from_command_line,
)
from django.core.management.commands.loaddata import Command as LoaddataCommand
from django.core.management.commands.runserver import (
@@ -31,6 +31,7 @@ from django.db.migrations.recorder import MigrationRecorder
from django.test import (
LiveServerTestCase, SimpleTestCase, TestCase, override_settings,
)
+from django.test.utils import captured_stderr, captured_stdout
custom_templates_dir = os.path.join(os.path.dirname(__file__), 'custom_templates')
@@ -1867,6 +1868,20 @@ class ArgumentOrder(AdminScriptTestCase):
)
+class ExecuteFromCommandLine(SimpleTestCase):
+ def test_program_name_from_argv(self):
+ """
+ Program name is computed from the execute_from_command_line()'s argv
+ argument, not sys.argv.
+ """
+ args = ['help', 'shell']
+ with captured_stdout() as out, captured_stderr() as err:
+ with mock.patch('sys.argv', [None] + args):
+ execute_from_command_line(['django-admin'] + args)
+ self.assertIn('usage: django-admin shell', out.getvalue())
+ self.assertEqual(err.getvalue(), '')
+
+
@override_settings(ROOT_URLCONF='admin_scripts.urls')
class StartProject(LiveServerTestCase, AdminScriptTestCase):