From 1e8e22829778d87e63d94eb63ef89e2de7be32aa Mon Sep 17 00:00:00 2001 From: BT-cjimeno Date: Fri, 5 Jul 2024 11:54:50 +0200 Subject: [PATCH] [MIG] fetchmail_notify_error_to_sender_test: Migration to 17.0 --- .../README.rst | 1 + .../__manifest__.py | 2 +- .../readme/CONTRIBUTORS.md | 1 + .../static/description/index.html | 1 + .../test_fetchmail_notify_error_to_sender.py | 59 +++++++++++-------- 5 files changed, 40 insertions(+), 24 deletions(-) diff --git a/fetchmail_notify_error_to_sender_test/README.rst b/fetchmail_notify_error_to_sender_test/README.rst index 0b322a237..6af17b42f 100644 --- a/fetchmail_notify_error_to_sender_test/README.rst +++ b/fetchmail_notify_error_to_sender_test/README.rst @@ -67,6 +67,7 @@ Contributors - Denis Valenchyts (VentorTech OU ) - foram shah +- Carlos Jimeno carlos.jimeno@braintec.com (https://braintec.com) Maintainers ----------- diff --git a/fetchmail_notify_error_to_sender_test/__manifest__.py b/fetchmail_notify_error_to_sender_test/__manifest__.py index 100924ca6..bf8d92361 100644 --- a/fetchmail_notify_error_to_sender_test/__manifest__.py +++ b/fetchmail_notify_error_to_sender_test/__manifest__.py @@ -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", diff --git a/fetchmail_notify_error_to_sender_test/readme/CONTRIBUTORS.md b/fetchmail_notify_error_to_sender_test/readme/CONTRIBUTORS.md index 289914894..71799d08f 100644 --- a/fetchmail_notify_error_to_sender_test/readme/CONTRIBUTORS.md +++ b/fetchmail_notify_error_to_sender_test/readme/CONTRIBUTORS.md @@ -7,3 +7,4 @@ - Denis Valenchyts \<\> (VentorTech OU \<\>) - foram shah \<\> +- Carlos Jimeno (https://braintec.com) diff --git a/fetchmail_notify_error_to_sender_test/static/description/index.html b/fetchmail_notify_error_to_sender_test/static/description/index.html index d5a468d08..c77c3c5d7 100644 --- a/fetchmail_notify_error_to_sender_test/static/description/index.html +++ b/fetchmail_notify_error_to_sender_test/static/description/index.html @@ -413,6 +413,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
  • 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)
  • diff --git a/fetchmail_notify_error_to_sender_test/tests/test_fetchmail_notify_error_to_sender.py b/fetchmail_notify_error_to_sender_test/tests/test_fetchmail_notify_error_to_sender.py index 9a2fb0387..290bb9a8e 100644 --- a/fetchmail_notify_error_to_sender_test/tests/test_fetchmail_notify_error_to_sender.py +++ b/fetchmail_notify_error_to_sender_test/tests/test_fetchmail_notify_error_to_sender.py @@ -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 ", 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)] )