1
0
mirror of https://github.com/django/django.git synced 2024-12-25 10:35:48 +00:00
django/tests/modeltests/signals/tests.py
Jacob Kaplan-Moss c935d7ffe3 Fixed #11134: signals recievers that disconnect during their processing no longer mess things up for other handlers. Thanks, Honza Kral.
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
2009-05-20 16:13:55 +00:00

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, [])