diff options
author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-12-18 11:19:56 +0100 |
---|---|---|
committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-12-22 11:39:17 +0100 |
commit | 742ed9878e7edbb7a11667c489c719c4d9ab82de (patch) | |
tree | d7a39020d0a9648f33911c92bab12928a3b6fb48 /tests/app_loading | |
parent | 73c9e65b75cd956410ae71f39fb2f6a9b7b45b42 (diff) | |
download | django-742ed9878e7edbb7a11667c489c719c4d9ab82de.tar.gz |
Refactored registration of models.
Got rid of AppConfig._stub. As a side effect, app_cache.app_configs now
only contains entries for applications that are in INSTALLED_APPS, which
is a good thing and will allow dramatic simplifications (which I will
perform in the next commit). That required adjusting all methods that
iterate on app_configs without checking the "installed" flag, hence the
large changes in get_model[s].
Introduced AppCache.all_models to store models:
- while the app cache is being populated and a suitable app config
object to register models isn't available yet;
- for applications that aren't in INSTALLED_APPS since they don't have
an app config any longer.
Replaced get_model(seed_cache=False) by registered_model() which can be
kept simple and safe to call at any time, and removed the seed_cache
argument to get_model[s]. There's no replacement for that private API.
Allowed non-master app caches to go through populate() as it is now
safe to do so. They were introduced in 1.7 so backwards compatibility
isn't a concern as long as the migrations framework keeps working.
Diffstat (limited to 'tests/app_loading')
-rw-r--r-- | tests/app_loading/tests.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/tests/app_loading/tests.py b/tests/app_loading/tests.py index b32f510a24..e282306ec0 100644 --- a/tests/app_loading/tests.py +++ b/tests/app_loading/tests.py @@ -22,6 +22,7 @@ class EggLoadingTest(TestCase): def tearDown(self): app_cache.app_configs['app_loading'].models = self._old_models + app_cache.all_models['app_loading'] = self._old_models app_cache._get_models_cache = {} sys.path = self.old_path @@ -80,9 +81,9 @@ class EggLoadingTest(TestCase): app_cache.master = True with override_settings(INSTALLED_APPS=('notexists',)): with self.assertRaises(ImportError): - app_cache.get_model('notexists', 'nomodel', seed_cache=True) + app_cache.get_model('notexists', 'nomodel') with self.assertRaises(ImportError): - app_cache.get_model('notexists', 'nomodel', seed_cache=True) + app_cache.get_model('notexists', 'nomodel') class GetModelsTest(TestCase): @@ -101,17 +102,17 @@ class GetModelsTest(TestCase): self.not_installed_module.NotInstalledModel) def test_get_models_only_returns_installed_models(self): - self.assertFalse( - "NotInstalledModel" in + self.assertNotIn( + "NotInstalledModel", [m.__name__ for m in app_cache.get_models()]) def test_get_models_with_app_label_only_returns_installed_models(self): 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 app_cache.get_models(only_installed=False)]) + self.assertIn( + "NotInstalledModel", + [m.__name__ for m in app_cache.get_models(only_installed=False)]) class NotInstalledModelsTest(TestCase): |