From d2792da8c5c7fd91ad1a22dc42eec5f9fa24bb2e Mon Sep 17 00:00:00 2001 From: nicolas Date: Tue, 17 May 2022 17:17:03 -0300 Subject: [PATCH] [MIG] mail_tracking_mailgun: Migration to 15.0 --- mail_tracking_mailgun/__manifest__.py | 2 +- .../migrations/14.0.2.0.0/post-migration.py | 34 ------------------- mail_tracking_mailgun/models/res_partner.py | 8 ++--- mail_tracking_mailgun/tests/test_mailgun.py | 4 ++- 4 files changed, 7 insertions(+), 41 deletions(-) delete mode 100644 mail_tracking_mailgun/migrations/14.0.2.0.0/post-migration.py diff --git a/mail_tracking_mailgun/__manifest__.py b/mail_tracking_mailgun/__manifest__.py index aebd127..47c158c 100644 --- a/mail_tracking_mailgun/__manifest__.py +++ b/mail_tracking_mailgun/__manifest__.py @@ -6,7 +6,7 @@ { "name": "Mail tracking for Mailgun", "summary": "Mail tracking and Mailgun webhooks integration", - "version": "14.0.2.0.0", + "version": "15.0.1.0.0", "category": "Social Network", "website": "https://github.com/OCA/social", "author": "Tecnativa, Odoo Community Association (OCA)", diff --git a/mail_tracking_mailgun/migrations/14.0.2.0.0/post-migration.py b/mail_tracking_mailgun/migrations/14.0.2.0.0/post-migration.py deleted file mode 100644 index f5ed56c..0000000 --- a/mail_tracking_mailgun/migrations/14.0.2.0.0/post-migration.py +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright 2021 Tecnativa - Jairo Llopis -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). - -import logging - -from openupgradelib import openupgrade - -_logger = logging.getLogger(__name__) - - -@openupgrade.migrate() -def migrate(env, version): - """Update webhooks. - - This version dropped support for legacy webhooks and added support for - webhook auto registering. Do that process now. - """ - if version != "14.0.1.0.0": - return - settings = env["res.config.settings"].create({}) - if not settings.mail_tracking_mailgun_enabled: - _logger.warning("Not updating webhooks because mailgun is not configured") - return - _logger.info("Updating mailgun webhooks") - try: - settings.mail_tracking_mailgun_unregister_webhooks() - settings.mail_tracking_mailgun_register_webhooks() - except Exception: - # Don't fail the update if you can't register webhooks; it can be a - # failing network condition or air-gapped upgrade, and that's OK, you - # can just update them later - _logger.warning( - "Failed to update mailgun webhooks; do that manually", exc_info=True - ) diff --git a/mail_tracking_mailgun/models/res_partner.py b/mail_tracking_mailgun/models/res_partner.py index 0e6bc45..6e201f8 100644 --- a/mail_tracking_mailgun/models/res_partner.py +++ b/mail_tracking_mailgun/models/res_partner.py @@ -32,11 +32,9 @@ class ResPartner(models.Model): event.id or 0, event.id or _("unknown"), ) - body = _("Email has been bounced: %s\nReason: %s\nEvent: %s") % ( - partner.email, - reason, - event_str, - ) + body = _( + "Email has been bounced: %(email)s\nReason: %(reason)s\nEvent: %(event_str)s" + ) % ({"email": partner.email, "reason": reason, "event_str": event_str}) partner.message_post(body=body) def check_email_validity(self): diff --git a/mail_tracking_mailgun/tests/test_mailgun.py b/mail_tracking_mailgun/tests/test_mailgun.py index fefb74d..e4f265c 100644 --- a/mail_tracking_mailgun/tests/test_mailgun.py +++ b/mail_tracking_mailgun/tests/test_mailgun.py @@ -398,6 +398,9 @@ class TestMailgun(TransactionCase): } with self.assertRaises(UserError): self.partner.check_email_validity() + # If we autocheck, the mail will be bounced + self.partner.with_context(mailgun_auto_check=True).check_email_validity() + self.assertTrue(self.partner.email_bounced) # Unable to fully validate mock_request.get.return_value.json.return_value = { "is_valid": True, @@ -405,7 +408,6 @@ class TestMailgun(TransactionCase): } with self.assertRaises(UserError): self.partner.check_email_validity() - self.assertTrue(self.partner.email_bounced) @mock.patch(_packagepath + ".models.res_partner.requests") def test_email_validity_exceptions(self, mock_request):