summaryrefslogtreecommitdiff
path: root/tests/apps/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/apps/tests.py')
-rw-r--r--tests/apps/tests.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/apps/tests.py b/tests/apps/tests.py
index 89e295ffde..347996454f 100644
--- a/tests/apps/tests.py
+++ b/tests/apps/tests.py
@@ -259,6 +259,44 @@ class AppsTests(TestCase):
finally:
apps.apps_ready = True
+ def test_lazy_model_operation(self):
+ """
+ Tests apps.lazy_model_operation().
+ """
+ model_classes = []
+ initial_pending = set(apps._pending_operations)
+
+ def test_func(*models):
+ model_classes[:] = models
+
+ class LazyA(models.Model):
+ pass
+
+ # Test models appearing twice, and models appearing consecutively
+ model_keys = [('apps', model_name) for model_name in ['lazya', 'lazyb', 'lazyb', 'lazyc', 'lazya']]
+ apps.lazy_model_operation(test_func, *model_keys)
+
+ # LazyModelA shouldn't be waited on since it's already registered,
+ # and LazyModelC shouldn't be waited on until LazyModelB exists.
+ self.assertSetEqual(set(apps._pending_operations) - initial_pending, {('apps', 'lazyb')})
+
+ # Test that multiple operations can wait on the same model
+ apps.lazy_model_operation(test_func, ('apps', 'lazyb'))
+
+ class LazyB(models.Model):
+ pass
+
+ self.assertListEqual(model_classes, [LazyB])
+
+ # Now we are just waiting on LazyModelC.
+ self.assertSetEqual(set(apps._pending_operations) - initial_pending, {('apps', 'lazyc')})
+
+ class LazyC(models.Model):
+ pass
+
+ # Everything should be loaded - make sure the callback was executed properly.
+ self.assertListEqual(model_classes, [LazyA, LazyB, LazyB, LazyC, LazyA])
+
class Stub(object):
def __init__(self, **kwargs):