Files
odoo_source/addons/test_mass_mailing/tests/test_link.py
T
Thibault Delavallée b287504977 [REF] test_mass_mailing: update module to new common
PURPOSE

Currently tools and asserts for mail tests are located inside test_mail
module. It makes difficult to re-use them in apps tests or force them to
write custom quick and dirty tools and asserts.

SPECIFICATIONS

Update this module to new tools / asserts / helpers / classes defined in mail
and test_mail.

In this commit we remove the ``MassMailingCase`` and replace it by a fresh
``TestMailCommon`` that is simply updated to hold a marketing user by default.
That way all mocks and asserts are available in all sub test classes.

Coming from common update, we have notably

  * ``BaseFunctionalTest`` class is replaced by the new ``TestMailCommon``
    pimped one;
  * ``assertNotifications`` is replaced by ``assertSinglePostNotifications``
    (shortcut for a simple message_post) or ``assertPostNotifications``
    (complete asserts involving several messages and notifications);
  * correctly invoke ``mock_mail_gateway`` when mocking email sending;
  * replace manual check of sent emails or ``assertEmails`` by
    ``assertSentEmails``;
  * remove custom mocks / checks and replace them by now standard mocks
    and assertions (if any);

LINKS

Task ID 2068986
PR #38070
2019-11-20 16:01:06 +00:00

66 lines
2.2 KiB
Python

# -*- 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.TestMailCommon):
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['mailing.mailing'].create({'name': 'Test Mailing', "subject": "Hi!"})
code = self.link.code
self.assertEqual(self.link.count, 1)
stat = self.env['mailing.trace'].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',
mailing_trace_id=stat.id
)
self.assertEqual(self.link.count, 2)
self.assertEqual(click.mass_mailing_id, mailing)
self.assertTrue(stat.opened)
self.assertTrue(stat.clicked)