Browse Source

[MIG] mail_tracking_mailgun: Migration to 11.0

pull/268/head
David 7 years ago
parent
commit
bf68b260a3
  1. 11
      mail_tracking_mailgun/README.rst
  2. 1
      mail_tracking_mailgun/__init__.py
  3. 7
      mail_tracking_mailgun/__manifest__.py
  4. 1
      mail_tracking_mailgun/models/__init__.py
  5. 8
      mail_tracking_mailgun/models/mail_tracking_email.py
  6. 2
      mail_tracking_mailgun/models/res_partner.py
  7. 1
      mail_tracking_mailgun/tests/__init__.py
  8. 120
      mail_tracking_mailgun/tests/test_mailgun.py

11
mail_tracking_mailgun/README.rst

@ -47,11 +47,12 @@ You can also config partner email autocheck with this system parameter:
Usage
=====
In your mail tracking status screens (explained on module *mail_tracking*), you will
see a more accurate information, like the 'Received' or 'Bounced' status, which are
not usually detected by normal SMTP servers.
In your mail tracking status screens (explained on module *mail_tracking*), you
will see a more accurate information, like the 'Received' or 'Bounced' status,
which are not usually detected by normal SMTP servers.
It's also possible to make some checks to the partner's email addresses against the Mailgun API:
It's also possible to make some checks to the partner's email addresses against
the Mailgun API:
- Check if the partner's email is in Mailgun's bounced list.
- Check the validity of the partner's mailbox.
@ -64,7 +65,7 @@ short lifespan, so after 24h they won't be recoverable.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/205/9.0
:target: https://runbot.odoo-community.org/runbot/205/11.0
Known issues / Roadmap
======================

1
mail_tracking_mailgun/__init__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import models

7
mail_tracking_mailgun/__manifest__.py

@ -1,15 +1,14 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Tecnativa - Antonio Espinosa
# Copyright 2016 Tecnativa - Carlos Dauden
# Copyright 2017 Tecnativa - Pedro M. Baeza
# Copyright 2017 Tecnativa - David Vidal
# Copyright 2017-18 Tecnativa - David Vidal
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Mail tracking for Mailgun",
"summary": "Mail tracking and Mailgun webhooks integration",
"version": "10.0.1.1.3",
"version": "11.0.1.0.0",
"category": "Social Network",
"website": "https://odoo-community.org/",
"website": "https://github.com/OCA/social",
"author": "Tecnativa, "
"Odoo Community Association (OCA)",
"license": "AGPL-3",

1
mail_tracking_mailgun/models/__init__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import ir_mail_server

8
mail_tracking_mailgun/models/mail_tracking_email.py

@ -60,8 +60,8 @@ class MailTrackingEmail(models.Model):
def _mailgun_signature(self, api_key, timestamp, token):
return hmac.new(
key=str(api_key),
msg='{}{}'.format(str(timestamp), str(token)),
key=bytes(api_key, 'utf-8'),
msg=bytes('{}{}'.format(str(timestamp), str(token)), 'utf-8'),
digestmod=hashlib.sha256).hexdigest()
def _mailgun_values(self):
@ -135,7 +135,7 @@ class MailTrackingEmail(models.Model):
'ua_type': 'client-type',
'url': 'url',
}
for k, v in mapping.iteritems():
for k, v in mapping.items():
if event.get(v, False):
metadata[k] = event[v]
# Special field mapping
@ -238,7 +238,7 @@ class MailTrackingEmail(models.Model):
if not res or res.status_code != 200:
raise ValidationError(_(
"Couldn't retrieve Mailgun information"))
content = json.loads(res.content, res.apparent_encoding)
content = json.loads(res.content)
if "items" not in content:
raise ValidationError(_("Event information not longer stored"))
for item in content["items"]:

2
mail_tracking_mailgun/models/res_partner.py

