summaryrefslogtreecommitdiff
path: root/tests/apps/tests.py
diff options
context:
space:
mode:
authorIuri de Silvio <iurisilvio@gmail.com>2020-08-10 15:16:45 -0300
committerGitHub <noreply@github.com>2020-08-10 20:16:45 +0200
commitebd78a9f97d8ba850d279a844d89a1d805370738 (patch)
tree4098ba912720e049b27db7ae6583d3407e32c4c7 /tests/apps/tests.py
parentad827ddaef05069a1385cc2d26fd2ab9c6ba1f4d (diff)
Fixed #31870 -- Fixed crash when populating app registry with empty or without apps module.
Regression in 3f2821af6bc48fa8e7970c1ce27bc54c3172545e.
Diffstat (limited to 'tests/apps/tests.py')
-rw-r--r--tests/apps/tests.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/apps/tests.py b/tests/apps/tests.py
index f4b0a8879b..cf487a65da 100644
--- a/tests/apps/tests.py
+++ b/tests/apps/tests.py
@@ -10,9 +10,13 @@ from django.test.utils import extend_sys_path, isolate_apps
from django.utils.deprecation import RemovedInDjango41Warning
from .explicit_default_config_app.apps import ExplicitDefaultConfig
+from .explicit_default_config_empty_apps import ExplicitDefaultConfigEmptyApps
from .explicit_default_config_mismatch_app.not_apps import (
ExplicitDefaultConfigMismatch,
)
+from .explicit_default_config_without_apps import (
+ ExplicitDefaultConfigWithoutApps,
+)
from .models import SoAlternative, TotallyNormal, new_apps
from .one_config_app.apps import OneConfig
from .two_configs_one_default_app.apps import TwoConfig
@@ -520,3 +524,51 @@ class DeprecationTests(SimpleTestCase):
with self.settings(INSTALLED_APPS=['apps.explicit_default_config_mismatch_app']):
config = apps.get_app_config('explicit_default_config_mismatch_app')
self.assertIsInstance(config, ExplicitDefaultConfigMismatch)
+
+ def test_explicit_default_app_config_empty_apps(self):
+ """
+ Load an app that specifies a default AppConfig class in __init__ and
+ have an empty apps module.
+ """
+ msg = (
+ "'apps.explicit_default_config_empty_apps' defines "
+ "default_app_config = 'apps.explicit_default_config_empty_apps."
+ "ExplicitDefaultConfigEmptyApps'. However, Django's automatic "
+ "detection did not find this configuration. You should move the "
+ "default config class to the apps submodule of your application "
+ "and, if this module defines several config classes, mark the "
+ "default one with default = True."
+ )
+ with self.assertRaisesMessage(RemovedInDjango41Warning, msg):
+ with self.settings(INSTALLED_APPS=['apps.explicit_default_config_empty_apps']):
+ pass
+ with ignore_warnings(category=RemovedInDjango41Warning):
+ with self.settings(INSTALLED_APPS=['apps.explicit_default_config_empty_apps']):
+ self.assertIsInstance(
+ apps.get_app_config('explicit_default_config_empty_apps'),
+ ExplicitDefaultConfigEmptyApps,
+ )
+
+ def test_explicit_default_app_config_without_apps(self):
+ """
+ Load an app that specifies a default AppConfig class in __init__ and do
+ not have an apps module.
+ """
+ msg = (
+ "'apps.explicit_default_config_without_apps' defines "
+ "default_app_config = 'apps.explicit_default_config_without_apps."
+ "ExplicitDefaultConfigWithoutApps'. However, Django's automatic "
+ "detection did not find this configuration. You should move the "
+ "default config class to the apps submodule of your application "
+ "and, if this module defines several config classes, mark the "
+ "default one with default = True."
+ )
+ with self.assertRaisesMessage(RemovedInDjango41Warning, msg):
+ with self.settings(INSTALLED_APPS=['apps.explicit_default_config_without_apps']):
+ pass
+ with ignore_warnings(category=RemovedInDjango41Warning):
+ with self.settings(INSTALLED_APPS=['apps.explicit_default_config_without_apps']):
+ self.assertIsInstance(
+ apps.get_app_config('explicit_default_config_without_apps'),
+ ExplicitDefaultConfigWithoutApps,
+ )