summaryrefslogtreecommitdiff
path: root/tests/model_validation
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2013-11-04 23:11:51 -0500
committerSimon Charette <charette.s@gmail.com>2013-11-24 17:51:22 -0500
commiteb38257e5199ca06b8b32f82dd50f64fd6b0d98d (patch)
tree218b5face70be2baaffaabd3e5dac009a227727e /tests/model_validation
parent03bc0a8ac5b465a9a1ec88dedb0a2f4bd91dd547 (diff)
Fixed #21391 -- Allow model signals to lazily reference their senders.
Diffstat (limited to 'tests/model_validation')
-rw-r--r--tests/model_validation/tests.py34
1 files changed, 33 insertions, 1 deletions
diff --git a/tests/model_validation/tests.py b/tests/model_validation/tests.py
index 494af97f96..c55a1307e1 100644
--- a/tests/model_validation/tests.py
+++ b/tests/model_validation/tests.py
@@ -1,10 +1,22 @@
from django.core import management
+from django.core.management.validation import (
+ ModelErrorCollection, validate_model_signals
+)
+from django.db.models.signals import post_init
from django.test import TestCase
from django.utils import six
-class ModelValidationTest(TestCase):
+class OnPostInit(object):
+ def __call__(self, **kwargs):
+ pass
+
+
+def on_post_init(**kwargs):
+ pass
+
+class ModelValidationTest(TestCase):
def test_models_validate(self):
# All our models should validate properly
# Validation Tests:
@@ -13,3 +25,23 @@ class ModelValidationTest(TestCase):
# * related_name='+' doesn't clash with another '+'
# See: https://code.djangoproject.com/ticket/21375
management.call_command("validate", stdout=six.StringIO())
+
+ def test_model_signal(self):
+ unresolved_references = post_init.unresolved_references.copy()
+ post_init.connect(on_post_init, sender='missing-app.Model')
+ post_init.connect(OnPostInit(), sender='missing-app.Model')
+ e = ModelErrorCollection(six.StringIO())
+ validate_model_signals(e)
+ self.assertSetEqual(set(e.errors), {
+ ('model_validation.tests',
+ "The `on_post_init` function was connected to the `post_init` "
+ "signal with a lazy reference to the 'missing-app.Model' "
+ "sender, which has not been installed."
+ ),
+ ('model_validation.tests',
+ "An instance of the `OnPostInit` class was connected to "
+ "the `post_init` signal with a lazy reference to the "
+ "'missing-app.Model' sender, which has not been installed."
+ )
+ })
+ post_init.unresolved_references = unresolved_references