2017-10-17 20:38:11 +02:00
|
|
|
# Copyright 2016 Tecnativa - Antonio Espinosa
|
|
|
|
# Copyright 2017 Tecnativa - David Vidal
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
# Copyright 2021 Tecnativa - Jairo Llopis
|
2016-07-15 13:41:49 +02:00
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
|
|
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
from contextlib import contextmanager, suppress
|
2017-10-17 20:38:11 +02:00
|
|
|
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
import mock
|
|
|
|
from freezegun import freeze_time
|
|
|
|
from werkzeug.exceptions import NotAcceptable
|
|
|
|
|
|
|
|
from odoo.exceptions import MissingError, UserError, ValidationError
|
|
|
|
from odoo.tests.common import Form, TransactionCase
|
2020-04-02 11:15:00 +02:00
|
|
|
from odoo.tools import mute_logger
|
|
|
|
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
from ..controllers.main import MailTrackingController
|
|
|
|
|
|
|
|
# HACK https://github.com/odoo/odoo/pull/78424 because website is not dependency
|
|
|
|
try:
|
|
|
|
from odoo.addons.website.tools import MockRequest
|
|
|
|
except ImportError:
|
|
|
|
MockRequest = None
|
|
|
|
|
|
|
|
|
2020-04-02 11:15:00 +02:00
|
|
|
_packagepath = "odoo.addons.mail_tracking_mailgun"
|
2016-07-15 13:41:49 +02:00
|
|
|
|
|
|
|
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
@freeze_time("2016-08-12 17:00:00", tick=True)
|
2016-07-15 13:41:49 +02:00
|
|
|
class TestMailgun(TransactionCase):
|
|
|
|
def mail_send(self):
|
2020-04-02 11:15:00 +02:00
|
|
|
mail = self.env["mail.mail"].create(
|
|
|
|
{
|
|
|
|
"subject": "Test subject",
|
|
|
|
"email_from": "from@example.com",
|
|
|
|
"email_to": self.recipient,
|
|
|
|
"body_html": "<p>This is a test message</p>",
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
"message_id": "<test-id@f187c54734e8>",
|
2020-04-02 11:15:00 +02:00
|
|
|
}
|
|
|
|
)
|
2016-07-15 13:41:49 +02:00
|
|
|
mail.send()
|
|
|
|
# Search tracking created
|
2020-04-02 11:15:00 +02:00
|
|
|
tracking_email = self.env["mail.tracking.email"].search(
|
|
|
|
[("mail_id", "=", mail.id)]
|
|
|
|
)
|
2016-07-15 13:41:49 +02:00
|
|
|
return mail, tracking_email
|
|
|
|
|
|
|
|
def setUp(self):
|
2021-07-22 10:24:42 +02:00
|
|
|
super().setUp()
|
2020-04-02 11:15:00 +02:00
|
|
|
self.recipient = "to@example.com"
|
2016-07-15 13:41:49 +02:00
|
|
|
self.mail, self.tracking_email = self.mail_send()
|
2020-04-02 11:15:00 +02:00
|
|
|
self.domain = "example.com"
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
# Configure Mailgun through GUI
|
|
|
|
cf = Form(self.env["res.config.settings"])
|
|
|
|
cf.mail_tracking_mailgun_enabled = True
|
|
|
|
cf.mail_tracking_mailgun_api_key = (
|
|
|
|
cf.mail_tracking_mailgun_webhook_signing_key
|
|
|
|
) = (
|
|
|
|
cf.mail_tracking_mailgun_validation_key
|
|
|
|
) = "key-12345678901234567890123456789012"
|
|
|
|
cf.mail_tracking_mailgun_domain = False
|
|
|
|
cf.mail_tracking_mailgun_auto_check_partner_emails = False
|
|
|
|
config = cf.save()
|
|
|
|
# Done this way as `hr_expense` adds this field again as readonly, and thus Form
|
|
|
|
# doesn't process it correctly
|
|
|
|
config.alias_domain = self.domain
|
|
|
|
config.execute()
|
2020-04-02 11:15:00 +02:00
|
|
|
self.token = "f1349299097a51b9a7d886fcb5c2735b426ba200ada6e9e149"
|
|
|
|
self.timestamp = "1471021089"
|
|
|
|
self.signature = (
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
"4fb6d4dbbe10ce5d620265dcd7a3c0b8" "ca0dede1433103891bc1ae4086e9d5b2"
|
2020-04-02 11:15:00 +02:00
|
|
|
)
|
2016-07-15 13:41:49 +02:00
|
|
|
self.event = {
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
"log-level": "info",
|
|
|
|
"id": "oXAVv5URCF-dKv8c6Sa7T",
|
|
|
|
"timestamp": 1471021089.0,
|
|
|
|
"message": {
|
|
|
|
"headers": {
|
|
|
|
"to": "test@test.com",
|
|
|
|
"message-id": "test-id@f187c54734e8",
|
|
|
|
"from": "Mr. Odoo <mrodoo@odoo.com>",
|
|
|
|
"subject": "This is a test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"event": "delivered",
|
|
|
|
"recipient": "to@example.com",
|
|
|
|
"user-variables": {
|
|
|
|
"odoo_db": self.env.cr.dbname,
|
|
|
|
"tracking_email_id": self.tracking_email.id,
|
|
|
|
},
|
2016-07-15 13:41:49 +02:00
|
|
|
}
|
|
|
|
self.metadata = {
|
2020-04-02 11:15:00 +02:00
|
|
|
"ip": "127.0.0.1",
|
|
|
|
"user_agent": False,
|
|
|
|
"os_family": False,
|
|
|
|
"ua_family": False,
|
2016-07-15 13:41:49 +02:00
|
|
|
}
|
2020-04-02 11:15:00 +02:00
|
|
|
self.partner = self.env["res.partner"].create(
|
|
|
|
{"name": "Mr. Odoo", "email": "mrodoo@example.com"}
|
|
|
|
)
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
self.response = {"items": [self.event]}
|
|
|
|
self.MailTrackingController = MailTrackingController()
|
|
|
|
|
|
|
|
@contextmanager
|
|
|
|
def _request_mock(self, reset_replay_cache=True):
|
|
|
|
# HACK https://github.com/odoo/odoo/pull/78424
|
|
|
|
if MockRequest is None:
|
|
|
|
self.skipTest("MockRequest not found, sorry")
|
|
|
|
if reset_replay_cache:
|
|
|
|
with suppress(AttributeError):
|
|
|
|
del self.env.registry._mail_tracking_mailgun_processed_tokens
|
|
|
|
# Imitate Mailgun JSON request
|
|
|
|
mock = MockRequest(self.env)
|
|
|
|
with mock as request:
|
|
|
|
request.jsonrequest = {
|
|
|
|
"signature": {
|
|
|
|
"timestamp": self.timestamp,
|
|
|
|
"token": self.token,
|
|
|
|
"signature": self.signature,
|
|
|
|
},
|
|
|
|
"event-data": self.event,
|
|
|
|
}
|
|
|
|
request.params = {"db": self.env.cr.dbname}
|
|
|
|
request.session.db = self.env.cr.dbname
|
|
|
|
yield request
|
2016-07-15 13:41:49 +02:00
|
|
|
|
|
|
|
def event_search(self, event_type):
|
2020-04-02 11:15:00 +02:00
|
|
|
event = self.env["mail.tracking.event"].search(
|
|
|
|
[
|
|
|
|
("tracking_email_id", "=", self.tracking_email.id),
|
|
|
|
("event_type", "=", event_type),
|
|
|
|
]
|
|
|
|
)
|
2016-07-15 13:41:49 +02:00
|
|
|
self.assertTrue(event)
|
|
|
|
return event
|
|
|
|
|
|
|
|
def test_no_api_key(self):
|
2020-04-02 11:15:00 +02:00
|
|
|
self.env["ir.config_parameter"].set_param("mailgun.apikey", "")
|
2017-10-17 20:38:11 +02:00
|
|
|
with self.assertRaises(ValidationError):
|
2020-04-02 11:15:00 +02:00
|
|
|
self.env["mail.tracking.email"]._mailgun_values()
|
2017-10-17 20:38:11 +02:00
|
|
|
|
|
|
|
def test_no_domain(self):
|
2020-04-02 11:15:00 +02:00
|
|
|
self.env["ir.config_parameter"].set_param("mail.catchall.domain", "")
|
2017-10-17 20:38:11 +02:00
|
|
|
with self.assertRaises(ValidationError):
|
2020-04-02 11:15:00 +02:00
|
|
|
self.env["mail.tracking.email"]._mailgun_values()
|
2018-08-02 10:53:59 +02:00
|
|
|
# now we set an specific domain for Mailgun:
|
|
|
|
# i.e: we configure new EU zone without loosing old domain statistics
|
2020-04-02 11:15:00 +02:00
|
|
|
self.env["ir.config_parameter"].set_param("mailgun.domain", "eu.example.com")
|
2018-08-02 10:53:59 +02:00
|
|
|
self.test_event_delivered()
|
2016-07-15 13:41:49 +02:00
|
|
|
|
2020-04-02 11:15:00 +02:00
|
|
|
@mute_logger("odoo.addons.mail_tracking_mailgun.models.mail_tracking_email")
|
2016-07-15 13:41:49 +02:00
|
|
|
def test_bad_signature(self):
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
self.signature = "bad_signature"
|
|
|
|
with self._request_mock(), self.assertRaises(NotAcceptable):
|
|
|
|
self.MailTrackingController.mail_tracking_mailgun_webhook()
|
2016-07-15 13:41:49 +02:00
|
|
|
|
2020-04-02 11:15:00 +02:00
|
|
|
@mute_logger("odoo.addons.mail_tracking_mailgun.models.mail_tracking_email")
|
2016-07-15 13:41:49 +02:00
|
|
|
def test_bad_event_type(self):
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
old_events = self.tracking_email.tracking_event_ids
|
2020-04-02 11:15:00 +02:00
|
|
|
self.event.update({"event": "bad_event"})
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
with self._request_mock():
|
|
|
|
self.MailTrackingController.mail_tracking_mailgun_webhook()
|
|
|
|
self.assertFalse(self.tracking_email.tracking_event_ids - old_events)
|
2016-07-15 13:41:49 +02:00
|
|
|
|
|
|
|
def test_bad_ts(self):
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
self.timestamp = "7a" # Now time will be used instead
|
|
|
|
self.signature = (
|
|
|
|
"06cc05680f6e8110e59b41152b2d1c0f1045d755ef2880ff922344325c89a6d4"
|
2020-04-02 11:15:00 +02:00
|
|
|
)
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
with self._request_mock(), self.assertRaises(ValueError):
|
|
|
|
self.MailTrackingController.mail_tracking_mailgun_webhook()
|
2016-07-15 13:41:49 +02:00
|
|
|
|
2020-04-02 11:15:00 +02:00
|
|
|
@mute_logger("odoo.addons.mail_tracking_mailgun.models.mail_tracking_email")
|
2016-07-15 13:41:49 +02:00
|
|
|
def test_tracking_not_found(self):
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
self.event.update(
|
|
|
|
{
|
|
|
|
"event": "delivered",
|
|
|
|
"message": {
|
|
|
|
"headers": {
|
|
|
|
"to": "else@test.com",
|
|
|
|
"message-id": "test-id-else@f187c54734e8",
|
|
|
|
"from": "Mr. Odoo <mrodoo@odoo.com>",
|
|
|
|
"subject": "This is a bad test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"user-variables": {
|
|
|
|
"odoo_db": self.env.cr.dbname,
|
|
|
|
"tracking_email_id": -1,
|
|
|
|
},
|
|
|
|
}
|
2020-04-02 11:15:00 +02:00
|
|
|
)
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
with self._request_mock(), self.assertRaises(MissingError):
|
|
|
|
self.MailTrackingController.mail_tracking_mailgun_webhook()
|
|
|
|
|
|
|
|
@mute_logger("odoo.addons.mail_tracking_mailgun.models.mail_tracking_email")
|
|
|
|
def test_tracking_wrong_db(self):
|
|
|
|
self.event["user-variables"]["odoo_db"] = "%s_nope" % self.env.cr.dbname
|
|
|
|
with self._request_mock(), self.assertRaises(ValidationError):
|
|
|
|
self.MailTrackingController.mail_tracking_mailgun_webhook()
|
2016-07-15 13:41:49 +02:00
|
|
|
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
# https://documentation.mailgun.com/en/latest/user_manual.html#tracking-deliveries
|
2016-07-15 13:41:49 +02:00
|
|
|
def test_event_delivered(self):
|
2020-04-02 11:15:00 +02:00
|
|
|
self.event.update({"event": "delivered"})
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
with self._request_mock():
|
|
|
|
self.MailTrackingController.mail_tracking_mailgun_webhook()
|
2020-04-02 11:15:00 +02:00
|
|
|
events = self.event_search("delivered")
|
2018-08-02 10:53:59 +02:00
|
|
|
for event in events:
|
|
|
|
self.assertEqual(event.timestamp, float(self.timestamp))
|
|
|
|
self.assertEqual(event.recipient, self.recipient)
|
2016-07-15 13:41:49 +02:00
|
|
|
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
# https://documentation.mailgun.com/en/latest/user_manual.html#tracking-opens
|
2016-07-15 13:41:49 +02:00
|
|
|
def test_event_opened(self):
|
2020-04-02 11:15:00 +02:00
|
|
|
ip = "127.0.0.1"
|
|
|
|
user_agent = "Odoo Test/8.0 Gecko Firefox/11.0"
|
|
|
|
os_family = "Linux"
|
|
|
|
ua_family = "Firefox"
|
|
|
|
ua_type = "browser"
|
|
|
|
self.event.update(
|
|
|
|
{
|
|
|
|
"event": "opened",
|
|
|
|
"city": "Mountain View",
|
|
|
|
"country": "US",
|
|
|
|
"region": "CA",
|
|
|
|
"client-name": ua_family,
|
|
|
|
"client-os": os_family,
|
|
|
|
"client-type": ua_type,
|
|
|
|
"device-type": "desktop",
|
|
|
|
"ip": ip,
|
|
|
|
"user-agent": user_agent,
|
|
|
|
}
|
|
|
|
)
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
with self._request_mock():
|
|
|
|
self.MailTrackingController.mail_tracking_mailgun_webhook()
|
2020-04-02 11:15:00 +02:00
|
|
|
event = self.event_search("open")
|
2016-07-15 13:41:49 +02:00
|
|
|
self.assertEqual(event.timestamp, float(self.timestamp))
|
|
|
|
self.assertEqual(event.recipient, self.recipient)
|
|
|
|
self.assertEqual(event.ip, ip)
|
|
|
|
self.assertEqual(event.user_agent, user_agent)
|
|
|
|
self.assertEqual(event.os_family, os_family)
|
|
|
|
self.assertEqual(event.ua_family, ua_family)
|
|
|
|
self.assertEqual(event.ua_type, ua_type)
|
|
|
|
self.assertEqual(event.mobile, False)
|
2020-04-02 11:15:00 +02:00
|
|
|
self.assertEqual(event.user_country_id.code, "US")
|
2016-07-15 13:41:49 +02:00
|
|
|
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
# https://documentation.mailgun.com/en/latest/user_manual.html#tracking-clicks
|
2016-07-15 13:41:49 +02:00
|
|
|
def test_event_clicked(self):
|
2020-04-02 11:15:00 +02:00
|
|
|
ip = "127.0.0.1"
|
|
|
|
user_agent = "Odoo Test/8.0 Gecko Firefox/11.0"
|
|
|
|
os_family = "Linux"
|
|
|
|
ua_family = "Firefox"
|
|
|
|
ua_type = "browser"
|
|
|
|
url = "https://odoo-community.org"
|
|
|
|
self.event.update(
|
|
|
|
{
|
|
|
|
"event": "clicked",
|
|
|
|
"city": "Mountain View",
|
|
|
|
"country": "US",
|
|
|
|
"region": "CA",
|
|
|
|
"client-name": ua_family,
|
|
|
|
"client-os": os_family,
|
|
|
|
"client-type": ua_type,
|
|
|
|
"device-type": "tablet",
|
|
|
|
"ip": ip,
|
|
|
|
"user-agent": user_agent,
|
|
|
|
"url": url,
|
|
|
|
}
|
|
|
|
)
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
with self._request_mock():
|
|
|
|
self.MailTrackingController.mail_tracking_mailgun_webhook()
|
2020-04-02 11:15:00 +02:00
|
|
|
event = self.event_search("click")
|
2016-07-15 13:41:49 +02:00
|
|
|
self.assertEqual(event.timestamp, float(self.timestamp))
|
|
|
|
self.assertEqual(event.recipient, self.recipient)
|
|
|
|
self.assertEqual(event.ip, ip)
|
|
|
|
self.assertEqual(event.user_agent, user_agent)
|
|
|
|
self.assertEqual(event.os_family, os_family)
|
|
|
|
self.assertEqual(event.ua_family, ua_family)
|
|
|
|
self.assertEqual(event.ua_type, ua_type)
|
|
|
|
self.assertEqual(event.mobile, True)
|
|
|
|
self.assertEqual(event.url, url)
|
|
|
|
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
# https://documentation.mailgun.com/en/latest/user_manual.html#tracking-unsubscribes
|
2016-07-15 13:41:49 +02:00
|
|
|
def test_event_unsubscribed(self):
|
2020-04-02 11:15:00 +02:00
|
|
|
ip = "127.0.0.1"
|
|
|
|
user_agent = "Odoo Test/8.0 Gecko Firefox/11.0"
|
|
|
|
os_family = "Linux"
|
|
|
|
ua_family = "Firefox"
|
|
|
|
ua_type = "browser"
|
|
|
|
self.event.update(
|
|
|
|
{
|
|
|
|
"event": "unsubscribed",
|
|
|
|
"city": "Mountain View",
|
|
|
|
"country": "US",
|
|
|
|
"region": "CA",
|
|
|
|
"client-name": ua_family,
|
|
|
|
"client-os": os_family,
|
|
|
|
"client-type": ua_type,
|
|
|
|
"device-type": "mobile",
|
|
|
|
"ip": ip,
|
|
|
|
"user-agent": user_agent,
|
|
|
|
}
|
|
|
|
)
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
with self._request_mock():
|
|
|
|
self.MailTrackingController.mail_tracking_mailgun_webhook()
|
2020-04-02 11:15:00 +02:00
|
|
|
event = self.event_search("unsub")
|
2016-07-15 13:41:49 +02:00
|
|
|
self.assertEqual(event.timestamp, float(self.timestamp))
|
|
|
|
self.assertEqual(event.recipient, self.recipient)
|
|
|
|
self.assertEqual(event.ip, ip)
|
|
|
|
self.assertEqual(event.user_agent, user_agent)
|
|
|
|
self.assertEqual(event.os_family, os_family)
|
|
|
|
self.assertEqual(event.ua_family, ua_family)
|
|
|
|
self.assertEqual(event.ua_type, ua_type)
|
|
|
|
self.assertEqual(event.mobile, True)
|
|
|
|
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
# https://documentation.mailgun.com/en/latest/user_manual.html#tracking-spam-complaints
|
2016-07-15 13:41:49 +02:00
|
|
|
def test_event_complained(self):
|
2020-04-02 11:15:00 +02:00
|
|
|
self.event.update({"event": "complained"})
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
with self._request_mock():
|
|
|
|
self.MailTrackingController.mail_tracking_mailgun_webhook()
|
2020-04-02 11:15:00 +02:00
|
|
|
event = self.event_search("spam")
|
2016-07-15 13:41:49 +02:00
|
|
|
self.assertEqual(event.timestamp, float(self.timestamp))
|
|
|
|
self.assertEqual(event.recipient, self.recipient)
|
2020-04-02 11:15:00 +02:00
|
|
|
self.assertEqual(event.error_type, "spam")
|
2016-07-15 13:41:49 +02:00
|
|
|
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
# https://documentation.mailgun.com/en/latest/user_manual.html#tracking-bounces
|
|
|
|
def test_event_failed(self):
|
|
|
|
code = 550
|
2020-04-02 11:15:00 +02:00
|
|
|
error = (
|
|
|
|
"5.1.1 The email account does not exist.\n"
|
|
|
|
"5.1.1 double-checking the recipient's email address"
|
|
|
|
)
|
2018-05-08 18:24:36 +02:00
|
|
|
notification = "Please, check recipient's email address"
|
2020-04-02 11:15:00 +02:00
|
|
|
self.event.update(
|
|
|
|
{
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
"event": "failed",
|
|
|
|
"delivery-status": {
|
|
|
|
"attempt-no": 1,
|
|
|
|
"code": code,
|
|
|
|
"description": notification,
|
|
|
|
"message": error,
|
|
|
|
"session-seconds": 0.0,
|
|
|
|
},
|
|
|
|
"severity": "permanent",
|
2020-04-02 11:15:00 +02:00
|
|
|
}
|
|
|
|
)
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
with self._request_mock():
|
|
|
|
self.MailTrackingController.mail_tracking_mailgun_webhook()
|
2020-04-02 11:15:00 +02:00
|
|
|
event = self.event_search("hard_bounce")
|
2016-07-15 13:41:49 +02:00
|
|
|
self.assertEqual(event.timestamp, float(self.timestamp))
|
|
|
|
self.assertEqual(event.recipient, self.recipient)
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
self.assertEqual(event.error_type, str(code))
|
2016-07-15 13:41:49 +02:00
|
|
|
self.assertEqual(event.error_description, error)
|
|
|
|
self.assertEqual(event.error_details, notification)
|
|
|
|
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
def test_event_rejected(self):
|
2020-04-02 11:15:00 +02:00
|
|
|
reason = "hardfail"
|
|
|
|
description = "Not delivering to previously bounced address"
|
|
|
|
self.event.update(
|
|
|
|
{
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
"event": "rejected",
|
|
|
|
"reject": {"reason": reason, "description": description},
|
2020-04-02 11:15:00 +02:00
|
|
|
}
|
|
|
|
)
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
with self._request_mock():
|
|
|
|
self.MailTrackingController.mail_tracking_mailgun_webhook()
|
2020-04-02 11:15:00 +02:00
|
|
|
event = self.event_search("reject")
|
2016-07-15 13:41:49 +02:00
|
|
|
self.assertEqual(event.timestamp, float(self.timestamp))
|
|
|
|
self.assertEqual(event.recipient, self.recipient)
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
self.assertEqual(event.error_type, "rejected")
|
|
|
|
self.assertEqual(event.error_description, reason)
|
2016-07-15 13:41:49 +02:00
|
|
|
self.assertEqual(event.error_details, description)
|
2017-10-17 20:38:11 +02:00
|
|
|
|
2020-04-02 11:15:00 +02:00
|
|
|
@mock.patch(_packagepath + ".models.res_partner.requests")
|
2017-10-17 20:38:11 +02:00
|
|
|
def test_email_validity(self, mock_request):
|
|
|
|
self.partner.email_bounced = False
|
2020-04-02 11:15:00 +02:00
|
|
|
mock_request.get.return_value.apparent_encoding = "ascii"
|
2017-10-17 20:38:11 +02:00
|
|
|
mock_request.get.return_value.status_code = 200
|
2018-05-08 18:24:36 +02:00
|
|
|
mock_request.get.return_value.json.return_value = {
|
2020-04-02 11:15:00 +02:00
|
|
|
"is_valid": True,
|
|
|
|
"mailbox_verification": "true",
|
2018-05-08 18:24:36 +02:00
|
|
|
}
|
2018-02-16 13:15:32 +01:00
|
|
|
# Trigger email auto validation in partner
|
2020-04-02 11:15:00 +02:00
|
|
|
self.env["ir.config_parameter"].set_param(
|
|
|
|
"mailgun.auto_check_partner_email", "True"
|
|
|
|
)
|
|
|
|
self.partner.email = "info@tecnativa.com"
|
2017-10-17 20:38:11 +02:00
|
|
|
self.assertFalse(self.partner.email_bounced)
|
2020-04-02 11:15:00 +02:00
|
|
|
self.partner.email = "xoxoxoxo@tecnativa.com"
|
2017-10-17 20:38:11 +02:00
|
|
|
# Not a valid mailbox
|
2018-05-08 18:24:36 +02:00
|
|
|
mock_request.get.return_value.json.return_value = {
|
2020-04-02 11:15:00 +02:00
|
|
|
"is_valid": True,
|
|
|
|
"mailbox_verification": "false",
|
2018-05-08 18:24:36 +02:00
|
|
|
}
|
2017-10-17 20:38:11 +02:00
|
|
|
with self.assertRaises(UserError):
|
|
|
|
self.partner.check_email_validity()
|
|
|
|
# Not a valid mail address
|
2018-05-08 18:24:36 +02:00
|
|
|
mock_request.get.return_value.json.return_value = {
|
2020-04-02 11:15:00 +02:00
|
|
|
"is_valid": False,
|
|
|
|
"mailbox_verification": "false",
|
2018-05-08 18:24:36 +02:00
|
|
|
}
|
2017-10-17 20:38:11 +02:00
|
|
|
with self.assertRaises(UserError):
|
|
|
|
self.partner.check_email_validity()
|
2022-05-17 22:17:03 +02:00
|
|
|
# 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)
|
2017-10-17 20:38:11 +02:00
|
|
|
# Unable to fully validate
|
2018-05-08 18:24:36 +02:00
|
|
|
mock_request.get.return_value.json.return_value = {
|
2020-04-02 11:15:00 +02:00
|
|
|
"is_valid": True,
|
|
|
|
"mailbox_verification": "unknown",
|
2018-05-08 18:24:36 +02:00
|
|
|
}
|
2017-10-17 20:38:11 +02:00
|
|
|
with self.assertRaises(UserError):
|
|
|
|
self.partner.check_email_validity()
|
|
|
|
|
2020-04-02 11:15:00 +02:00
|
|
|
@mock.patch(_packagepath + ".models.res_partner.requests")
|
2017-10-17 20:38:11 +02:00
|
|
|
def test_email_validity_exceptions(self, mock_request):
|
|
|
|
mock_request.get.return_value.status_code = 404
|
|
|
|
with self.assertRaises(UserError):
|
|
|
|
self.partner.check_email_validity()
|
2020-04-02 11:15:00 +02:00
|
|
|
self.env["ir.config_parameter"].set_param("mailgun.validation_key", "")
|
2017-10-17 20:38:11 +02:00
|
|
|
with self.assertRaises(UserError):
|
|
|
|
self.partner.check_email_validity()
|
|
|
|
|
2020-04-02 11:15:00 +02:00
|
|
|
@mock.patch(_packagepath + ".models.res_partner.requests")
|
2017-10-17 20:38:11 +02:00
|
|
|
def test_bounced(self, mock_request):
|
|
|
|
self.partner.email_bounced = True
|
|
|
|
mock_request.get.return_value.status_code = 404
|
|
|
|
self.partner.check_email_bounced()
|
|
|
|
self.assertFalse(self.partner.email_bounced)
|
|
|
|
mock_request.get.return_value.status_code = 200
|
|
|
|
self.partner.force_set_bounced()
|
|
|
|
self.partner.check_email_bounced()
|
|
|
|
self.assertTrue(self.partner.email_bounced)
|
|
|
|
mock_request.delete.return_value.status_code = 200
|
|
|
|
self.partner.force_unset_bounced()
|
|
|
|
self.assertFalse(self.partner.email_bounced)
|
|
|
|
|
|
|
|
def test_email_bounced_set(self):
|
|
|
|
message_number = len(self.partner.message_ids) + 1
|
2020-04-02 11:15:00 +02:00
|
|
|
self.partner._email_bounced_set("test_error", False)
|
2017-10-17 20:38:11 +02:00
|
|
|
self.assertEqual(len(self.partner.message_ids), message_number)
|
|
|
|
self.partner.email = ""
|
2020-04-02 11:15:00 +02:00
|
|
|
self.partner._email_bounced_set("test_error", False)
|
2017-10-17 20:38:11 +02:00
|
|
|
self.assertEqual(len(self.partner.message_ids), message_number)
|
|
|
|
|
2020-04-02 11:15:00 +02:00
|
|
|
@mock.patch(_packagepath + ".models.mail_tracking_email.requests")
|
2017-10-17 20:38:11 +02:00
|
|
|
def test_manual_check(self, mock_request):
|
2018-05-08 18:24:36 +02:00
|
|
|
mock_request.get.return_value.json.return_value = self.response
|
2017-10-17 20:38:11 +02:00
|
|
|
mock_request.get.return_value.status_code = 200
|
|
|
|
self.tracking_email.action_manual_check_mailgun()
|
2020-04-02 11:15:00 +02:00
|
|
|
event = self.env["mail.tracking.event"].search(
|
|
|
|
[("mailgun_id", "=", self.response["items"][0]["id"])]
|
|
|
|
)
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
self.assertTrue(event)
|
2020-04-02 11:15:00 +02:00
|
|
|
self.assertEqual(event.event_type, self.response["items"][0]["event"])
|
2017-10-17 20:38:11 +02:00
|
|
|
|
2020-04-02 11:15:00 +02:00
|
|
|
@mock.patch(_packagepath + ".models.mail_tracking_email.requests")
|
2017-10-17 20:38:11 +02:00
|
|
|
def test_manual_check_exceptions(self, mock_request):
|
|
|
|
mock_request.get.return_value.status_code = 404
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
with self.assertRaises(UserError):
|
2017-10-17 20:38:11 +02:00
|
|
|
self.tracking_email.action_manual_check_mailgun()
|
|
|
|
mock_request.get.return_value.status_code = 200
|
2018-05-08 18:24:36 +02:00
|
|
|
mock_request.get.return_value.json.return_value = {}
|
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Before this patch, the module was designed after the [deprecated Mailgun webhooks][3]. However Mailgun had the [events API][2] which was quite different. Modern Mailgun has deprecated those webhooks and instead uses new ones that include the same payload as the events API, so you can reuse code.
However, this was incorrectly reusing the code inversely: trying to process the events API through the same code prepared for the deprecated webhooks.
Besides, both `failed` and `rejected` mailgun events were mapped to `error` state, but that was also wrong because [`mail_tracking` doesn't have an `error` state][1].
So the logic of the whole module is changed, adapting it to process the events API payload, both through controllers (prepared for the new webhooks) and manual updates that directly call the events API.
Also, `rejected` is now translated into `reject`, and `failed` is translated into `hard_bounce` or `soft_bounce` depending on the severity, as specified by [mailgun docs][2]. Also, `bounced` and `dropped` mailgun states are removed because they don't exist, and instead `failed` and `rejected` properly get their metadata.
Of course, to know the severity, now the method to obtain that info must change, it' can't be a simple dict anymore.
Added more parameters because for example modern Mailgun uses different keys for signing payload than for accessing the API. As there are so many parameters, configuration is now possible through `res.config.settings`. Go there to autoregister webhooks too.
Since the new webhooks are completely incompatible with the old supposedly-abstract webhooks controllers (that were never really that abstract), support for old webhooks is removed, and it will be removed in the future from `mail_tracking` directly. There is a migration script that attempts to unregister old webhooks and register new ones automatically.
[1]: https://github.com/OCA/social/blob/f73de421e28a43d018176f61725a3a59665f715d/mail_tracking/models/mail_tracking_event.py#L31-L42
[2]: https://documentation.mailgun.com/en/latest/api-events.html#event-types
[3]: https://documentation.mailgun.com/en/latest/api-webhooks-deprecated.html
2021-10-28 12:33:59 +02:00
|
|
|
with self.assertRaises(UserError):
|
2017-10-17 20:38:11 +02:00
|
|
|
self.tracking_email.action_manual_check_mailgun()
|