I am using Django 3.2
I have written an app that raises custom events, and I am writing tests for the apps.
Here is the relevant section of my code:
class TestAppModel(TestCase):
# .. set up instance variables etc.
def test_liked_signal_emits_correct_data(self):
self.signal_was_called = False
self.sender = None
self.instance = None
self.event_type = None
self.actor = None
def handler(sender, instance, event_type, actor, **kwargs):
self.signal_was_called = True
self.sender = sender
self.instance = instance
self.event_type = event_type
self.actor = actor
item_liked.connect(handler)
self.daddy.like(self.admin_user)
# Check that the sender is a Foo
self.assertIsInstance(self.sender, Foo) # <- Nonsensical error emitted here
When I run the test, I get the error message:
AssertionError: <class 'social.models.Foo'> is not an instance of <class 'social.models.Foo'>
Which obviously, is a nonsensical error message that doesn't help me solve the problem.
My question is why am I not able to check the instance type using assertIsInstance, and how do I check the class type in the signal receiver?