diff options
author | Mads Jensen <mje@inducks.org> | 2018-01-30 16:44:58 +0100 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2018-01-30 10:44:58 -0500 |
commit | 1500573620fe2d2bba421da80aa4d8298b9262e8 (patch) | |
tree | 285c5acd464b61d4da5a769862a5a36b99344137 /tests/apps | |
parent | 136bf5c2142ae3261669d02e2dd050c3141f7f2f (diff) | |
download | django-1500573620fe2d2bba421da80aa4d8298b9262e8.tar.gz |
Added test for Apps.get_models() when models_ready=False.
Diffstat (limited to 'tests/apps')
-rw-r--r-- | tests/apps/tests.py | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/tests/apps/tests.py b/tests/apps/tests.py index 2910220b94..2fec1d8b4c 100644 --- a/tests/apps/tests.py +++ b/tests/apps/tests.py @@ -45,9 +45,9 @@ class AppsTests(SimpleTestCase): Tests the ready property of the master registry. """ # The master app registry is always ready when the tests run. - self.assertTrue(apps.ready) + self.assertIs(apps.ready, True) # Non-master app registries are populated in __init__. - self.assertTrue(Apps().ready) + self.assertIs(Apps().ready, True) def test_bad_app_config(self): """ @@ -124,10 +124,10 @@ class AppsTests(SimpleTestCase): """ Tests apps.is_installed(). """ - self.assertTrue(apps.is_installed('django.contrib.admin')) - self.assertTrue(apps.is_installed('django.contrib.auth')) - self.assertTrue(apps.is_installed('django.contrib.staticfiles')) - self.assertFalse(apps.is_installed('django.contrib.admindocs')) + 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): @@ -184,6 +184,19 @@ class AppsTests(SimpleTestCase): new_apps.get_model("apps", "TotallyNormal") self.assertEqual(new_apps.get_model("apps", "SoAlternative"), SoAlternative) + def test_models_not_loaded(self): + """ + apps.get_models() raises an exception if apps.models_ready isn't True. + """ + apps.models_ready = False + try: + # The cache must be cleared to trigger the exception. + apps.get_models.cache_clear() + with self.assertRaisesMessage(AppRegistryNotReady, "Models aren't loaded yet."): + apps.get_models() + finally: + apps.models_ready = True + def test_dynamic_load(self): """ Makes a new model at runtime and ensures it goes into the right place. |