refactor: Removed parse package

This commit is contained in:
chillaranand 2022-07-12 19:28:11 +05:30
parent 4671460b65
commit d7bb903212
3 changed files with 29 additions and 7 deletions

View file

@ -5,7 +5,7 @@ from collections import Counter
from email.utils import getaddresses
from urllib.parse import unquote
from parse import compile
from bs4 import BeautifulSoup
import frappe
from frappe import _
@ -144,8 +144,8 @@ class Communication(Document, CommunicationEmailMixin):
if not self.content:
return
quill_parser = compile('<div class="ql-editor read-mode">{}</div>')
email_body = quill_parser.parse(self.content)
soup = BeautifulSoup(self.content, "html.parser")
email_body = soup.find("div", {"class": "ql-editor read-mode"})
if not email_body:
return
@ -169,7 +169,11 @@ class Communication(Document, CommunicationEmailMixin):
if not signature:
return
_signature = quill_parser.parse(signature)[0] if "ql-editor" in signature else None
soup = BeautifulSoup(signature, "html.parser")
html_signature = soup.find("div", {"class": "ql-editor read-mode"})
_signature = None
if html_signature:
_signature = html_signature.renderContents()
if (_signature or signature) not in self.content:
self.content = f'{self.content}</p><br><p class="signature">{signature}'

View file

@ -6,11 +6,12 @@ from urllib.parse import quote
import frappe
from frappe.core.doctype.communication.communication import get_emails
from frappe.email.doctype.email_queue.email_queue import EmailQueue
from frappe.tests.utils import FrappeTestCase
test_records = frappe.get_test_records("Communication")
class TestCommunication(unittest.TestCase):
class TestCommunication(FrappeTestCase):
def test_email(self):
valid_email_list = [
"Full Name <full@example.com>",
@ -259,8 +260,25 @@ class TestCommunication(unittest.TestCase):
self.assertEqual(emails[1], "first.lastname@email.com")
self.assertEqual(emails[2], "test@user.com")
def test_signature_in_email_content(self):
email_account = create_email_account()
signature = email_account.signature
comm = frappe.get_doc(
{
"doctype": "Communication",
"communication_medium": "Email",
"subject": "Document Link in Email",
"sender": "comm_sender@example.com",
"content": """<div class="ql-editor read-mode">
Hi,
How are you?
</div>""",
}
).insert(ignore_permissions=True)
assert signature in comm.content
class TestCommunicationEmailMixin(unittest.TestCase):
class TestCommunicationEmailMixin(FrappeTestCase):
def new_communication(self, recipients=None, cc=None, bcc=None):
recipients = ", ".join(recipients or [])
cc = ", ".join(cc or [])
@ -345,6 +363,7 @@ def create_email_account():
"append_to": "ToDo",
"email_account_name": "_Test Comm Account 1",
"enable_outgoing": 1,
"default_outgoing": 1,
"smtp_server": "test.example.com",
"email_id": "test_comm@example.com",
"password": "password",

View file

@ -43,7 +43,6 @@ dependencies = [
"num2words~=0.5.10",
"oauthlib~=3.1.0",
"openpyxl~=3.0.7",
"parse~=1.19.0",
"passlib~=1.7.4",
"pdfkit~=1.0.0",
"phonenumbers==8.12.40",