mail_* = mail, test_mail, test_mail_full, test_mass_mailing PURPOSE Improve tooling of mail tests. Use SMTP mockup class available in base tests in mail tests to have a better and simplified mock tool when dealing with mail tests. Remove old fashioned code. SPECIFICATIONS Include ``MockSmtplibCase`` directly into ``MockEmail`` so that we re-use existing components for mocking outgoing emails. Also make parameters for gateway coherent between those two classes (use same test values). Remove 'sim_error' weird parameter of Mail ``mock_mail_gateway`` and use standard mock 'side_effect' instead in some specific tests, notably on SMTP.connect() mock. Add some assert / tools method and improve existing tools, used for creating or improving test data. This will be used in future commits when adding new tests. Add outgoing mail servers data in mail tests, allowing to make tests closer to real life use cases. Remove unnecessary calls to ``_init_mail_gateway`` as it is automatically done in ``MailCommon.setUpClass()``. Try to consolidate starting test data, notably with countries, phone numbers or email in mind to be sure test mail are deterministic. Task-2673913 (TestMail: Cleanup and improve test coverage) Part-of: odoo/odoo#86393
52 lines
2.2 KiB
Python
52 lines
2.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo.addons.test_mail.tests.common import TestMailCommon, TestRecipients
|
|
from odoo.tests import tagged
|
|
from odoo.tests.common import users
|
|
|
|
|
|
@tagged('mail_composer_mixin')
|
|
class TestMailComposerMixin(TestMailCommon, TestRecipients):
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
super(TestMailComposerMixin, cls).setUpClass()
|
|
|
|
cls.mail_template = cls.env['mail.template'].create({
|
|
'subject': 'Subject for {{ object.name }}',
|
|
'body_html': '<p>Body for <t t-out="object.name"/></p>',
|
|
})
|
|
|
|
@users("employee")
|
|
def test_content_sync(self):
|
|
record = self.env['mail.test.composer.mixin'].create({
|
|
'name': 'Invite',
|
|
'template_id': self.mail_template.id,
|
|
})
|
|
self.assertEqual(record.subject, self.mail_template.subject)
|
|
self.assertEqual(record.body, self.mail_template.body_html)
|
|
|
|
subject = record._render_field('subject', record.ids)[record.id]
|
|
self.assertEqual(subject, 'Subject for %s' % record.name)
|
|
body = record._render_field('body', record.ids)[record.id]
|
|
self.assertEqual(body, '<p>Body for %s</p>' % record.name)
|
|
|
|
@users("employee")
|
|
def test_rendering(self):
|
|
record = self.env['mail.test.composer.mixin'].create({
|
|
'name': 'Invite',
|
|
'subject': 'Subject for {{ object.name }}',
|
|
'body': '<p>Content from <t t-out="user.name"/></p>',
|
|
'description': '<p>Description for <t t-esc="object.name"/></p>',
|
|
})
|
|
self.assertEqual(record.subject, 'Subject for {{ object.name }}')
|
|
self.assertEqual(record.body, '<p>Content from <t t-out="user.name"/></p>')
|
|
|
|
subject = record._render_field('subject', record.ids)[record.id]
|
|
self.assertEqual(subject, 'Subject for %s' % record.name)
|
|
body = record._render_field('body', record.ids)[record.id]
|
|
self.assertEqual(body, '<p>Content from %s</p>' % self.env.user.name)
|
|
description = record._render_field('description', record.ids)[record.id]
|
|
self.assertEqual(description, '<p>Description for Invite</p>')
|