-1

Hi I have been trying to write the test case for the following post save signal, without any success. Can anyone help.

@receiver(post_save, sender=Item, dispatch_uid="item_created")
def notify_member_item_create(sender, instance, **kwargs):
        email_subject = "email_subject"
        email_body = "email_body"
        email_list = [instance.inventory.owner.email]
        send_mail(email_subject, email_body, settings.EMAIL_HOST_USER, email_list)

1 Answers1

0

Could you please more specific in your question? But if you need to write test for check how signal works you can write test like that

    def test_notify_member_item_create(self):
        Item.objects.create(name='test')
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].subject, 'email_subject')
Anna
  • 523
  • 3
  • 8