From 46a34e25e8ecae7e5ea9e0e8bc72c9819d97af2b Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Wed, 15 Nov 2023 00:01:13 +0100 Subject: [PATCH] test: parse links in email --- .../communication/test_communication.py | 44 +++++++------------ 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/frappe/core/doctype/communication/test_communication.py b/frappe/core/doctype/communication/test_communication.py index 90b2c624ec..aa0a7fe2e2 100644 --- a/frappe/core/doctype/communication/test_communication.py +++ b/frappe/core/doctype/communication/test_communication.py @@ -1,10 +1,9 @@ # Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors # License: MIT. See LICENSE from typing import TYPE_CHECKING -from urllib.parse import quote import frappe -from frappe.core.doctype.communication.communication import Communication, get_emails +from frappe.core.doctype.communication.communication import Communication, get_emails, parse_email from frappe.core.doctype.communication.email import add_attachments from frappe.email.doctype.email_queue.email_queue import EmailQueue from frappe.tests.utils import FrappeTestCase @@ -219,36 +218,25 @@ class TestCommunication(FrappeTestCase): self.assertIn(comm_note_1.name, data) self.assertIn(comm_note_2.name, data) - def test_link_in_email(self): - create_email_account() + def test_parse_email(self): + to = "Jon Doe " + cc = """=?UTF-8?Q?Max_Mu=C3=9F?= , + erp+Customer+that%20company@example.org""" + bcc = "" - notes = {} - for i in range(2): - frappe.delete_doc_if_exists("Note", f"test document link in email {i}") - notes[i] = frappe.get_doc( - { - "doctype": "Note", - "title": f"test document link in email {i}", - } - ).insert(ignore_permissions=True) + results = list(parse_email([to, cc, bcc])) + self.assertEqual([("Customer", "that company")], results) - comm = frappe.get_doc( - { - "doctype": "Communication", - "communication_medium": "Email", - "subject": "Document Link in Email", - "sender": "comm_sender@example.com", - "recipients": f'comm_recipient+{quote("Note")}+{quote(notes[0].name)}@example.com,comm_recipient+{quote("Note")}={quote(notes[1].name)}@example.com', - } - ).insert(ignore_permissions=True) + results = list(parse_email([to, bcc])) + self.assertEqual(results, []) - doc_links = [ - (timeline_link.link_doctype, timeline_link.link_name) for timeline_link in comm.timeline_links - ] - self.assertIn(("Note", notes[0].name), doc_links) - self.assertIn(("Note", notes[1].name), doc_links) + to = "jane.doe+A+Test@example.org" + cc = "" + bcc = "=?UTF-8?Q?Max_Mu=C3=9F?= " + results = list(parse_email([to, cc, bcc])) + self.assertEqual([("A", "Test"), ("Note", "Very important")], results) - def test_parse_emails(self): + def test_get_emails(self): emails = get_emails( [ "comm_recipient+DocType+DocName@example.com",