Ver código fonte

feat: add tests for imap folders email syncing with multiple folders

version-14
kamaljohnson 3 anos atrás
pai
commit
3734dc7927
4 arquivos alterados com 145 adições e 8 exclusões
  1. +8
    -2
      frappe/email/doctype/email_account/email_account.py
  2. +55
    -5
      frappe/email/doctype/email_account/test_email_account.py
  3. +81
    -0
      frappe/email/doctype/email_account/test_mails/messages-1.raw
  4. +1
    -1
      frappe/email/doctype/email_account/test_records.json

+ 8
- 2
frappe/email/doctype/email_account/email_account.py Ver arquivo

@@ -457,7 +457,7 @@ class EmailAccount(Document):
if exceptions:
raise Exception(frappe.as_json(exceptions))

def get_inbound_mails(self, test_mails=None) -> List[InboundMail]:
def get_inbound_mails(self, test_mails=None, messages=None) -> List[InboundMail]:
"""retrive and return inbound mails.

"""
@@ -472,7 +472,13 @@ class EmailAccount(Document):
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 self.enable_incoming:
for folder in self.imap_folder:
_messages = messages[folder.folder_name] if folder.folder_name in messages and ( messages[folder.folder_name] is not None) else {}
process_mail(_messages, folder.append_to)
return mails
else:
return [InboundMail(msg, self) for msg in test_mails or []]

if not self.enable_incoming:
return []


+ 55
- 5
frappe/email/doctype/email_account/test_email_account.py Ver arquivo

@@ -247,14 +247,64 @@ class TestEmailAccount(unittest.TestCase):
email_account.validate()

def test_append_to(self):
email_aacount = frappe.get_doc("Email Account", "_Test Email Account 1")
email_account = frappe.get_doc("Email Account", "_Test Email Account 1")
mail_content = self.get_test_mail(fname="incoming-2.raw")

inbound_mail = InboundMail(mail_content, email_aacount, 12345, 1, 'ToDo')
inbound_mail = InboundMail(mail_content, email_account, 12345, 1, 'ToDo')
communication = inbound_mail.process()
if inbound_mail.append_to == 'ToDo':
self.assertEqual(communication.reference_doctype, 'ToDo')
self.assertTrue(communication.reference_name)
# the append_to for the email is set to ToDO in "_Test Email Account 1"
self.assertEqual(communication.reference_doctype, 'ToDo')
self.assertTrue(communication.reference_name)
self.assertTrue(frappe.db.exists(communication.reference_doctype, communication.reference_name))

def test_append_to_with_imap_folders(self):
email_account = frappe.get_doc("Email Account", "_Test Email Account 1")

mail_content_1 = self.get_test_mail(fname="incoming-1.raw")
mail_content_2 = self.get_test_mail(fname="incoming-2.raw")
mail_content_3 = self.get_test_mail(fname="incoming-3.raw")

messages = {
'INBOX': { # append_to = ToDo
'latest_messages': [
mail_content_1,
mail_content_2
],
'seen_status': {
0: 'UNSEEN',
1: 'UNSEEN'
},
'uid_list': [0,1]
},
'Test Folder': { # append_to = Communication
'latest_messages': [
mail_content_3
],
'seen_status': {
2: 'UNSEEN'
},
'uid_list': [2]
}
}
mails = email_account.get_inbound_mails(messages=messages)
self.assertEqual(len(mails), 3)
inbox_mails = 0
test_folder_mails = 0

for mail in mails:
communication = mail.process()
if mail.append_to == 'ToDo':
inbox_mails += 1
self.assertEqual(communication.reference_doctype, 'ToDo')
self.assertTrue(communication.reference_name)
self.assertTrue(frappe.db.exists(communication.reference_doctype, communication.reference_name))
else:
test_folder_mails += 1
self.assertEqual(communication.reference_doctype, None)

