- remove in_test block from production codeversion-14
@@ -471,9 +471,6 @@ class EmailAccount(Document): | |||||
# only append the emails with status != 'SEEN' if sync option is set to 'UNSEEN' | # only append the emails with status != 'SEEN' if sync option is set to 'UNSEEN' | ||||
mails.append(InboundMail(message, self, uid, seen_status, append_to)) | mails.append(InboundMail(message, self, uid, seen_status, append_to)) | ||||
if frappe.local.flags.in_test: | |||||
return [InboundMail(msg, self) for msg in test_mails or []] | |||||
if not self.enable_incoming: | if not self.enable_incoming: | ||||
return [] | return [] | ||||
@@ -386,10 +386,9 @@ class TestEmailAccount(unittest.TestCase): | |||||
self.assertEqual(inbox_mails, 2) | self.assertEqual(inbox_mails, 2) | ||||
self.assertEqual(test_folder_mails, 1) | self.assertEqual(test_folder_mails, 1) | ||||
@patch("frappe.local.flags.in_test", False) | |||||
@patch("frappe.email.receive.EmailServer.select_imap_folder", return_value=True) | @patch("frappe.email.receive.EmailServer.select_imap_folder", return_value=True) | ||||
@patch("frappe.email.receive.EmailServer.logout", side_effect=lambda: None) | @patch("frappe.email.receive.EmailServer.logout", side_effect=lambda: None) | ||||
def mocked_get_inbound_mails(email_account, messages={}, mocked_logout=None, mocked_select_imap_folder=None, mocked_in_test=None): | |||||
def mocked_get_inbound_mails(email_account, messages={}, mocked_logout=None, mocked_select_imap_folder=None): | |||||
from frappe.email.receive import EmailServer | from frappe.email.receive import EmailServer | ||||
def get_mocked_messages(**kwargs): | def get_mocked_messages(**kwargs): | ||||
@@ -400,10 +399,9 @@ class TestEmailAccount(unittest.TestCase): | |||||
return mails | return mails | ||||
@patch("frappe.local.flags.in_test", False) | |||||
@patch("frappe.email.receive.EmailServer.select_imap_folder", return_value=True) | @patch("frappe.email.receive.EmailServer.select_imap_folder", return_value=True) | ||||
@patch("frappe.email.receive.EmailServer.logout", side_effect=lambda: None) | @patch("frappe.email.receive.EmailServer.logout", side_effect=lambda: None) | ||||
def mocked_email_receive(email_account, messages={}, mocked_logout=None, mocked_select_imap_folder=None, mocked_in_test=None): | |||||
def mocked_email_receive(email_account, messages={}, mocked_logout=None, mocked_select_imap_folder=None): | |||||
def get_mocked_messages(**kwargs): | def get_mocked_messages(**kwargs): | ||||
return messages[kwargs["folder"]] | return messages[kwargs["folder"]] | ||||
@@ -3,6 +3,8 @@ | |||||
import unittest, frappe, re, email | import unittest, frappe, re, email | ||||
from frappe.email.doctype.email_account.test_email_account import TestEmailAccount | |||||
test_dependencies = ['Email Account'] | test_dependencies = ['Email Account'] | ||||
class TestEmail(unittest.TestCase): | class TestEmail(unittest.TestCase): | ||||
@@ -173,12 +175,34 @@ class TestEmail(unittest.TestCase): | |||||
frappe.db.delete("Communication", {"sender": "sukh@yyy.com"}) | frappe.db.delete("Communication", {"sender": "sukh@yyy.com"}) | ||||
with open(frappe.get_app_path('frappe', 'tests', 'data', 'email_with_image.txt'), 'r') as raw: | with open(frappe.get_app_path('frappe', 'tests', 'data', 'email_with_image.txt'), 'r') as raw: | ||||
mails = email_account.get_inbound_mails(test_mails=[raw.read()]) | |||||
messages = { | |||||
'"INBOX"': { # append_to = ToDo | |||||
'latest_messages': [ | |||||
raw.read() | |||||
], | |||||
'seen_status': { | |||||
2: 'UNSEEN' | |||||
}, | |||||
'uid_list': [2] | |||||
} | |||||
} | |||||
email_account = frappe.get_doc("Email Account", "_Test Email Account 1") | |||||
changed_flag = False | |||||
if not email_account.enable_incoming: | |||||
email_account.enable_incoming = True | |||||
changed_flag = True | |||||
mails = TestEmailAccount.mocked_get_inbound_mails(email_account, messages) | |||||
# mails = email_account.get_inbound_mails(test_mails=[raw.read()]) | |||||
communication = mails[0].process() | communication = mails[0].process() | ||||
self.assertTrue(re.search('''<img[^>]*src=["']/private/files/rtco1.png[^>]*>''', communication.content)) | self.assertTrue(re.search('''<img[^>]*src=["']/private/files/rtco1.png[^>]*>''', communication.content)) | ||||
self.assertTrue(re.search('''<img[^>]*src=["']/private/files/rtco2.png[^>]*>''', communication.content)) | self.assertTrue(re.search('''<img[^>]*src=["']/private/files/rtco2.png[^>]*>''', communication.content)) | ||||
if changed_flag: | |||||
email_account.enable_incoming = False | |||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
frappe.connect() | frappe.connect() | ||||