mirror of https://github.com/django/django.git
Refs #32594 -- Added Signal.disconnect() test with a model class.
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
This commit is contained in:
parent
d915dd1c58
commit
f83214a3e1
|
@ -280,6 +280,31 @@ class SignalTests(BaseSignalSetup, TestCase):
|
|||
signals.pre_init.disconnect(callback)
|
||||
ref.assert_not_called()
|
||||
|
||||
@isolate_apps('signals', kwarg_name='apps')
|
||||
def test_disconnect_model(self, apps):
|
||||
received = []
|
||||
|
||||
def receiver(**kwargs):
|
||||
received.append(kwargs)
|
||||
|
||||
class Created(models.Model):
|
||||
pass
|
||||
|
||||
signals.post_init.connect(receiver, sender=Created, apps=apps)
|
||||
try:
|
||||
self.assertIs(
|
||||
signals.post_init.disconnect(receiver, sender=Created, apps=apps),
|
||||
True,
|
||||
)
|
||||
self.assertIs(
|
||||
signals.post_init.disconnect(receiver, sender=Created, apps=apps),
|
||||
False,
|
||||
)
|
||||
Created()
|
||||
self.assertEqual(received, [])
|
||||
finally:
|
||||
signals.post_init.disconnect(receiver, sender=Created)
|
||||
|
||||
|
||||
class LazyModelRefTests(BaseSignalSetup, SimpleTestCase):
|
||||
def setUp(self):
|
||||
|
|
Loading…
Reference in New Issue