self.assertEqual(inbox_mails, 2)
self.assertEqual(test_folder_mails, 1)

class TestInboundMail(unittest.TestCase):
@classmethod


+ 81
- 0
frappe/email/doctype/email_account/test_mails/messages-1.raw Ver arquivo

@@ -0,0 +1,81 @@
Delivered-To: kamal@frappe.io
Received: by 2002:a59:bcaf:0:b0:283:bf56:ecc6 with SMTP id q15csp1608707vqy;
Tue, 1 Feb 2022 18:36:19 -0800 (PST)
X-Received: by 2002:a05:6638:d06:: with SMTP id q6mr5074243jaj.197.1643769379814;
Tue, 01 Feb 2022 18:36:19 -0800 (PST)
ARC-Seal: i=1; a=rsa-sha256; t=1643769379; cv=none;
d=google.com; s=arc-20160816;
b=V0+D/66dKKmy7d5BdoHKohecWHF6PhMgtgarnemPm8UaOL5S5WyGUWt+azZZLK0HcU
TkxA3HY+/UlO3BjdmvY9hHtprPzTgK0U27S7sboIEQJXLblKfx9OOL2Wq0cS6YSlTcXQ
OIZaDepuJ9u7KUhRiHbmQCYXWmDdG0syALsONwjfXVBwqHn9wGizHbkp7tBCrgGbSfiF
NQgNOiwnau1jC48T+IKm7+9/1gqSWpU5c+4iWEDzmDaUTyE69XrHoAsThPXQ1FTn7beC
taVnDkMXIpJcOBJZLIWJLCKhju2oBz5EkX4j/IkNAnOIw40RAV/s9HT5DZUDjPoMd8g+
IrGw==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
h=to:subject:message-id:date:from:mime-version:dkim-signature;
bh=8ECAAGQ3yaTI5Xt9rqRpk+teGEit3tpBNmAS2780QKw=;
b=OjYxw0kvdSTP3Z+jAiU8LQJ65Ej6FAdZxEpUb8xvpFiP96kvRKkGEGhMFabPXDUXMn
mEeKI1Ocqm55b1XUWY44EK5E/eecA651SbIKvR/ihOXzrnPD3hItfj9S2PsgjyQp+rX1
+vREp5o1A+tWbFI3smRYPqWUv1g7J5hRzCXjI1FyNI1OdkJn7K9PlEsR1xqjflGDmOif
nfglNmrkjCMIw9XHQ91rMY1ta+yrVvVeDFVLLBV4R0yCL/DrpmozSDViZPNzMmo6ITRQ
T+/qkuku9aBReM1XebA7mLKPrPGuU27l2GJX4hpsz0gEYDpItf53MEaO5XIkoELo0b8s
AxRQ==
ARC-Authentication-Results: i=1; mx.google.com;
dkim=pass header.i=@gmail.com header.s=20210112 header.b=J6sQ2r3s;
spf=pass (google.com: domain of kamaljohnson12345@gmail.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=kamaljohnson12345@gmail.com;
dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com
Return-Path: <kamaljohnson12345@gmail.com>
Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41])
by mx.google.com with SMTPS id 1sor6796918jao.124.2022.02.01.18.36.19
for <kamal@frappe.io>
(Google Transport Security);
Tue, 01 Feb 2022 18:36:19 -0800 (PST)
Received-SPF: pass (google.com: domain of kamaljohnson12345@gmail.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41;
Authentication-Results: mx.google.com;
dkim=pass header.i=@gmail.com header.s=20210112 header.b=J6sQ2r3s;
spf=pass (google.com: domain of kamaljohnson12345@gmail.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=kamaljohnson12345@gmail.com;
dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20210112;
h=mime-version:from:date:message-id:subject:to;
bh=8ECAAGQ3yaTI5Xt9rqRpk+teGEit3tpBNmAS2780QKw=;
b=J6sQ2r3s24Gj5ATpKCyjleWOaF9+9rvwKg/NJ979EpEvy13v4rRX4gL7xbX8GIVkZ4
QoOl3xUNtRItJPYWuW984GXsmL5v8YrakCb0JzS5iWk3VC+Q+orhk95giHDLx/1UrTeK
KFhLQ632i23M2IutOA4vRVet3n4wnmYwXiJZ1G/HoE70h+1Jn+E0nsvBsz8IU5eWHve7
SKWAaEtUOwcyuLi9SncQh62bM9ZW6V034LEb0MXz/suAJ+sPIvjSSNJwehKpvYfg1AUt
CkzuAxJt17MThTwz+/YCZkttN7LKDeBAUJWh2+JB+BfyvzYR1pUyJfwLhRMNYoeWZpGK
L/6g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:from:date:message-id:subject:to;
bh=8ECAAGQ3yaTI5Xt9rqRpk+teGEit3tpBNmAS2780QKw=;
b=CyVqLYduXIsBE7f62ti9wFFkTv/Vn6anf1UtnakmhgeWksW0nvjOjnAdytXHiD5Phl
vtTpmCGgLVcTZBI8wUaKdjsGDVWnpG8zYRQljytyrptyi+M4ShnUMq2WbyceeFFop+Ta
5z/0PE3wva+H45uj2ICRu2l0o1nvjNKxt14zzbaCYgUyx2ZF24MLgIO2ko1xnTXS6M5g
ASnc4ia+9r3MhLa3y3Ss97KYRcLXeVzbqEXS4X3DB1h+/tHLogLTAX5D8w5LME7M0MfR
uy4dC0K4VmhhDJTzoFHzgBqWw1vqNU/G92Fr/kZdVzMiSegt0Up76ePA8mwpeEKzaNdP
e4wg==
X-Gm-Message-State: AOAM532tem+DamkNGjOKo5Ayzg9Gdh0clTzSw+ajeLwzgcNy/fNYBVhC
YHvVK8Ylvd0Jr8XjwshuyN/hz8UOoV2fkjOij9CED3Vo
X-Google-Smtp-Source: ABdhPJwB/h4hp6eiaPL7IIkokMwriJ92sqjBOp3ptJnp+mtkZNAr8JNrt86gahMU24MuTsB8HUnK9oEXGRKV+55XO5U=
X-Received: by 2002:a02:c916:: with SMTP id t22mr15608489jao.300.1643769379473;
Tue, 01 Feb 2022 18:36:19 -0800 (PST)
MIME-Version: 1.0
From: Kamal Johnson <kamaljohnson12345@gmail.com>
Date: Wed, 2 Feb 2022 08:06:06 +0530
Message-ID: <CANAS5e6S2MwWG4nTjMcd7Dr+TLS8pPTxK9Wd1=wLQp9c29t_3Q@mail.gmail.com>
Subject: Hfruuhhs
To: Kamal Johnson <kamal@frappe.io>
Content-Type: multipart/alternative; boundary="000000000000f4cb7505d6ffe106"

--000000000000f4cb7505d6ffe106
Content-Type: text/plain; charset="UTF-8"

Yysjtshsg

--000000000000f4cb7505d6ffe106
Content-Type: text/html; charset="UTF-8"

<div dir="auto">Yysjtshsg</div>

--000000000000f4cb7505d6ffe106--

+ 1
- 1
frappe/email/doctype/email_account/test_records.json Ver arquivo

@@ -20,7 +20,7 @@
"pop3_server": "pop.test.example.com",
"no_remaining":"0",
"append_to": "ToDo",
"imap_folder": [{"folder_name": "INBOX", "append_to": "ToDo"}],
"imap_folder": [{"folder_name": "INBOX", "append_to": "ToDo"}, {"folder_name": "Test Folder", "append_to": "Communication"}],
"track_email_status": 1
},
{


Carregando…
Cancelar
Salvar