def on_post_created(self): self.thread.on_email_added(self) self.mailinglist.on_email_added(self) if not getattr(settings, "HYPERKITTY_BATCH_MODE", False): # For batch imports, let the cron job do the work from hyperkitty.tasks import check_orphans check_orphans(self.id)
def test_check_orphans(self): # Create an orphan: the reply arrived first msg_reply = EmailMessage() msg_reply["From"] = "*****@*****.**" msg_reply["Message-ID"] = "<msgid2>" msg_reply["In-Reply-To"] = "<msgid1>" msg_reply.set_payload("reply") msg_orig = EmailMessage() msg_orig["From"] = "*****@*****.**" msg_orig["Message-ID"] = "<msgid1>" msg_orig.set_payload("original message") with patch("hyperkitty.tasks.check_orphans") as mock_co: add_to_list("example-list", msg_reply) add_to_list("example-list", msg_orig) self.assertEqual(mock_co.call_count, 2) orig = Email.objects.get(message_id="msgid1") reply = Email.objects.get(message_id="msgid2") self.assertIsNone(reply.parent) # Now call the check_orphans function tasks.check_orphans(orig.id) reply.refresh_from_db() self.assertEqual(reply.parent_id, orig.pk)
def test_check_orphans_no_email(self): try: tasks.check_orphans(42) except Email.DoesNotExist: self.fail("No protection when the email is deleted")