Fixed #25285 -- Provided unknown command message with plain django-admin.py
Thanks Maxime Lorant for the report and Tim Graham for suggesting the improved comment.
This commit is contained in:
parent
f9de197268
commit
c1893e2839
|
@ -177,8 +177,14 @@ class ManagementUtility(object):
|
||||||
try:
|
try:
|
||||||
app_name = commands[subcommand]
|
app_name = commands[subcommand]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# This might trigger ImproperlyConfigured (masked in get_commands)
|
if os.environ.get('DJANGO_SETTINGS_MODULE'):
|
||||||
|
# If `subcommand` is missing due to misconfigured settings, the
|
||||||
|
# following line will retrigger an ImproperlyConfigured exception
|
||||||
|
# (get_commands() swallows the original one) so the user is
|
||||||
|
# informed about it.
|
||||||
settings.INSTALLED_APPS
|
settings.INSTALLED_APPS
|
||||||
|
else:
|
||||||
|
sys.stderr.write("No Django settings specified.\n")
|
||||||
sys.stderr.write("Unknown command: %r\nType '%s help' for usage.\n" %
|
sys.stderr.write("Unknown command: %r\nType '%s help' for usage.\n" %
|
||||||
(subcommand, self.prog_name))
|
(subcommand, self.prog_name))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
|
@ -283,7 +283,8 @@ class DjangoAdminDefaultSettings(AdminScriptTestCase):
|
||||||
args = ['noargs_command']
|
args = ['noargs_command']
|
||||||
out, err = self.run_django_admin(args)
|
out, err = self.run_django_admin(args)
|
||||||
self.assertNoOutput(out)
|
self.assertNoOutput(out)
|
||||||
self.assertOutput(err, "settings are not configured")
|
self.assertOutput(err, "No Django settings specified")
|
||||||
|
self.assertOutput(err, "Unknown command: 'noargs_command'")
|
||||||
|
|
||||||
def test_custom_command_with_settings(self):
|
def test_custom_command_with_settings(self):
|
||||||
"default: django-admin can execute user commands if settings are provided as argument"
|
"default: django-admin can execute user commands if settings are provided as argument"
|
||||||
|
@ -351,7 +352,8 @@ class DjangoAdminFullPathDefaultSettings(AdminScriptTestCase):
|
||||||
args = ['noargs_command']
|
args = ['noargs_command']
|
||||||
out, err = self.run_django_admin(args)
|
out, err = self.run_django_admin(args)
|
||||||
self.assertNoOutput(out)
|
self.assertNoOutput(out)
|
||||||
self.assertOutput(err, "settings are not configured")
|
self.assertOutput(err, "No Django settings specified")
|
||||||
|
self.assertOutput(err, "Unknown command: 'noargs_command'")
|
||||||
|
|
||||||
def test_custom_command_with_settings(self):
|
def test_custom_command_with_settings(self):
|
||||||
"fulldefault: django-admin can execute user commands if settings are provided as argument"
|
"fulldefault: django-admin can execute user commands if settings are provided as argument"
|
||||||
|
@ -418,7 +420,8 @@ class DjangoAdminMinimalSettings(AdminScriptTestCase):
|
||||||
args = ['noargs_command']
|
args = ['noargs_command']
|
||||||
out, err = self.run_django_admin(args)
|
out, err = self.run_django_admin(args)
|
||||||
self.assertNoOutput(out)
|
self.assertNoOutput(out)
|
||||||
self.assertOutput(err, "settings are not configured")
|
self.assertOutput(err, "No Django settings specified")
|
||||||
|
self.assertOutput(err, "Unknown command: 'noargs_command'")
|
||||||
|
|
||||||
def test_custom_command_with_settings(self):
|
def test_custom_command_with_settings(self):
|
||||||
"minimal: django-admin can't execute user commands, even if settings are provided as argument"
|
"minimal: django-admin can't execute user commands, even if settings are provided as argument"
|
||||||
|
@ -485,7 +488,8 @@ class DjangoAdminAlternateSettings(AdminScriptTestCase):
|
||||||
args = ['noargs_command']
|
args = ['noargs_command']
|
||||||
out, err = self.run_django_admin(args)
|
out, err = self.run_django_admin(args)
|
||||||
self.assertNoOutput(out)
|
self.assertNoOutput(out)
|
||||||
self.assertOutput(err, "settings are not configured")
|
self.assertOutput(err, "No Django settings specified")
|
||||||
|
self.assertOutput(err, "Unknown command: 'noargs_command'")
|
||||||
|
|
||||||
def test_custom_command_with_settings(self):
|
def test_custom_command_with_settings(self):
|
||||||
"alternate: django-admin can execute user commands if settings are provided as argument"
|
"alternate: django-admin can execute user commands if settings are provided as argument"
|
||||||
|
@ -555,7 +559,8 @@ class DjangoAdminMultipleSettings(AdminScriptTestCase):
|
||||||
args = ['noargs_command']
|
args = ['noargs_command']
|
||||||
out, err = self.run_django_admin(args)
|
out, err = self.run_django_admin(args)
|
||||||
self.assertNoOutput(out)
|
self.assertNoOutput(out)
|
||||||
self.assertOutput(err, "settings are not configured")
|
self.assertOutput(err, "No Django settings specified")
|
||||||
|
self.assertOutput(err, "Unknown command: 'noargs_command'")
|
||||||
|
|
||||||
def test_custom_command_with_settings(self):
|
def test_custom_command_with_settings(self):
|
||||||
"alternate: django-admin can execute user commands if settings are provided as argument"
|
"alternate: django-admin can execute user commands if settings are provided as argument"
|
||||||
|
@ -644,7 +649,8 @@ class DjangoAdminSettingsDirectory(AdminScriptTestCase):
|
||||||
args = ['noargs_command']
|
args = ['noargs_command']
|
||||||
out, err = self.run_django_admin(args)
|
out, err = self.run_django_admin(args)
|
||||||
self.assertNoOutput(out)
|
self.assertNoOutput(out)
|
||||||
self.assertOutput(err, "settings are not configured")
|
self.assertOutput(err, "No Django settings specified")
|
||||||
|
self.assertOutput(err, "Unknown command: 'noargs_command'")
|
||||||
|
|
||||||
def test_builtin_with_settings(self):
|
def test_builtin_with_settings(self):
|
||||||
"directory: django-admin builtin commands succeed if settings are provided as argument"
|
"directory: django-admin builtin commands succeed if settings are provided as argument"
|
||||||
|
|
Loading…
Reference in New Issue