mirror of
https://github.com/django/django.git
synced 2024-12-27 03:25:58 +00:00
c935d7ffe3
While I was at it I also cleaned up the formatting of the docstrings a bit. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10831 bcc190cf-cafb-0310-a4f2-bffc1f526a37
29 lines
932 B
Python
29 lines
932 B
Python
from django.db.models import signals
|
|
from django.test import TestCase
|
|
from modeltests.signals.models import Person
|
|
|
|
class MyReceiver(object):
|
|
def __init__(self, param):
|
|
self.param = param
|
|
self._run = False
|
|
|
|
def __call__(self, signal, sender, **kwargs):
|
|
self._run = True
|
|
signal.disconnect(receiver=self, sender=sender)
|
|
|
|
class SignalTests(TestCase):
|
|
def test_disconnect_in_dispatch(self):
|
|
"""
|
|
Test that signals that disconnect when being called don't mess future
|
|
dispatching.
|
|
"""
|
|
a, b = MyReceiver(1), MyReceiver(2)
|
|
signals.post_save.connect(sender=Person, receiver=a)
|
|
signals.post_save.connect(sender=Person, receiver=b)
|
|
p = Person.objects.create(first_name='John', last_name='Smith')
|
|
|
|
self.failUnless(a._run)
|
|
self.failUnless(b._run)
|
|
self.assertEqual(signals.post_save.receivers, [])
|
|
|