[MIG] fetchmail_notify_error_to_sender_test: Migration to 17.0

pull/2982/head
BT-cjimeno 2024-07-05 11:54:50 +02:00
parent 410c05b1c8
commit 1e8e228297
No known key found for this signature in database
5 changed files with 40 additions and 24 deletions

View File

@ -67,6 +67,7 @@ Contributors
- Denis Valenchyts <denis@ventor.tech> (VentorTech OU - Denis Valenchyts <denis@ventor.tech> (VentorTech OU
<https://ventor.tech>) <https://ventor.tech>)
- foram shah <foram.shah@initos.com> - foram shah <foram.shah@initos.com>
- Carlos Jimeno carlos.jimeno@braintec.com (https://braintec.com)
Maintainers Maintainers
----------- -----------

View File

@ -6,7 +6,7 @@
{ {
"name": "Fetchmail Notify Error to Sender Test", "name": "Fetchmail Notify Error to Sender Test",
"summary": "Test for Fetchmail Notify Error to Sender", "summary": "Test for Fetchmail Notify Error to Sender",
"version": "14.0.1.0.0", "version": "17.0.1.0.0",
"category": "Tools", "category": "Tools",
"author": "Agile Business Group,ForgeFlow,Odoo Community Association (OCA)", "author": "Agile Business Group,ForgeFlow,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/server-tools", "website": "https://github.com/OCA/server-tools",

View File

@ -7,3 +7,4 @@
- Denis Valenchyts \<<denis@ventor.tech>\> (VentorTech OU - Denis Valenchyts \<<denis@ventor.tech>\> (VentorTech OU
\<<https://ventor.tech>\>) \<<https://ventor.tech>\>)
- foram shah \<<foram.shah@initos.com>\> - foram shah \<<foram.shah@initos.com>\>
- Carlos Jimeno <carlos.jimeno@braintec.com> (https://braintec.com)

View File

@ -413,6 +413,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
<li>Denis Valenchyts &lt;<a class="reference external" href="mailto:denis&#64;ventor.tech">denis&#64;ventor.tech</a>&gt; (VentorTech OU <li>Denis Valenchyts &lt;<a class="reference external" href="mailto:denis&#64;ventor.tech">denis&#64;ventor.tech</a>&gt; (VentorTech OU
&lt;<a class="reference external" href="https://ventor.tech">https://ventor.tech</a>&gt;)</li> &lt;<a class="reference external" href="https://ventor.tech">https://ventor.tech</a>&gt;)</li>
<li>foram shah &lt;<a class="reference external" href="mailto:foram.shah&#64;initos.com">foram.shah&#64;initos.com</a>&gt;</li> <li>foram shah &lt;<a class="reference external" href="mailto:foram.shah&#64;initos.com">foram.shah&#64;initos.com</a>&gt;</li>
<li>Carlos Jimeno <a class="reference external" href="mailto:carlos.jimeno&#64;braintec.com">carlos.jimeno&#64;braintec.com</a> (<a class="reference external" href="https://braintec.com">https://braintec.com</a>)</li>
</ul> </ul>
</div> </div>
<div class="section" id="maintainers"> <div class="section" id="maintainers">

View File

@ -10,28 +10,22 @@ from odoo.addons.test_mail.tests.test_mail_gateway import TestMailgateway
class TestFetchmailNotifyErrorToSender(TestMailgateway): class TestFetchmailNotifyErrorToSender(TestMailgateway):
def setUp(self): @classmethod
super(TestFetchmailNotifyErrorToSender, self).setUp() 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", "name": "Test Fetchmail Server",
"server_type": "imap", "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( def format_and_process_with_context(
self, self,
template, template,
to_email="groups@example.com, other@gmail.com", to_email="noone@example.com",
subject="Frogs", subject="spam",
extra="", extra="",
email_from="Sylvie Lelitre <test.sylvie.lelitre@agrolait.com>", email_from="Sylvie Lelitre <test.sylvie.lelitre@agrolait.com>",
cc_email="", cc_email="",
@ -42,7 +36,8 @@ class TestFetchmailNotifyErrorToSender(TestMailgateway):
ctx=None, ctx=None,
): ):
self.assertFalse(self.env[target_model].search([(target_field, "=", subject)])) self.assertFalse(self.env[target_model].search([(target_field, "=", subject)]))
mail = template.format( mail = self.format(
template,
to=to_email, to=to_email,
subject=subject, subject=subject,
cc=cc_email, cc=cc_email,
@ -50,7 +45,7 @@ class TestFetchmailNotifyErrorToSender(TestMailgateway):
email_from=email_from, email_from=email_from,
msg_id=msg_id, 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, model,
mail, mail,
) )
@ -59,26 +54,44 @@ class TestFetchmailNotifyErrorToSender(TestMailgateway):
@mute_logger("odoo.addons.mail.models.mail_thread", "odoo.models") @mute_logger("odoo.addons.mail.models.mail_thread", "odoo.models")
def test_message_process(self): def test_message_process(self):
email_from = formataddr((self.partner_1.name, self.partner_1.email)) 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( count_return_mails_before = self.env["mail.mail"].search_count(
[("email_to", "=", email_from)] [("email_to", "=", email_from)]
) )
# 1. Default fetchmail server not present in context
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
self.format_and_process_with_context( self.format_and_process_with_context(
MAIL_TEMPLATE, MAIL_TEMPLATE,
email_from=email_from, email_from=email_from,
to_email="noone@example.com", extra=extra,
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},
) )
# 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( count_return_mails_after = self.env["mail.mail"].search_count(
[("email_to", "=", email_from)] [("email_to", "=", email_from)]
) )