mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Refs #33476 -- Reformatted code with Black.
This commit is contained in:
committed by
Mariusz Felisiak
parent
f68fa8b45d
commit
9c19aff7c7
@@ -16,24 +16,23 @@ from .two_configs_one_default_app.apps import TwoConfig
|
||||
# Intentionally not in alphabetical order to check if the order is preserved.
|
||||
|
||||
SOME_INSTALLED_APPS = [
|
||||
'apps.apps.MyAdmin',
|
||||
'apps.apps.MyAuth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
"apps.apps.MyAdmin",
|
||||
"apps.apps.MyAuth",
|
||||
"django.contrib.contenttypes",
|
||||
"django.contrib.sessions",
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
]
|
||||
|
||||
SOME_INSTALLED_APPS_NAMES = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
"django.contrib.admin",
|
||||
"django.contrib.auth",
|
||||
] + SOME_INSTALLED_APPS[2:]
|
||||
|
||||
HERE = os.path.dirname(__file__)
|
||||
|
||||
|
||||
class AppsTests(SimpleTestCase):
|
||||
|
||||
def test_singleton_master(self):
|
||||
"""
|
||||
Only one master registry can exist.
|
||||
@@ -59,7 +58,7 @@ class AppsTests(SimpleTestCase):
|
||||
"""
|
||||
msg = "'apps.apps.BadConfig' must supply a name attribute."
|
||||
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
||||
with self.settings(INSTALLED_APPS=['apps.apps.BadConfig']):
|
||||
with self.settings(INSTALLED_APPS=["apps.apps.BadConfig"]):
|
||||
pass
|
||||
|
||||
def test_not_an_app_config(self):
|
||||
@@ -68,7 +67,7 @@ class AppsTests(SimpleTestCase):
|
||||
"""
|
||||
msg = "'apps.apps.NotAConfig' isn't a subclass of AppConfig."
|
||||
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
||||
with self.settings(INSTALLED_APPS=['apps.apps.NotAConfig']):
|
||||
with self.settings(INSTALLED_APPS=["apps.apps.NotAConfig"]):
|
||||
pass
|
||||
|
||||
def test_no_such_app(self):
|
||||
@@ -77,17 +76,17 @@ class AppsTests(SimpleTestCase):
|
||||
directly or via an app config.
|
||||
"""
|
||||
with self.assertRaises(ImportError):
|
||||
with self.settings(INSTALLED_APPS=['there is no such app']):
|
||||
with self.settings(INSTALLED_APPS=["there is no such app"]):
|
||||
pass
|
||||
msg = "Cannot import 'there is no such app'. Check that 'apps.apps.NoSuchApp.name' is correct."
|
||||
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
||||
with self.settings(INSTALLED_APPS=['apps.apps.NoSuchApp']):
|
||||
with self.settings(INSTALLED_APPS=["apps.apps.NoSuchApp"]):
|
||||
pass
|
||||
|
||||
def test_no_such_app_config(self):
|
||||
msg = "Module 'apps' does not contain a 'NoSuchConfig' class."
|
||||
with self.assertRaisesMessage(ImportError, msg):
|
||||
with self.settings(INSTALLED_APPS=['apps.NoSuchConfig']):
|
||||
with self.settings(INSTALLED_APPS=["apps.NoSuchConfig"]):
|
||||
pass
|
||||
|
||||
def test_no_such_app_config_with_choices(self):
|
||||
@@ -97,25 +96,25 @@ class AppsTests(SimpleTestCase):
|
||||
"'MyAuth', 'NoSuchApp', 'PlainAppsConfig', 'RelabeledAppsConfig'."
|
||||
)
|
||||
with self.assertRaisesMessage(ImportError, msg):
|
||||
with self.settings(INSTALLED_APPS=['apps.apps.NoSuchConfig']):
|
||||
with self.settings(INSTALLED_APPS=["apps.apps.NoSuchConfig"]):
|
||||
pass
|
||||
|
||||
def test_no_config_app(self):
|
||||
"""Load an app that doesn't provide an AppConfig class."""
|
||||
with self.settings(INSTALLED_APPS=['apps.no_config_app']):
|
||||
config = apps.get_app_config('no_config_app')
|
||||
with self.settings(INSTALLED_APPS=["apps.no_config_app"]):
|
||||
config = apps.get_app_config("no_config_app")
|
||||
self.assertIsInstance(config, AppConfig)
|
||||
|
||||
def test_one_config_app(self):
|
||||
"""Load an app that provides an AppConfig class."""
|
||||
with self.settings(INSTALLED_APPS=['apps.one_config_app']):
|
||||
config = apps.get_app_config('one_config_app')
|
||||
with self.settings(INSTALLED_APPS=["apps.one_config_app"]):
|
||||
config = apps.get_app_config("one_config_app")
|
||||
self.assertIsInstance(config, OneConfig)
|
||||
|
||||
def test_two_configs_app(self):
|
||||
"""Load an app that provides two AppConfig classes."""
|
||||
with self.settings(INSTALLED_APPS=['apps.two_configs_app']):
|
||||
config = apps.get_app_config('two_configs_app')
|
||||
with self.settings(INSTALLED_APPS=["apps.two_configs_app"]):
|
||||
config = apps.get_app_config("two_configs_app")
|
||||
self.assertIsInstance(config, AppConfig)
|
||||
|
||||
def test_two_default_configs_app(self):
|
||||
@@ -125,15 +124,15 @@ class AppsTests(SimpleTestCase):
|
||||
"default AppConfig: 'TwoConfig', 'TwoConfigBis'."
|
||||
)
|
||||
with self.assertRaisesMessage(RuntimeError, msg):
|
||||
with self.settings(INSTALLED_APPS=['apps.two_default_configs_app']):
|
||||
with self.settings(INSTALLED_APPS=["apps.two_default_configs_app"]):
|
||||
pass
|
||||
|
||||
def test_two_configs_one_default_app(self):
|
||||
"""
|
||||
Load an app that provides two AppConfig classes, one being the default.
|
||||
"""
|
||||
with self.settings(INSTALLED_APPS=['apps.two_configs_one_default_app']):
|
||||
config = apps.get_app_config('two_configs_one_default_app')
|
||||
with self.settings(INSTALLED_APPS=["apps.two_configs_one_default_app"]):
|
||||
config = apps.get_app_config("two_configs_one_default_app")
|
||||
self.assertIsInstance(config, TwoConfig)
|
||||
|
||||
@override_settings(INSTALLED_APPS=SOME_INSTALLED_APPS)
|
||||
@@ -142,69 +141,77 @@ class AppsTests(SimpleTestCase):
|
||||
Tests apps.get_app_configs().
|
||||
"""
|
||||
app_configs = apps.get_app_configs()
|
||||
self.assertEqual([app_config.name for app_config in app_configs], SOME_INSTALLED_APPS_NAMES)
|
||||
self.assertEqual(
|
||||
[app_config.name for app_config in app_configs], SOME_INSTALLED_APPS_NAMES
|
||||
)
|
||||
|
||||
@override_settings(INSTALLED_APPS=SOME_INSTALLED_APPS)
|
||||
def test_get_app_config(self):
|
||||
"""
|
||||
Tests apps.get_app_config().
|
||||
"""
|
||||
app_config = apps.get_app_config('admin')
|
||||
self.assertEqual(app_config.name, 'django.contrib.admin')
|
||||
app_config = apps.get_app_config("admin")
|
||||
self.assertEqual(app_config.name, "django.contrib.admin")
|
||||
|
||||
app_config = apps.get_app_config('staticfiles')
|
||||
self.assertEqual(app_config.name, 'django.contrib.staticfiles')
|
||||
app_config = apps.get_app_config("staticfiles")
|
||||
self.assertEqual(app_config.name, "django.contrib.staticfiles")
|
||||
|
||||
with self.assertRaises(LookupError):
|
||||
apps.get_app_config('admindocs')
|
||||
apps.get_app_config("admindocs")
|
||||
|
||||
msg = "No installed app with label 'django.contrib.auth'. Did you mean 'myauth'"
|
||||
with self.assertRaisesMessage(LookupError, msg):
|
||||
apps.get_app_config('django.contrib.auth')
|
||||
apps.get_app_config("django.contrib.auth")
|
||||
|
||||
@override_settings(INSTALLED_APPS=SOME_INSTALLED_APPS)
|
||||
def test_is_installed(self):
|
||||
"""
|
||||
Tests apps.is_installed().
|
||||
"""
|
||||
self.assertIs(apps.is_installed('django.contrib.admin'), True)
|
||||
self.assertIs(apps.is_installed('django.contrib.auth'), True)
|
||||
self.assertIs(apps.is_installed('django.contrib.staticfiles'), True)
|
||||
self.assertIs(apps.is_installed('django.contrib.admindocs'), False)
|
||||
self.assertIs(apps.is_installed("django.contrib.admin"), True)
|
||||
self.assertIs(apps.is_installed("django.contrib.auth"), True)
|
||||
self.assertIs(apps.is_installed("django.contrib.staticfiles"), True)
|
||||
self.assertIs(apps.is_installed("django.contrib.admindocs"), False)
|
||||
|
||||
@override_settings(INSTALLED_APPS=SOME_INSTALLED_APPS)
|
||||
def test_get_model(self):
|
||||
"""
|
||||
Tests apps.get_model().
|
||||
"""
|
||||
self.assertEqual(apps.get_model('admin', 'LogEntry'), LogEntry)
|
||||
self.assertEqual(apps.get_model("admin", "LogEntry"), LogEntry)
|
||||
with self.assertRaises(LookupError):
|
||||
apps.get_model('admin', 'LogExit')
|
||||
apps.get_model("admin", "LogExit")
|
||||
|
||||
# App label is case-sensitive, Model name is case-insensitive.
|
||||
self.assertEqual(apps.get_model('admin', 'loGentrY'), LogEntry)
|
||||
self.assertEqual(apps.get_model("admin", "loGentrY"), LogEntry)
|
||||
with self.assertRaises(LookupError):
|
||||
apps.get_model('Admin', 'LogEntry')
|
||||
apps.get_model("Admin", "LogEntry")
|
||||
|
||||
# A single argument is accepted.
|
||||
self.assertEqual(apps.get_model('admin.LogEntry'), LogEntry)
|
||||
self.assertEqual(apps.get_model("admin.LogEntry"), LogEntry)
|
||||
with self.assertRaises(LookupError):
|
||||
apps.get_model('admin.LogExit')
|
||||
apps.get_model("admin.LogExit")
|
||||
with self.assertRaises(ValueError):
|
||||
apps.get_model('admin_LogEntry')
|
||||
apps.get_model("admin_LogEntry")
|
||||
|
||||
@override_settings(INSTALLED_APPS=['apps.apps.RelabeledAppsConfig'])
|
||||
@override_settings(INSTALLED_APPS=["apps.apps.RelabeledAppsConfig"])
|
||||
def test_relabeling(self):
|
||||
self.assertEqual(apps.get_app_config('relabeled').name, 'apps')
|
||||
self.assertEqual(apps.get_app_config("relabeled").name, "apps")
|
||||
|
||||
def test_duplicate_labels(self):
|
||||
with self.assertRaisesMessage(ImproperlyConfigured, "Application labels aren't unique"):
|
||||
with self.settings(INSTALLED_APPS=['apps.apps.PlainAppsConfig', 'apps']):
|
||||
with self.assertRaisesMessage(
|
||||
ImproperlyConfigured, "Application labels aren't unique"
|
||||
):
|
||||
with self.settings(INSTALLED_APPS=["apps.apps.PlainAppsConfig", "apps"]):
|
||||
pass
|
||||
|
||||
def test_duplicate_names(self):
|
||||
with self.assertRaisesMessage(ImproperlyConfigured, "Application names aren't unique"):
|
||||
with self.settings(INSTALLED_APPS=['apps.apps.RelabeledAppsConfig', 'apps']):
|
||||
with self.assertRaisesMessage(
|
||||
ImproperlyConfigured, "Application names aren't unique"
|
||||
):
|
||||
with self.settings(
|
||||
INSTALLED_APPS=["apps.apps.RelabeledAppsConfig", "apps"]
|
||||
):
|
||||
pass
|
||||
|
||||
def test_import_exception_is_not_masked(self):
|
||||
@@ -212,7 +219,7 @@ class AppsTests(SimpleTestCase):
|
||||
App discovery should preserve stack traces. Regression test for #22920.
|
||||
"""
|
||||
with self.assertRaisesMessage(ImportError, "Oops"):
|
||||
with self.settings(INSTALLED_APPS=['import_error_package']):
|
||||
with self.settings(INSTALLED_APPS=["import_error_package"]):
|
||||
pass
|
||||
|
||||
def test_models_py(self):
|
||||
@@ -235,7 +242,9 @@ class AppsTests(SimpleTestCase):
|
||||
try:
|
||||
# The cache must be cleared to trigger the exception.
|
||||
apps.get_models.cache_clear()
|
||||
with self.assertRaisesMessage(AppRegistryNotReady, "Models aren't loaded yet."):
|
||||
with self.assertRaisesMessage(
|
||||
AppRegistryNotReady, "Models aren't loaded yet."
|
||||
):
|
||||
apps.get_models()
|
||||
finally:
|
||||
apps.models_ready = True
|
||||
@@ -249,12 +258,12 @@ class AppsTests(SimpleTestCase):
|
||||
body = {}
|
||||
new_apps = Apps(["apps"])
|
||||
meta_contents = {
|
||||
'app_label': "apps",
|
||||
'apps': new_apps,
|
||||
"app_label": "apps",
|
||||
"apps": new_apps,
|
||||
}
|
||||
meta = type("Meta", (), meta_contents)
|
||||
body['Meta'] = meta
|
||||
body['__module__'] = TotallyNormal.__module__
|
||||
body["Meta"] = meta
|
||||
body["__module__"] = TotallyNormal.__module__
|
||||
temp_model = type("SouthPonies", (models.Model,), body)
|
||||
# Make sure it appeared in the right place!
|
||||
self.assertEqual(list(apps.get_app_config("apps").get_models()), old_models)
|
||||
@@ -268,21 +277,21 @@ class AppsTests(SimpleTestCase):
|
||||
"""
|
||||
new_apps = Apps(["apps"])
|
||||
meta_contents = {
|
||||
'app_label': "apps",
|
||||
'apps': new_apps,
|
||||
"app_label": "apps",
|
||||
"apps": new_apps,
|
||||
}
|
||||
|
||||
body = {}
|
||||
body['Meta'] = type("Meta", (), meta_contents)
|
||||
body['__module__'] = TotallyNormal.__module__
|
||||
body["Meta"] = type("Meta", (), meta_contents)
|
||||
body["__module__"] = TotallyNormal.__module__
|
||||
type("SouthPonies", (models.Model,), body)
|
||||
|
||||
# When __name__ and __module__ match we assume the module
|
||||
# was reloaded and issue a warning. This use-case is
|
||||
# useful for REPL. Refs #23621.
|
||||
body = {}
|
||||
body['Meta'] = type("Meta", (), meta_contents)
|
||||
body['__module__'] = TotallyNormal.__module__
|
||||
body["Meta"] = type("Meta", (), meta_contents)
|
||||
body["__module__"] = TotallyNormal.__module__
|
||||
msg = (
|
||||
"Model 'apps.southponies' was already registered. "
|
||||
"Reloading models is not advised as it can lead to inconsistencies, "
|
||||
@@ -294,9 +303,11 @@ class AppsTests(SimpleTestCase):
|
||||
# If it doesn't appear to be a reloaded module then we expect
|
||||
# a RuntimeError.
|
||||
body = {}
|
||||
body['Meta'] = type("Meta", (), meta_contents)
|
||||
body['__module__'] = TotallyNormal.__module__ + '.whatever'
|
||||
with self.assertRaisesMessage(RuntimeError, "Conflicting 'southponies' models in application 'apps':"):
|
||||
body["Meta"] = type("Meta", (), meta_contents)
|
||||
body["__module__"] = TotallyNormal.__module__ + ".whatever"
|
||||
with self.assertRaisesMessage(
|
||||
RuntimeError, "Conflicting 'southponies' models in application 'apps':"
|
||||
):
|
||||
type("SouthPonies", (models.Model,), body)
|
||||
|
||||
def test_get_containing_app_config_apps_not_ready(self):
|
||||
@@ -306,12 +317,14 @@ class AppsTests(SimpleTestCase):
|
||||
"""
|
||||
apps.apps_ready = False
|
||||
try:
|
||||
with self.assertRaisesMessage(AppRegistryNotReady, "Apps aren't loaded yet"):
|
||||
apps.get_containing_app_config('foo')
|
||||
with self.assertRaisesMessage(
|
||||
AppRegistryNotReady, "Apps aren't loaded yet"
|
||||
):
|
||||
apps.get_containing_app_config("foo")
|
||||
finally:
|
||||
apps.apps_ready = True
|
||||
|
||||
@isolate_apps('apps', kwarg_name='apps')
|
||||
@isolate_apps("apps", kwarg_name="apps")
|
||||
def test_lazy_model_operation(self, apps):
|
||||
"""
|
||||
Tests apps.lazy_model_operation().
|
||||
@@ -326,15 +339,20 @@ class AppsTests(SimpleTestCase):
|
||||
pass
|
||||
|
||||
# Test models appearing twice, and models appearing consecutively
|
||||
model_keys = [('apps', model_name) for model_name in ['lazya', 'lazyb', 'lazyb', 'lazyc', 'lazya']]
|
||||
model_keys = [
|
||||
("apps", model_name)
|
||||
for model_name in ["lazya", "lazyb", "lazyb", "lazyc", "lazya"]
|
||||
]
|
||||
apps.lazy_model_operation(test_func, *model_keys)
|
||||
|
||||
# LazyModelA shouldn't be waited on since it's already registered,
|
||||
# and LazyModelC shouldn't be waited on until LazyModelB exists.
|
||||
self.assertEqual(set(apps._pending_operations) - initial_pending, {('apps', 'lazyb')})
|
||||
self.assertEqual(
|
||||
set(apps._pending_operations) - initial_pending, {("apps", "lazyb")}
|
||||
)
|
||||
|
||||
# Multiple operations can wait on the same model
|
||||
apps.lazy_model_operation(test_func, ('apps', 'lazyb'))
|
||||
apps.lazy_model_operation(test_func, ("apps", "lazyb"))
|
||||
|
||||
class LazyB(models.Model):
|
||||
pass
|
||||
@@ -342,7 +360,9 @@ class AppsTests(SimpleTestCase):
|
||||
self.assertEqual(model_classes, [LazyB])
|
||||
|
||||
# Now we are just waiting on LazyModelC.
|
||||
self.assertEqual(set(apps._pending_operations) - initial_pending, {('apps', 'lazyc')})
|
||||
self.assertEqual(
|
||||
set(apps._pending_operations) - initial_pending, {("apps", "lazyc")}
|
||||
)
|
||||
|
||||
class LazyC(models.Model):
|
||||
pass
|
||||
@@ -358,104 +378,107 @@ class Stub:
|
||||
|
||||
class AppConfigTests(SimpleTestCase):
|
||||
"""Unit tests for AppConfig class."""
|
||||
|
||||
def test_path_set_explicitly(self):
|
||||
"""If subclass sets path as class attr, no module attributes needed."""
|
||||
|
||||
class MyAppConfig(AppConfig):
|
||||
path = 'foo'
|
||||
path = "foo"
|
||||
|
||||
ac = MyAppConfig('label', Stub())
|
||||
ac = MyAppConfig("label", Stub())
|
||||
|
||||
self.assertEqual(ac.path, 'foo')
|
||||
self.assertEqual(ac.path, "foo")
|
||||
|
||||
def test_explicit_path_overrides(self):
|
||||
"""If path set as class attr, overrides __path__ and __file__."""
|
||||
|
||||
class MyAppConfig(AppConfig):
|
||||
path = 'foo'
|
||||
path = "foo"
|
||||
|
||||
ac = MyAppConfig('label', Stub(__path__=['a'], __file__='b/__init__.py'))
|
||||
ac = MyAppConfig("label", Stub(__path__=["a"], __file__="b/__init__.py"))
|
||||
|
||||
self.assertEqual(ac.path, 'foo')
|
||||
self.assertEqual(ac.path, "foo")
|
||||
|
||||
def test_dunder_path(self):
|
||||
"""If single element in __path__, use it (in preference to __file__)."""
|
||||
ac = AppConfig('label', Stub(__path__=['a'], __file__='b/__init__.py'))
|
||||
ac = AppConfig("label", Stub(__path__=["a"], __file__="b/__init__.py"))
|
||||
|
||||
self.assertEqual(ac.path, 'a')
|
||||
self.assertEqual(ac.path, "a")
|
||||
|
||||
def test_no_dunder_path_fallback_to_dunder_file(self):
|
||||
"""If there is no __path__ attr, use __file__."""
|
||||
ac = AppConfig('label', Stub(__file__='b/__init__.py'))
|
||||
ac = AppConfig("label", Stub(__file__="b/__init__.py"))
|
||||
|
||||
self.assertEqual(ac.path, 'b')
|
||||
self.assertEqual(ac.path, "b")
|
||||
|
||||
def test_empty_dunder_path_fallback_to_dunder_file(self):
|
||||
"""If the __path__ attr is empty, use __file__ if set."""
|
||||
ac = AppConfig('label', Stub(__path__=[], __file__='b/__init__.py'))
|
||||
ac = AppConfig("label", Stub(__path__=[], __file__="b/__init__.py"))
|
||||
|
||||
self.assertEqual(ac.path, 'b')
|
||||
self.assertEqual(ac.path, "b")
|
||||
|
||||
def test_multiple_dunder_path_fallback_to_dunder_file(self):
|
||||
"""If the __path__ attr is length>1, use __file__ if set."""
|
||||
ac = AppConfig('label', Stub(__path__=['a', 'b'], __file__='c/__init__.py'))
|
||||
ac = AppConfig("label", Stub(__path__=["a", "b"], __file__="c/__init__.py"))
|
||||
|
||||
self.assertEqual(ac.path, 'c')
|
||||
self.assertEqual(ac.path, "c")
|
||||
|
||||
def test_no_dunder_path_or_dunder_file(self):
|
||||
"""If there is no __path__ or __file__, raise ImproperlyConfigured."""
|
||||
with self.assertRaises(ImproperlyConfigured):
|
||||
AppConfig('label', Stub())
|
||||
AppConfig("label", Stub())
|
||||
|
||||
def test_empty_dunder_path_no_dunder_file(self):
|
||||
"""If the __path__ attr is empty and there is no __file__, raise."""
|
||||
with self.assertRaises(ImproperlyConfigured):
|
||||
AppConfig('label', Stub(__path__=[]))
|
||||
AppConfig("label", Stub(__path__=[]))
|
||||
|
||||
def test_multiple_dunder_path_no_dunder_file(self):
|
||||
"""If the __path__ attr is length>1 and there is no __file__, raise."""
|
||||
with self.assertRaises(ImproperlyConfigured):
|
||||
AppConfig('label', Stub(__path__=['a', 'b']))
|
||||
AppConfig("label", Stub(__path__=["a", "b"]))
|
||||
|
||||
def test_duplicate_dunder_path_no_dunder_file(self):
|
||||
"""
|
||||
If the __path__ attr contains duplicate paths and there is no
|
||||
__file__, they duplicates should be deduplicated (#25246).
|
||||
"""
|
||||
ac = AppConfig('label', Stub(__path__=['a', 'a']))
|
||||
self.assertEqual(ac.path, 'a')
|
||||
ac = AppConfig("label", Stub(__path__=["a", "a"]))
|
||||
self.assertEqual(ac.path, "a")
|
||||
|
||||
def test_repr(self):
|
||||
ac = AppConfig('label', Stub(__path__=['a']))
|
||||
self.assertEqual(repr(ac), '<AppConfig: label>')
|
||||
ac = AppConfig("label", Stub(__path__=["a"]))
|
||||
self.assertEqual(repr(ac), "<AppConfig: label>")
|
||||
|
||||
def test_invalid_label(self):
|
||||
class MyAppConfig(AppConfig):
|
||||
label = 'invalid.label'
|
||||
label = "invalid.label"
|
||||
|
||||
msg = "The app label 'invalid.label' is not a valid Python identifier."
|
||||
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
||||
MyAppConfig('test_app', Stub())
|
||||
MyAppConfig("test_app", Stub())
|
||||
|
||||
@override_settings(
|
||||
INSTALLED_APPS=['apps.apps.ModelPKAppsConfig'],
|
||||
DEFAULT_AUTO_FIELD='django.db.models.SmallAutoField',
|
||||
INSTALLED_APPS=["apps.apps.ModelPKAppsConfig"],
|
||||
DEFAULT_AUTO_FIELD="django.db.models.SmallAutoField",
|
||||
)
|
||||
def test_app_default_auto_field(self):
|
||||
apps_config = apps.get_app_config('apps')
|
||||
apps_config = apps.get_app_config("apps")
|
||||
self.assertEqual(
|
||||
apps_config.default_auto_field,
|
||||
'django.db.models.BigAutoField',
|
||||
"django.db.models.BigAutoField",
|
||||
)
|
||||
self.assertIs(apps_config._is_default_auto_field_overridden, True)
|
||||
|
||||
@override_settings(
|
||||
INSTALLED_APPS=['apps.apps.PlainAppsConfig'],
|
||||
DEFAULT_AUTO_FIELD='django.db.models.SmallAutoField',
|
||||
INSTALLED_APPS=["apps.apps.PlainAppsConfig"],
|
||||
DEFAULT_AUTO_FIELD="django.db.models.SmallAutoField",
|
||||
)
|
||||
def test_default_auto_field_setting(self):
|
||||
apps_config = apps.get_app_config('apps')
|
||||
apps_config = apps.get_app_config("apps")
|
||||
self.assertEqual(
|
||||
apps_config.default_auto_field,
|
||||
'django.db.models.SmallAutoField',
|
||||
"django.db.models.SmallAutoField",
|
||||
)
|
||||
self.assertIs(apps_config._is_default_auto_field_overridden, False)
|
||||
|
||||
@@ -465,17 +488,17 @@ class NamespacePackageAppTests(SimpleTestCase):
|
||||
# location for it (if its inside a normal package with an __init__.py that
|
||||
# isn't possible). In order to avoid cluttering the already-full tests/ dir
|
||||
# (which is on sys.path), we add these new entries to sys.path temporarily.
|
||||
base_location = os.path.join(HERE, 'namespace_package_base')
|
||||
other_location = os.path.join(HERE, 'namespace_package_other_base')
|
||||
app_path = os.path.join(base_location, 'nsapp')
|
||||
base_location = os.path.join(HERE, "namespace_package_base")
|
||||
other_location = os.path.join(HERE, "namespace_package_other_base")
|
||||
app_path = os.path.join(base_location, "nsapp")
|
||||
|
||||
def test_single_path(self):
|
||||
"""
|
||||
A Py3.3+ namespace package can be an app if it has only one path.
|
||||
"""
|
||||
with extend_sys_path(self.base_location):
|
||||
with self.settings(INSTALLED_APPS=['nsapp']):
|
||||
app_config = apps.get_app_config('nsapp')
|
||||
with self.settings(INSTALLED_APPS=["nsapp"]):
|
||||
app_config = apps.get_app_config("nsapp")
|
||||
self.assertEqual(app_config.path, self.app_path)
|
||||
|
||||
def test_multiple_paths(self):
|
||||
@@ -489,7 +512,7 @@ class NamespacePackageAppTests(SimpleTestCase):
|
||||
# components of the "nsapp" package.
|
||||
with extend_sys_path(self.base_location, self.other_location):
|
||||
with self.assertRaises(ImproperlyConfigured):
|
||||
with self.settings(INSTALLED_APPS=['nsapp']):
|
||||
with self.settings(INSTALLED_APPS=["nsapp"]):
|
||||
pass
|
||||
|
||||
def test_multiple_paths_explicit_path(self):
|
||||
@@ -499,6 +522,6 @@ class NamespacePackageAppTests(SimpleTestCase):
|
||||
# Temporarily add two directories to sys.path that both contain
|
||||
# components of the "nsapp" package.
|
||||
with extend_sys_path(self.base_location, self.other_location):
|
||||
with self.settings(INSTALLED_APPS=['nsapp.apps.NSAppConfig']):
|
||||
app_config = apps.get_app_config('nsapp')
|
||||
with self.settings(INSTALLED_APPS=["nsapp.apps.NSAppConfig"]):
|
||||
app_config = apps.get_app_config("nsapp")
|
||||
self.assertEqual(app_config.path, self.app_path)
|
||||
|
||||
Reference in New Issue
Block a user