mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Added get_app_config() to look up app configs by label.
Refactored get_app() to rely on that method.
get_app() starts by calling _populate(), which goes through
INSTALLED_APPS and, for each app, imports the app module and attempts to
import the models module. At this point, no further imports are
necessary to return the models module for a given app. Therefore, the
implementation of get_app() can be simplified and the safeguards for
race conditions can be removed.
Besides, the emptyOK parameter isn't used anywhere in Django. It was
introduced in d6c95e93
but not actually used nor documented, and it has
just been carried around since then. Since it's an obscure private API,
it's acceptable to stop supporting it without a deprecation path. This
branch aims at providing first-class support for applications without a
models module eventually.
For backwards-compatibility, get_app() still raises ImproperlyConfigured
when an app isn't found, even though LookupError is technically more
correct. I haven't gone as far as to preserve the exact error messages.
I've adjusted a few tests instead.
This commit is contained in:
parent
c5eac3a2f6
commit
a4cb140004
3 changed files with 34 additions and 25 deletions
|
@ -379,14 +379,14 @@ class DjangoAdminMinimalSettings(AdminScriptTestCase):
|
|||
args = ['sqlall', '--settings=test_project.settings', 'admin_scripts']
|
||||
out, err = self.run_django_admin(args)
|
||||
self.assertNoOutput(out)
|
||||
self.assertOutput(err, 'App with label admin_scripts could not be found')
|
||||
self.assertOutput(err, "No app with label 'admin_scripts'.")
|
||||
|
||||
def test_builtin_with_environment(self):
|
||||
"minimal: django-admin builtin commands fail if settings are provided in the environment"
|
||||
args = ['sqlall', 'admin_scripts']
|
||||
out, err = self.run_django_admin(args, 'test_project.settings')
|
||||
self.assertNoOutput(out)
|
||||
self.assertOutput(err, 'App with label admin_scripts could not be found')
|
||||
self.assertOutput(err, "No app with label 'admin_scripts'.")
|
||||
|
||||
def test_builtin_with_bad_settings(self):
|
||||
"minimal: django-admin builtin commands fail if settings file (from argument) doesn't exist"
|
||||
|
@ -815,21 +815,21 @@ class ManageMinimalSettings(AdminScriptTestCase):
|
|||
args = ['sqlall', 'admin_scripts']
|
||||
out, err = self.run_manage(args)
|
||||
self.assertNoOutput(out)
|
||||
self.assertOutput(err, 'App with label admin_scripts could not be found')
|
||||
self.assertOutput(err, "No app with label 'admin_scripts'.")
|
||||
|
||||
def test_builtin_with_settings(self):
|
||||
"minimal: manage.py builtin commands fail if settings are provided as argument"
|
||||
args = ['sqlall', '--settings=test_project.settings', 'admin_scripts']
|
||||
out, err = self.run_manage(args)
|
||||
self.assertNoOutput(out)
|
||||
self.assertOutput(err, 'App with label admin_scripts could not be found')
|
||||
self.assertOutput(err, "No app with label 'admin_scripts'.")
|
||||
|
||||
def test_builtin_with_environment(self):
|
||||
"minimal: manage.py builtin commands fail if settings are provided in the environment"
|
||||
args = ['sqlall', 'admin_scripts']
|
||||
out, err = self.run_manage(args, 'test_project.settings')
|
||||
self.assertNoOutput(out)
|
||||
self.assertOutput(err, 'App with label admin_scripts could not be found')
|
||||
self.assertOutput(err, "No app with label 'admin_scripts'.")
|
||||
|
||||
def test_builtin_with_bad_settings(self):
|
||||
"minimal: manage.py builtin commands fail if settings file (from argument) doesn't exist"
|
||||
|
@ -964,7 +964,7 @@ class ManageMultipleSettings(AdminScriptTestCase):
|
|||
args = ['sqlall', 'admin_scripts']
|
||||
out, err = self.run_manage(args)
|
||||
self.assertNoOutput(out)
|
||||
self.assertOutput(err, 'App with label admin_scripts could not be found.')
|
||||
self.assertOutput(err, "No app with label 'admin_scripts'.")
|
||||
|
||||
def test_builtin_with_settings(self):
|
||||
"multiple: manage.py builtin commands succeed if settings are provided as argument"
|
||||
|
@ -1442,13 +1442,13 @@ class CommandTypes(AdminScriptTestCase):
|
|||
"User AppCommands can execute when a single app name is provided"
|
||||
args = ['app_command', 'NOT_AN_APP']
|
||||
out, err = self.run_manage(args)
|
||||
self.assertOutput(err, "App with label NOT_AN_APP could not be found")
|
||||
self.assertOutput(err, "No app with label 'NOT_AN_APP'.")
|
||||
|
||||
def test_app_command_some_invalid_appnames(self):
|
||||
"User AppCommands can execute when some of the provided app names are invalid"
|
||||
args = ['app_command', 'auth', 'NOT_AN_APP']
|
||||
out, err = self.run_manage(args)
|
||||
self.assertOutput(err, "App with label NOT_AN_APP could not be found")
|
||||
self.assertOutput(err, "No app with label 'NOT_AN_APP'.")
|
||||
|
||||
def test_label_command(self):
|
||||
"User LabelCommands can execute when a label is provided"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue