[MIG] fetchmail_notify_error_to_sender_test: Migration to 17.0
parent
410c05b1c8
commit
1e8e228297
|
@ -67,6 +67,7 @@ Contributors
|
|||
- Denis Valenchyts <denis@ventor.tech> (VentorTech OU
|
||||
<https://ventor.tech>)
|
||||
- foram shah <foram.shah@initos.com>
|
||||
- Carlos Jimeno carlos.jimeno@braintec.com (https://braintec.com)
|
||||
|
||||
Maintainers
|
||||
-----------
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
{
|
||||
"name": "Fetchmail Notify Error to Sender Test",
|
||||
"summary": "Test for Fetchmail Notify Error to Sender",
|
||||
"version": "14.0.1.0.0",
|
||||
"version": "17.0.1.0.0",
|
||||
"category": "Tools",
|
||||
"author": "Agile Business Group,ForgeFlow,Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/server-tools",
|
||||
|
|
|
@ -7,3 +7,4 @@
|
|||
- Denis Valenchyts \<<denis@ventor.tech>\> (VentorTech OU
|
||||
\<<https://ventor.tech>\>)
|
||||
- foram shah \<<foram.shah@initos.com>\>
|
||||
- Carlos Jimeno <carlos.jimeno@braintec.com> (https://braintec.com)
|
||||
|
|
|
@ -413,6 +413,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
|
|||
<li>Denis Valenchyts <<a class="reference external" href="mailto:denis@ventor.tech">denis@ventor.tech</a>> (VentorTech OU
|
||||
<<a class="reference external" href="https://ventor.tech">https://ventor.tech</a>>)</li>
|
||||
<li>foram shah <<a class="reference external" href="mailto:foram.shah@initos.com">foram.shah@initos.com</a>></li>
|
||||
<li>Carlos Jimeno <a class="reference external" href="mailto:carlos.jimeno@braintec.com">carlos.jimeno@braintec.com</a> (<a class="reference external" href="https://braintec.com">https://braintec.com</a>)</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="maintainers">
|
||||
|
|
|
@ -10,28 +10,22 @@ from odoo.addons.test_mail.tests.test_mail_gateway import TestMailgateway
|
|||
|
||||
|
||||
class TestFetchmailNotifyErrorToSender(TestMailgateway):
|
||||
def setUp(self):
|
||||
super(TestFetchmailNotifyErrorToSender, self).setUp()
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
|
||||
self.fetchmail_server = self.env["fetchmail.server"].create(
|
||||
cls.fetchmail_server = cls.env["fetchmail.server"].create(
|
||||
{
|
||||
"name": "Test Fetchmail Server",
|
||||
"server_type": "imap",
|
||||
"error_notice_template_id": self.env.ref(
|
||||
"%s.%s"
|
||||
% (
|
||||
"fetchmail_notify_error_to_sender",
|
||||
"email_template_error_notice",
|
||||
)
|
||||
).id,
|
||||
}
|
||||
)
|
||||
|
||||
def format_and_process_with_context(
|
||||
self,
|
||||
template,
|
||||
to_email="groups@example.com, other@gmail.com",
|
||||
subject="Frogs",
|
||||
to_email="noone@example.com",
|
||||
subject="spam",
|
||||
extra="",
|
||||
email_from="Sylvie Lelitre <test.sylvie.lelitre@agrolait.com>",
|
||||
cc_email="",
|
||||
|
@ -42,7 +36,8 @@ class TestFetchmailNotifyErrorToSender(TestMailgateway):
|
|||
ctx=None,
|
||||
):
|
||||
self.assertFalse(self.env[target_model].search([(target_field, "=", subject)]))
|
||||
mail = template.format(
|
||||
mail = self.format(
|
||||
template,
|
||||
to=to_email,
|
||||
subject=subject,
|
||||
cc=cc_email,
|
||||
|
@ -50,7 +45,7 @@ class TestFetchmailNotifyErrorToSender(TestMailgateway):
|
|||
email_from=email_from,
|
||||
msg_id=msg_id,
|
||||
)
|
||||
self.env["mail.thread"].with_context(ctx or {}).message_process(
|
||||
self.env["mail.thread"].with_context(**ctx or {}).message_process(
|
||||
model,
|
||||
mail,
|
||||
)
|
||||
|
@ -59,26 +54,44 @@ class TestFetchmailNotifyErrorToSender(TestMailgateway):
|
|||
@mute_logger("odoo.addons.mail.models.mail_thread", "odoo.models")
|
||||
def test_message_process(self):
|
||||
email_from = formataddr((self.partner_1.name, self.partner_1.email))
|
||||
extra = (
|
||||
f"In-Reply-To: <12321321-openerp-{self.test_record.id}-"
|
||||
f"mail.test.simple@{socket.gethostname()}>"
|
||||
)
|
||||
ctx = {"default_fetchmail_server_id": self.fetchmail_server.id}
|
||||
|
||||
count_return_mails_before = self.env["mail.mail"].search_count(
|
||||
[("email_to", "=", email_from)]
|
||||
)
|
||||
|
||||
# 1. Default fetchmail server not present in context
|
||||
with self.assertRaises(ValueError):
|
||||
self.format_and_process_with_context(
|
||||
MAIL_TEMPLATE,
|
||||
email_from=email_from,
|
||||
to_email="noone@example.com",
|
||||
subject="spam",
|
||||
extra="In-Reply-To: <12321321-openerp-%d-mail.test.simple@%s"
|
||||
">"
|
||||
% (
|
||||
self.test_record.id,
|
||||
socket.gethostname(),
|
||||
),
|
||||
ctx={"default_fetchmail_server_id": self.fetchmail_server.id},
|
||||
extra=extra,
|
||||
)
|
||||
|
||||
# 2. Field error_notice_template_id not set
|
||||
with self.assertRaises(ValueError):
|
||||
self.format_and_process_with_context(
|
||||
MAIL_TEMPLATE,
|
||||
email_from=email_from,
|
||||
extra=extra,
|
||||
ctx=ctx,
|
||||
)
|
||||
|
||||
# 3. Everything is set, no error should be raised and an email should be sent
|
||||
self.fetchmail_server.error_notice_template_id = self.env.ref(
|
||||
"fetchmail_notify_error_to_sender.email_template_error_notice"
|
||||
)
|
||||
self.format_and_process_with_context(
|
||||
MAIL_TEMPLATE,
|
||||
email_from=email_from,
|
||||
extra=extra,
|
||||
ctx=ctx,
|
||||
)
|
||||
|
||||
count_return_mails_after = self.env["mail.mail"].search_count(
|
||||
[("email_to", "=", email_from)]
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue