diff options
author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-12-11 23:31:34 +0100 |
---|---|---|
committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-12-17 10:17:44 +0100 |
commit | 8662654d6d50e4d89f771a757ae5fc83c6b74db0 (patch) | |
tree | 1b9d98842d25a5d15a389bcc0dcefdc4fcffef4f /tests/app_loading | |
parent | 334551339de38569ac3530886e3f9cc681190224 (diff) | |
download | django-8662654d6d50e4d89f771a757ae5fc83c6b74db0.tar.gz |
Removed module-level functions for the app cache.
Since the original ones in django.db.models.loading were kept only for
backwards compatibility, there's no need to recreate them. However, many
internals of Django still relied on them.
They were also imported in django.db.models. They never appear in the
documentation, except a quick mention of get_models and get_app in the
1.2 release notes to document an edge case in GIS. I don't think that
makes them a public API.
This commit doesn't change the overall amount of global state but
clarifies that it's tied to the app_cache object instead of hiding it
behind half a dozen functions.
Diffstat (limited to 'tests/app_loading')
-rw-r--r-- | tests/app_loading/tests.py | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/tests/app_loading/tests.py b/tests/app_loading/tests.py index a8a5ba120f..b24522fab6 100644 --- a/tests/app_loading/tests.py +++ b/tests/app_loading/tests.py @@ -5,7 +5,8 @@ import os import sys from unittest import TestCase -from django.apps.cache import cache, load_app, get_model, get_models, AppCache +from django.apps import app_cache +from django.apps.cache import AppCache from django.test.utils import override_settings from django.utils._os import upath @@ -19,48 +20,48 @@ class EggLoadingTest(TestCase): # This test adds dummy applications to the app cache. These # need to be removed in order to prevent bad interactions # with the flush operation in other tests. - self.old_app_models = copy.deepcopy(cache.app_models) + self.old_app_models = copy.deepcopy(app_cache.app_models) def tearDown(self): sys.path = self.old_path - cache.app_models = self.old_app_models + app_cache.app_models = self.old_app_models def test_egg1(self): """Models module can be loaded from an app in an egg""" egg_name = '%s/modelapp.egg' % self.egg_dir sys.path.append(egg_name) - models = load_app('app_with_models') + models = app_cache.load_app('app_with_models') self.assertFalse(models is None) def test_egg2(self): """Loading an app from an egg that has no models returns no models (and no error)""" egg_name = '%s/nomodelapp.egg' % self.egg_dir sys.path.append(egg_name) - models = load_app('app_no_models') + models = app_cache.load_app('app_no_models') self.assertTrue(models is None) def test_egg3(self): """Models module can be loaded from an app located under an egg's top-level package""" egg_name = '%s/omelet.egg' % self.egg_dir sys.path.append(egg_name) - models = load_app('omelet.app_with_models') + models = app_cache.load_app('omelet.app_with_models') self.assertFalse(models is None) def test_egg4(self): """Loading an app with no models from under the top-level egg package generates no error""" egg_name = '%s/omelet.egg' % self.egg_dir sys.path.append(egg_name) - models = load_app('omelet.app_no_models') + models = app_cache.load_app('omelet.app_no_models') self.assertTrue(models is None) def test_egg5(self): """Loading an app from an egg that has an import error in its models module raises that error""" egg_name = '%s/brokenapp.egg' % self.egg_dir sys.path.append(egg_name) - self.assertRaises(ImportError, load_app, 'broken_app') + self.assertRaises(ImportError, app_cache.load_app, 'broken_app') raised = None try: - load_app('broken_app') + app_cache.load_app('broken_app') except ImportError as e: raised = e @@ -81,8 +82,8 @@ class EggLoadingTest(TestCase): a.loaded = False try: with override_settings(INSTALLED_APPS=('notexists',)): - self.assertRaises(ImportError, get_model, 'notexists', 'nomodel', seed_cache=True) - self.assertRaises(ImportError, get_model, 'notexists', 'nomodel', seed_cache=True) + self.assertRaises(ImportError, app_cache.get_model, 'notexists', 'nomodel', seed_cache=True) + self.assertRaises(ImportError, app_cache.get_model, 'notexists', 'nomodel', seed_cache=True) finally: a.loaded = True @@ -94,26 +95,26 @@ class GetModelsTest(TestCase): def test_get_model_only_returns_installed_models(self): self.assertEqual( - get_model("not_installed", "NotInstalledModel"), None) + app_cache.get_model("not_installed", "NotInstalledModel"), None) def test_get_model_with_not_installed(self): self.assertEqual( - get_model( + app_cache.get_model( "not_installed", "NotInstalledModel", only_installed=False), self.not_installed_module.NotInstalledModel) def test_get_models_only_returns_installed_models(self): self.assertFalse( "NotInstalledModel" in - [m.__name__ for m in get_models()]) + [m.__name__ for m in app_cache.get_models()]) def test_get_models_with_app_label_only_returns_installed_models(self): - self.assertEqual(get_models(self.not_installed_module), []) + self.assertEqual(app_cache.get_models(self.not_installed_module), []) def test_get_models_with_not_installed(self): self.assertTrue( "NotInstalledModel" in [ - m.__name__ for m in get_models(only_installed=False)]) + m.__name__ for m in app_cache.get_models(only_installed=False)]) class NotInstalledModelsTest(TestCase): |