summaryrefslogtreecommitdiff
path: root/addons/test_mass_mailing
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2018-10-29 14:23:16 +0000
committerThibault Delavallée <tde@odoo.com>2019-01-14 10:34:26 +0000
commitb670911a92883ebea49d427acafe2abac2753ace (patch)
tree72c4e143401d10882813702b85b6261718b36ec0 /addons/test_mass_mailing
parent75638ffb94fa4ae1753f733d8cb6f7f58f0b6a0a (diff)
[REF] link_tracker, mass_mailing: simplify add_click method and add tests
In this commit we rewrite a bit add_click in order to remove the inlined sudo and ease inheritance and parameter management inside the method. Access through controllers is sudo-ed as the main API method is now done with current user access rights. This commit is linked to task ID 1904277 and PR #28242.
Diffstat (limited to 'addons/test_mass_mailing')
-rw-r--r--addons/test_mass_mailing/tests/__init__.py1
-rw-r--r--addons/test_mass_mailing/tests/test_link.py65
2 files changed, 66 insertions, 0 deletions
diff --git a/addons/test_mass_mailing/tests/__init__.py b/addons/test_mass_mailing/tests/__init__.py
index 4283fdd0861..652f56e3078 100644
--- a/addons/test_mass_mailing/tests/__init__.py
+++ b/addons/test_mass_mailing/tests/__init__.py
@@ -4,6 +4,7 @@
from . import test_blacklist
from . import test_blacklist_mixin
from . import test_composer
+from . import test_link
from . import test_mail_auto_blacklist
from . import test_mail_channel
from . import test_mass_mailing
diff --git a/addons/test_mass_mailing/tests/test_link.py b/addons/test_mass_mailing/tests/test_link.py
new file mode 100644
index 00000000000..99819944d82
--- /dev/null
+++ b/addons/test_mass_mailing/tests/test_link.py
@@ -0,0 +1,65 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo.tests.common import users
+from odoo.addons.test_mass_mailing.tests import common
+
+
+class TestLinkTracker(common.MassMailingCase):
+
+ def setUp(self):
+ super(TestLinkTracker, self).setUp()
+
+ self.link = self.env['link.tracker'].create({
+ 'url': 'https://www.example.com'
+ })
+
+ self.click = self.env['link.tracker.click'].create({
+ 'link_id': self.link.id,
+ 'ip': '100.00.00.00',
+ 'country_id': self.env.ref('base.fr').id,
+ })
+
+ def test_add_link(self):
+ code = self.link.code
+ self.assertEqual(self.link.count, 1)
+
+ # click from a new IP should create a new entry
+ click = self.env['link.tracker.click'].sudo().add_click(
+ code,
+ ip='100.00.00.01',
+ country_code='BEL'
+ )
+ self.assertEqual(click.ip, '100.00.00.01')
+ self.assertEqual(click.country_id, self.env.ref('base.be'))
+ self.assertEqual(self.link.count, 2)
+
+ # click from same IP (even another country) does not create a new entry
+ click = self.env['link.tracker.click'].sudo().add_click(
+ code,
+ ip='100.00.00.01',
+ country_code='FRA'
+ )
+ self.assertEqual(click, None)
+ self.assertEqual(self.link.count, 2)
+
+ @users('marketing')
+ def test_add_link_mail_stat(self):
+ mailing = self.env['mail.mass_mailing'].create({'name': 'Test Mailing'})
+ code = self.link.code
+ self.assertEqual(self.link.count, 1)
+ stat = self.env['mail.mail.statistics'].create({'mass_mailing_id': mailing.id})
+ self.assertFalse(stat.opened)
+ self.assertFalse(stat.clicked)
+
+ # click from a new IP should create a new entry and update stat when provided
+ click = self.env['link.tracker.click'].sudo().add_click(
+ code,
+ ip='100.00.00.01',
+ country_code='BEL',
+ mail_stat_id=stat.id
+ )
+ self.assertEqual(self.link.count, 2)
+ self.assertEqual(click.mass_mailing_id, mailing)
+ self.assertTrue(stat.opened)
+ self.assertTrue(stat.clicked)