Refs #32594 -- Added Signal.disconnect() test with a model class.

Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
This commit is contained in:
Hugo Cachitas 2021-03-31 10:55:37 +02:00 committed by Mariusz Felisiak
parent d915dd1c58
commit f83214a3e1
1 changed files with 25 additions and 0 deletions

View File

@ -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):