summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2013-12-18 11:19:56 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2013-12-22 11:39:17 +0100
commit742ed9878e7edbb7a11667c489c719c4d9ab82de (patch)
treed7a39020d0a9648f33911c92bab12928a3b6fb48 /tests
parent73c9e65b75cd956410ae71f39fb2f6a9b7b45b42 (diff)
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')
-rw-r--r--tests/app_loading/tests.py15
-rw-r--r--tests/invalid_models/tests.py1
-rw-r--r--tests/managers_regress/tests.py3
-rw-r--r--tests/migrations/test_commands.py1
-rw-r--r--tests/proxy_model_inheritance/tests.py2
-rw-r--r--tests/proxy_models/tests.py1
-rw-r--r--tests/tablespaces/tests.py1
7 files changed, 17 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):
diff --git a/tests/invalid_models/tests.py b/tests/invalid_models/tests.py
index 712484c611..10d8fa47a7 100644
--- a/tests/invalid_models/tests.py
+++ b/tests/invalid_models/tests.py
@@ -24,6 +24,7 @@ class InvalidModelTestCase(unittest.TestCase):
def tearDown(self):
app_cache.app_configs['invalid_models'].models = self._old_models
+ app_cache.all_models['invalid_models'] = self._old_models
app_cache._get_models_cache = {}
sys.stdout = self.old_stdout
diff --git a/tests/managers_regress/tests.py b/tests/managers_regress/tests.py
index f2897862ec..b9c8244612 100644
--- a/tests/managers_regress/tests.py
+++ b/tests/managers_regress/tests.py
@@ -128,6 +128,7 @@ class ManagersRegressionTests(TestCase):
finally:
app_cache.app_configs['managers_regress'].models = _old_models
+ app_cache.all_models['managers_regress'] = _old_models
app_cache._get_models_cache = {}
@override_settings(TEST_SWAPPABLE_MODEL='managers_regress.Parent')
@@ -155,6 +156,7 @@ class ManagersRegressionTests(TestCase):
finally:
app_cache.app_configs['managers_regress'].models = _old_models
+ app_cache.all_models['managers_regress'] = _old_models
app_cache._get_models_cache = {}
@override_settings(TEST_SWAPPABLE_MODEL='managers_regress.Parent')
@@ -182,6 +184,7 @@ class ManagersRegressionTests(TestCase):
finally:
app_cache.app_configs['managers_regress'].models = _old_models
+ app_cache.all_models['managers_regress'] = _old_models
app_cache._get_models_cache = {}
def test_regress_3871(self):
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
index 59cd56e78b..13514cac91 100644
--- a/tests/migrations/test_commands.py
+++ b/tests/migrations/test_commands.py
@@ -135,6 +135,7 @@ class MakeMigrationsTests(MigrationTestBase):
def tearDown(self):
app_cache.app_configs['migrations'].models = self._old_models
+ app_cache.all_models['migrations'] = self._old_models
app_cache._get_models_cache = {}
os.chdir(self.test_dir)
diff --git a/tests/proxy_model_inheritance/tests.py b/tests/proxy_model_inheritance/tests.py
index 861ab4af17..601fdc5b42 100644
--- a/tests/proxy_model_inheritance/tests.py
+++ b/tests/proxy_model_inheritance/tests.py
@@ -34,6 +34,8 @@ class ProxyModelInheritanceTests(TransactionTestCase):
sys.path = self.old_sys_path
del app_cache.app_configs['app1']
del app_cache.app_configs['app2']
+ del app_cache.all_models['app1']
+ del app_cache.all_models['app2']
def test_table_exists(self):
try:
diff --git a/tests/proxy_models/tests.py b/tests/proxy_models/tests.py
index 3389f3597f..0995a778c0 100644
--- a/tests/proxy_models/tests.py
+++ b/tests/proxy_models/tests.py
@@ -175,6 +175,7 @@ class ProxyModelTests(TestCase):
proxy = True
finally:
app_cache.app_configs['proxy_models'].models = _old_models
+ app_cache.all_models['proxy_models'] = _old_models
app_cache._get_models_cache = {}
def test_myperson_manager(self):
diff --git a/tests/tablespaces/tests.py b/tests/tablespaces/tests.py
index 4a62ad5a45..fa90704c45 100644
--- a/tests/tablespaces/tests.py
+++ b/tests/tablespaces/tests.py
@@ -36,6 +36,7 @@ class TablespacesTests(TestCase):
model._meta.managed = False
app_cache.app_configs['tablespaces'].models = self._old_models
+ app_cache.all_models['tablespaces'] = self._old_models
app_cache._get_models_cache = {}
def assertNumContains(self, haystack, needle, count):