test: email queue sender with always_use_account_name_as_sender_name and always_use_account_email_id_as_sender
This commit is contained in:
parent
f8d7151e19
commit
5236aeb4b0
1 changed files with 32 additions and 8 deletions
|
|
@ -3,9 +3,11 @@
|
|||
|
||||
import email
|
||||
import re
|
||||
from unittest.mock import patch
|
||||
|
||||
import frappe
|
||||
from frappe.email.doctype.email_account.test_email_account import TestEmailAccount
|
||||
from frappe.email.doctype.email_queue.email_queue import QueueBuilder
|
||||
from frappe.tests.utils import FrappeTestCase
|
||||
|
||||
test_dependencies = ["Email Account"]
|
||||
|
|
@ -228,8 +230,37 @@ class TestEmail(FrappeTestCase):
|
|||
self.assertTrue("test1@example.com" in queue_recipients)
|
||||
self.assertEqual(len(queue_recipients), 2)
|
||||
|
||||
def test_sender(self):
|
||||
def _patched_assertion(email_account, assertion):
|
||||
with patch.object(QueueBuilder, "get_outgoing_email_account", return_value=email_account):
|
||||
frappe.sendmail(
|
||||
recipients=["test1@example.com"],
|
||||
sender="admin@example.com",
|
||||
subject="Test Email Queue",
|
||||
message="This mail is queued!",
|
||||
now=True,
|
||||
)
|
||||
email_queue_sender = frappe.db.get_value("Email Queue", {"status": "Sent"}, "sender")
|
||||
self.assertEqual(email_queue_sender, assertion)
|
||||
|
||||
email_account = frappe.get_doc("Email Account", "_Test Email Account 1")
|
||||
email_account.default_outgoing = 1
|
||||
|
||||
email_account.always_use_account_name_as_sender_name = 0
|
||||
email_account.always_use_account_email_id_as_sender = 0
|
||||
_patched_assertion(email_account, "admin@example.com")
|
||||
|
||||
email_account.always_use_account_name_as_sender_name = 1
|
||||
_patched_assertion(email_account, "_Test Email Account 1 <admin@example.com>")
|
||||
|
||||
email_account.always_use_account_name_as_sender_name = 0
|
||||
email_account.always_use_account_email_id_as_sender = 1
|
||||
_patched_assertion(email_account, '"admin@example.com" <test@example.com>')
|
||||
|
||||
email_account.always_use_account_name_as_sender_name = 1
|
||||
_patched_assertion(email_account, "_Test Email Account 1 <test@example.com>")
|
||||
|
||||
def test_unsubscribe(self):
|
||||
from frappe.email.doctype.email_queue.email_queue import QueueBuilder
|
||||
from frappe.email.queue import unsubscribe
|
||||
|
||||
unsubscribe(doctype="User", name="Administrator", email="test@example.com")
|
||||
|
|
@ -322,10 +353,3 @@ class TestVerifiedRequests(FrappeTestCase):
|
|||
set_request(method="GET", path="?" + signed_url)
|
||||
self.assertTrue(verify_request())
|
||||
frappe.local.request = None
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import unittest
|
||||
|
||||
frappe.connect()
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue