chore: add in a test for failed email notification
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
parent
e72b03adaf
commit
41d524c9a0
1 changed files with 39 additions and 0 deletions
|
|
@ -1,7 +1,9 @@
|
|||
# Copyright (c) 2015, Frappe Technologies and Contributors
|
||||
# License: MIT. See LICENSE
|
||||
import textwrap
|
||||
|
||||
import frappe
|
||||
from frappe.email.doctype.email_queue.email_queue import SendMailContext, get_email_retry_limit
|
||||
from frappe.tests.utils import FrappeTestCase
|
||||
|
||||
|
||||
|
|
@ -39,3 +41,40 @@ class TestEmailQueue(FrappeTestCase):
|
|||
|
||||
self.assertTrue(frappe.db.exists("Email Queue", new_record.name))
|
||||
self.assertTrue(frappe.db.exists("Email Queue Recipient", {"parent": new_record.name}))
|
||||
|
||||
def test_failed_email_notification(self):
|
||||
subject = frappe.generate_hash()
|
||||
email_record = frappe.new_doc("Email Queue")
|
||||
email_record.sender = "Test <test@example.com>"
|
||||
email_record.message = textwrap.dedent(
|
||||
f"""\
|
||||
MIME-Version: 1.0
|
||||
Message-Id: {frappe.generate_hash()}
|
||||
X-Original-From: Test <test@example.com>
|
||||
Subject: {subject}
|
||||
From: Test <test@example.com>
|
||||
To: <!--recipient-->
|
||||
Date: {frappe.utils.now_datetime().strftime('%a, %d %b %Y %H:%M:%S %z')}
|
||||
Reply-To: test@example.com
|
||||
X-Frappe-Site: {frappe.local.site}
|
||||
"""
|
||||
)
|
||||
email_record.status = "Error"
|
||||
email_record.retry = get_email_retry_limit()
|
||||
email_record.priority = 1
|
||||
email_record.reference_doctype = "User"
|
||||
email_record.reference_name = "Administrator"
|
||||
email_record.insert()
|
||||
|
||||
# Simulate an exception so that we get a notification
|
||||
try:
|
||||
with SendMailContext(queue_doc=email_record):
|
||||
raise Exception("Test Exception")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
notification_log = frappe.db.get_value(
|
||||
"Notification Log",
|
||||
{"subject": f"Failed to send email with subject: {subject}"},
|
||||
)
|
||||
self.assertTrue(notification_log)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue