From f83214a3e15ccadc9e2370dd157ed19bcdb07e2c Mon Sep 17 00:00:00 2001 From: Hugo Cachitas Date: Wed, 31 Mar 2021 10:55:37 +0200 Subject: [PATCH] Refs #32594 -- Added Signal.disconnect() test with a model class. Co-authored-by: Mariusz Felisiak --- tests/signals/tests.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/signals/tests.py b/tests/signals/tests.py index e0a24ccc6e..ee4661c93f 100644 --- a/tests/signals/tests.py +++ b/tests/signals/tests.py @@ -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):