@ -57,7 +57,7 @@ class ResPartner(models.Model):
raise UserError(_(
'Error %s trying to '
'check mail' % res.status_code or 'of connection'))
content = json.loads(res.content, res.apparent_encoding)
content = json.loads(res.content)
if 'mailbox_verification' not in content:
if not self.env.context.get('mailgun_auto_check'):
raise UserError(

1
mail_tracking_mailgun/tests/__init__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import test_mailgun

120
mail_tracking_mailgun/tests/test_mailgun.py

@ -29,12 +29,12 @@ class TestMailgun(TransactionCase):
def setUp(self):
super(TestMailgun, self).setUp()
self.recipient = u'to@example.com'
self.recipient = 'to@example.com'
self.mail, self.tracking_email = self.mail_send()
self.api_key = u'key-12345678901234567890123456789012'
self.domain = u'example.com'
self.token = u'f1349299097a51b9a7d886fcb5c2735b426ba200ada6e9e149'
self.timestamp = u'1471021089'
self.api_key = 'key-12345678901234567890123456789012'
self.domain = 'example.com'
self.token = 'f1349299097a51b9a7d886fcb5c2735b426ba200ada6e9e149'
self.timestamp = '1471021089'
self.signature = ('4fb6d4dbbe10ce5d620265dcd7a3c0b8'
'ca0dede1433103891bc1ae4086e9d5b2')
self.env['ir.config_parameter'].set_param(
@ -46,17 +46,17 @@ class TestMailgun(TransactionCase):
self.env['ir.config_parameter'].set_param(
'mailgun.auto_check_partner_email', '')
self.event = {
'Message-Id': u'<xxx.xxx.xxx-openerp-xxx-res.partner@test_db>',
'X-Mailgun-Sid': u'WyIwNjgxZSIsICJ0b0BleGFtcGxlLmNvbSIsICI3MG'
'Message-Id': '<xxx.xxx.xxx-openerp-xxx-res.partner@test_db>',
'X-Mailgun-Sid': 'WyIwNjgxZSIsICJ0b0BleGFtcGxlLmNvbSIsICI3MG'
'I0MWYiXQ==',
'token': self.token,
'timestamp': self.timestamp,
'signature': self.signature,
'domain': u'example.com',
'message-headers': u'[]',
'domain': 'example.com',
'message-headers': '[]',
'recipient': self.recipient,
'odoo_db': self.env.cr.dbname,
'tracking_email_id': u'%s' % self.tracking_email.id
'tracking_email_id': '%s' % self.tracking_email.id
}
self.metadata = {
'ip': '127.0.0.1',
@ -110,8 +110,8 @@ class TestMailgun(TransactionCase):
'.mail_tracking_email')
def test_bad_signature(self):
self.event.update({
'event': u'delivered',
'signature': u'bad_signature',
'event': 'delivered',
'signature': 'bad_signature',
})
response = self.env['mail.tracking.email'].event_process(
None, self.event, self.metadata)
@ -121,7 +121,7 @@ class TestMailgun(TransactionCase):
'.mail_tracking_email')
def test_bad_event_type(self):
self.event.update({
'event': u'bad_event',
'event': 'bad_event',
})
response = self.env['mail.tracking.email'].event_process(
None, self.event, self.metadata)
@ -131,19 +131,19 @@ class TestMailgun(TransactionCase):
'.mail_tracking_email')
def test_bad_db(self):
self.event.update({
'event': u'delivered',
'odoo_db': u'bad_db',
'event': 'delivered',
'odoo_db': 'bad_db',
})
response = self.env['mail.tracking.email'].event_process(
None, self.event, self.metadata)
self.assertEqual('ERROR: Invalid DB', response)
def test_bad_ts(self):
timestamp = u'7a' # Now time will be used instead
timestamp = '7a' # Now time will be used instead
signature = ('06cc05680f6e8110e59b41152b2d1c0f'
'1045d755ef2880ff922344325c89a6d4')
self.event.update({
'event': u'delivered',
'event': 'delivered',
'timestamp': timestamp,
'signature': signature,
})
@ -155,8 +155,8 @@ class TestMailgun(TransactionCase):
'.mail_tracking_email')
def test_tracking_not_found(self):
self.event.update({
'event': u'delivered',
'tracking_email_id': u'bad_id',
'event': 'delivered',
'tracking_email_id': 'bad_id',
})
response = self.env['mail.tracking.email'].event_process(
None, self.event, self.metadata)
@ -165,7 +165,7 @@ class TestMailgun(TransactionCase):
# https://documentation.mailgun.com/user_manual.html#tracking-deliveries
def test_event_delivered(self):
self.event.update({
'event': u'delivered',
'event': 'delivered',
})
response = self.env['mail.tracking.email'].event_process(
None, self.event, self.metadata)
@ -176,20 +176,20 @@ class TestMailgun(TransactionCase):
# https://documentation.mailgun.com/user_manual.html#tracking-opens
def test_event_opened(self):
ip = u'127.0.0.1'
user_agent = u'Odoo Test/8.0 Gecko Firefox/11.0'
os_family = u'Linux'
ua_family = u'Firefox'
ua_type = u'browser'
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': u'opened',
'city': u'Mountain View',
'country': u'US',
'region': u'CA',
'event': 'opened',
'city': 'Mountain View',
'country': 'US',
'region': 'CA',
'client-name': ua_family,
'client-os': os_family,
'client-type': ua_type,
'device-type': u'desktop',
'device-type': 'desktop',
'ip': ip,
'user-agent': user_agent,
})
@ -209,21 +209,21 @@ class TestMailgun(TransactionCase):
# https://documentation.mailgun.com/user_manual.html#tracking-clicks
def test_event_clicked(self):
ip = u'127.0.0.1'
user_agent = u'Odoo Test/8.0 Gecko Firefox/11.0'
os_family = u'Linux'
ua_family = u'Firefox'
ua_type = u'browser'
url = u'https://odoo-community.org'
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': u'clicked',
'city': u'Mountain View',
'country': u'US',
'region': u'CA',
'event': 'clicked',
'city': 'Mountain View',
'country': 'US',
'region': 'CA',
'client-name': ua_family,
'client-os': os_family,
'client-type': ua_type,
'device-type': u'tablet',
'device-type': 'tablet',
'ip': ip,
'user-agent': user_agent,
'url': url,
@ -244,20 +244,20 @@ class TestMailgun(TransactionCase):
# https://documentation.mailgun.com/user_manual.html#tracking-unsubscribes
def test_event_unsubscribed(self):
ip = u'127.0.0.1'
user_agent = u'Odoo Test/8.0 Gecko Firefox/11.0'
os_family = u'Linux'
ua_family = u'Firefox'
ua_type = u'browser'
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': u'unsubscribed',
'city': u'Mountain View',
'country': u'US',
'region': u'CA',
'event': 'unsubscribed',
'city': 'Mountain View',
'country': 'US',
'region': 'CA',
'client-name': ua_family,
'client-os': os_family,
'client-type': ua_type,
'device-type': u'mobile',
'device-type': 'mobile',
'ip': ip,
'user-agent': user_agent,
})
@ -278,7 +278,7 @@ class TestMailgun(TransactionCase):
# user_manual.html#tracking-spam-complaints
def test_event_complained(self):
self.event.update({
'event': u'complained',
'event': 'complained',
})
response = self.env['mail.tracking.email'].event_process(
None, self.event, self.metadata)
@ -290,12 +290,12 @@ class TestMailgun(TransactionCase):
# https://documentation.mailgun.com/user_manual.html#tracking-bounces
def test_event_bounced(self):
code = u'550'
error = (u"5.1.1 The email account does not exist.\n"
code = '550'
error = ("5.1.1 The email account does not exist.\n"
"5.1.1 double-checking the recipient's email address")
notification = u"Please, check recipient's email address"
notification = "Please, check recipient's email address"
self.event.update({
'event': u'bounced',
'event': 'bounced',
'code': code,
'error': error,
'notification': notification,
@ -312,11 +312,11 @@ class TestMailgun(TransactionCase):
# https://documentation.mailgun.com/user_manual.html#tracking-failures
def test_event_dropped(self):
reason = u'hardfail'
code = u'605'
description = u'Not delivering to previously bounced address'
reason = 'hardfail'
code = '605'
description = 'Not delivering to previously bounced address'
self.event.update({
'event': u'dropped',
'event': 'dropped',
'reason': reason,
'code': code,
'description': description,

Loading…
Cancel
Save