[MIG] mail_tracking_mailgun: Migration to 15.0

This commit is contained in:
nicolas 2022-05-17 17:17:03 -03:00 committed by Nicolas Mac Rouillon
parent df3453c4b4
commit d2792da8c5
4 changed files with 7 additions and 41 deletions

View File

@ -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)",

View File

@ -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
)

View File

@ -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):

View File

@ -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):