summaryrefslogtreecommitdiff
path: root/addons/test_mass_mailing/tests/test_mass_mailing.py
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2018-10-18 10:51:09 +0000
committerThibault Delavallée <tde@odoo.com>2018-10-18 13:57:02 +0000
commitdcec209805e58208eda50eb929b5355bc28fc05b (patch)
tree8f90ad98f5ef2566a2e9413ceef027460e8a0646 /addons/test_mass_mailing/tests/test_mass_mailing.py
parent7edcbfec389da5ba613f7ec0607e05224bc39052 (diff)
[FIX] mass_mailing: fix tracking link creation in mass mailing
When using only mass mailing two issues arise when trying to send mass mailings containing links * a link.tracker is created for each link to shorten; however rights are given currently only in website_links for website designers and not to marketing users that use mass mailing. This commit adds the rights for link.tracker model to those people; * a link.tracker.code is created to hold the shortened versions of the links. As it is a technical model it is now done as superuser as rights on link.tracked model has already been granted and adding rights on such a technical model is not necessary; A test is added that checks what is done with links when sending mass mailings. It helped spotting the hereabove issue. This commit is linked to task ID 1889703 and PR #27526.
Diffstat (limited to 'addons/test_mass_mailing/tests/test_mass_mailing.py')
-rw-r--r--addons/test_mass_mailing/tests/test_mass_mailing.py67
1 files changed, 64 insertions, 3 deletions
diff --git a/addons/test_mass_mailing/tests/test_mass_mailing.py b/addons/test_mass_mailing/tests/test_mass_mailing.py
index 8a8a2303317..6629be54f9f 100644
--- a/addons/test_mass_mailing/tests/test_mass_mailing.py
+++ b/addons/test_mass_mailing/tests/test_mass_mailing.py
@@ -1,9 +1,70 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
-from odoo.tests import common
+from unittest.mock import patch
+from werkzeug import urls
-class TestAccessRights(common.TransactionCase):
+from odoo.addons.test_mass_mailing.tests.common import MassMailingCase
+from odoo.addons.base.models.ir_config_parameter import IrConfigParameter
+from odoo.tests.common import TransactionCase, users
+from odoo.tools import mute_logger
+
+
+class TestMassMail(MassMailingCase):
+
+ def setUp(self):
+ """ In this setup we prepare 20 blacklist entries. We therefore add
+ 20 recipients compared to first test in order to have comparable results. """
+ super(TestMassMail, self).setUp()
+ values = [{
+ 'name': 'Recipient %s' % x,
+ 'email_from': 'Recipient <rec.%s@example.com>' % x,
+ } for x in range(0, 6)]
+ self.mm_recs = self.env['mass.mail.test.bl'].create(values)
+
+ self.env['mail.blacklist'].create({
+ 'email': 'rec.2@example.com'
+ })
+
+ self.test_medium = self.env['utm.medium'].create({'name': 'TestMedium'})
+
+ @users('marketing')
+ @mute_logger('odoo.addons.mail.models.mail_mail', 'odoo.models.unlink')
+ def test_link_tracker(self):
+ _url = 'https://www.example.com/foo/bar?baz=qux'
+ mailing = self.env['mail.mass_mailing'].create({
+ 'name': 'TestMailing',
+ 'medium_id': self.test_medium.id,
+ 'body_html': '<p>Hello <a role="button" href="%s">${object.name}</a><a role="button" href="/unsubscribe_from_list">Unsubscribe</a></p>' % _url,
+ 'reply_to_mode': 'email',
+ 'mailing_model_id': self.ref('test_mass_mailing.model_mass_mail_test_bl'),
+ 'mailing_domain': [('id', 'in', self.mm_recs.ids)],
+ })
+
+ mailing.send_mail()
+
+ # basic test emails are sent
+ self.assertEqual(mailing.sent, 5)
+ self.assertEqual(mailing.delivered, 5)
+
+ # link trackers
+ links = self.env['link.tracker'].sudo().search([('mass_mailing_id', '=', mailing.id)])
+ self.assertEqual(len(links), 1)
+ self.assertEqual(links.mapped('url'), [_url])
+ # check UTMS are correctly set on redirect URL
+ redirect_url = urls.url_parse(links.redirected_url)
+ redirect_params = redirect_url.decode_query().to_dict(flat=True)
+ self.assertEqual(redirect_url.scheme, 'https')
+ self.assertEqual(redirect_url.decode_netloc(), 'www.example.com')
+ self.assertEqual(redirect_url.path, '/foo/bar')
+ self.assertEqual(redirect_params, {
+ 'utm_source': mailing.name,
+ 'utm_medium': self.test_medium.name,
+ 'baz': 'qux',
+ })
+
+
+class TestAccessRights(TransactionCase):
def test_01_mass_mail_blacklist(self):
mass_mailing_contacts = self.env['mail.mass_mailing.contact']
@@ -204,7 +265,7 @@ class TestAccessRights(common.TransactionCase):
'Opt Out ignored email number incorrect, should be equals to 1')
-class TestOnResPartner(common.TransactionCase):
+class TestOnResPartner(TransactionCase):
def test_mass_mail_on_res_partner(self):
partners = self.env['res.partner']