[MOV] test_mail: split post and composer tests
PURPOSE
In order to rewrite some tests, remove low-level tests and add coverage
first step is to reorganize a bit test_mail content. Several tests cases
are spread among several files and finding back some feature coverage
tests is not easy.
SPECIFICATIONS
Reorganize tests, notably
* put message_post related test in test_message_post;
* have only composer related test in test_message_compose(r);
* put alias tests in test_mail_gateway;
* move some discuss tests to post tests as they are linked to notification
details, not really Discuss features.
LINKS
Task 1958697
This commit is contained in:
@@ -12,8 +12,9 @@ from . import test_mail_channel
|
||||
from . import test_mail_gateway
|
||||
from . import test_mail_redirect
|
||||
from . import test_mail_template
|
||||
from . import test_message_compose
|
||||
from . import test_message_composerr
|
||||
from . import test_message_management
|
||||
from . import test_message_post
|
||||
from . import test_message_track
|
||||
from . import test_odoobot
|
||||
from . import test_performance
|
||||
|
||||
@@ -79,49 +79,24 @@ class TestChatterTweaks(BaseFunctionalTest, TestRecipients):
|
||||
self.assertEqual(len(rec.sudo().mapped('message_ids.tracking_value_ids')), 0,
|
||||
"Creation message without tracking values should have been posted")
|
||||
|
||||
def test_cache_invalidation(self):
|
||||
""" Test that creating a mail-thread record does not invalidate the whole cache. """
|
||||
# make a new record in cache
|
||||
record = self.env['res.partner'].new({'name': 'Brave New Partner'})
|
||||
self.assertTrue(record.name)
|
||||
|
||||
class TestNotifications(BaseFunctionalTest, TestRecipients, MockEmails):
|
||||
# creating a mail-thread record should not invalidate the whole cache
|
||||
self.env['res.partner'].create({'name': 'Actual Partner'})
|
||||
self.assertTrue(record.name)
|
||||
|
||||
|
||||
class TestDiscuss(BaseFunctionalTest, TestRecipients, MockEmails):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestNotifications, cls).setUpClass()
|
||||
cls._create_portal_user()
|
||||
super(TestDiscuss, cls).setUpClass()
|
||||
cls.test_record = cls.env['mail.test.simple'].with_context(cls._test_context).create({'name': 'Test', 'email_from': 'ignasse@example.com'})
|
||||
|
||||
(cls.user_employee | cls.user_admin).write({'notification_type': 'inbox'})
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_needaction(self):
|
||||
with self.assertNotifications(partner_employee=(1, 'inbox', 'unread'), partner_admin=(0, '', '')):
|
||||
self.test_record.message_post(
|
||||
body='Test', message_type='comment', subtype='mail.mt_comment',
|
||||
partner_ids=[self.user_employee.partner_id.id])
|
||||
|
||||
self.test_record.message_subscribe([self.partner_1.id])
|
||||
with self.assertNotifications(partner_employee=(1, 'inbox', 'unread'), partner_admin=(0, '', ''), partner_1=(1, 'email', 'read')):
|
||||
self.test_record.message_post(
|
||||
body='Test', message_type='comment', subtype='mail.mt_comment',
|
||||
partner_ids=[self.user_employee.partner_id.id])
|
||||
|
||||
with self.assertNotifications(partner_admin=(0, '', ''), partner_1=(1, 'email', 'read'), partner_portal=(1, 'email', 'read')):
|
||||
self.test_record.message_post(
|
||||
body='Test', message_type='comment', subtype='mail.mt_comment',
|
||||
partner_ids=[self.partner_portal.id])
|
||||
|
||||
def test_inactive_follower(self):
|
||||
# In some case odoobot is follower of a record.
|
||||
# Even if it shouldn't be the case, we want to be sure that odoobot is not notified
|
||||
self.test_record._message_subscribe(self.user_employee.partner_id.ids)
|
||||
with self.assertNotifications(partner_employee=(1, 'inbox', 'unread')):
|
||||
self.test_record.message_post(
|
||||
body='Test', message_type='comment', subtype='mail.mt_comment')
|
||||
self.user_employee.active = False
|
||||
# at this point, partner is still active and would receive an email notification
|
||||
self.user_employee.partner_id._write({'active': False})
|
||||
with self.assertNotifications(partner_employee=(0, '', '')):
|
||||
self.test_record.message_post(
|
||||
body='Test', message_type='comment', subtype='mail.mt_comment')
|
||||
|
||||
def test_set_message_done_user(self):
|
||||
with self.assertNotifications(partner_employee=(0, '', '')):
|
||||
message = self.test_record.message_post(
|
||||
@@ -145,20 +120,3 @@ class TestNotifications(BaseFunctionalTest, TestRecipients, MockEmails):
|
||||
msg.toggle_message_starred()
|
||||
self.assertFalse(msg.starred)
|
||||
self.assertTrue(msg_emp.starred)
|
||||
|
||||
|
||||
class TestChatterMisc(BaseFunctionalTest):
|
||||
|
||||
def test_alias_setup(self):
|
||||
alias = self.env['mail.alias'].with_context(alias_model_name='mail.test').create({'alias_name': 'b4r+_#_R3wl$$'})
|
||||
self.assertEqual(alias.alias_name, 'b4r+_-_r3wl-', 'Disallowed chars should be replaced by hyphens')
|
||||
|
||||
def test_cache_invalidation(self):
|
||||
""" Test that creating a mail-thread record does not invalidate the whole cache. """
|
||||
# make a new record in cache
|
||||
record = self.env['res.partner'].new({'name': 'Brave New Partner'})
|
||||
self.assertTrue(record.name)
|
||||
|
||||
# creating a mail-thread record should not invalidate the whole cache
|
||||
self.env['res.partner'].create({'name': 'Actual Partner'})
|
||||
self.assertTrue(record.name)
|
||||
|
||||
@@ -69,6 +69,14 @@ class TestEmailParsing(BaseFunctionalTest, MockEmails):
|
||||
self.env['mail.thread'].message_parse(email.message_from_string(pycompat.to_text(test_mail_data.MAIL_XHTML)))
|
||||
|
||||
|
||||
@tagged('mail_gateway')
|
||||
class TestMailAlias(BaseFunctionalTest):
|
||||
|
||||
def test_alias_setup(self):
|
||||
alias = self.env['mail.alias'].with_context(alias_model_name='mail.test').create({'alias_name': 'b4r+_#_R3wl$$'})
|
||||
self.assertEqual(alias.alias_name, 'b4r+_-_r3wl-', 'Disallowed chars should be replaced by hyphens')
|
||||
|
||||
|
||||
@tagged('mail_gateway')
|
||||
class TestMailgateway(BaseFunctionalTest, MockEmails):
|
||||
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from odoo.addons.test_mail.tests.common import BaseFunctionalTest, MockEmails, TestRecipients
|
||||
from odoo.addons.test_mail.tests.common import mail_new_test_user
|
||||
from odoo.addons.test_mail.models.test_mail_models import MailTestSimple
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
|
||||
class TestComposer(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestComposer, cls).setUpClass()
|
||||
cls.test_record = cls.env['mail.test.simple'].with_context(cls._test_context).create({'name': 'Test', 'email_from': 'ignasse@example.com'})
|
||||
|
||||
# configure mailing
|
||||
cls.alias_domain = 'schlouby.fr'
|
||||
cls.alias_catchall = 'test+catchall'
|
||||
cls.env['ir.config_parameter'].set_param('mail.catchall.domain', cls.alias_domain)
|
||||
cls.env['ir.config_parameter'].set_param('mail.catchall.alias', cls.alias_catchall)
|
||||
|
||||
# admin should not receive emails
|
||||
cls.user_admin.write({'notification_type': 'email'})
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_composer_comment(self):
|
||||
composer = self.env['mail.compose.message'].with_context({
|
||||
'default_composition_mode': 'comment',
|
||||
'default_model': self.test_record._name,
|
||||
'default_res_id': self.test_record.id,
|
||||
}).with_user(self.user_employee).create({
|
||||
'body': '<p>Test Body</p>',
|
||||
'partner_ids': [(4, self.partner_1.id), (4, self.partner_2.id)]
|
||||
})
|
||||
composer.send_mail()
|
||||
|
||||
message = self.test_record.message_ids[0]
|
||||
self.assertEqual(message.body, '<p>Test Body</p>')
|
||||
self.assertEqual(message.author_id, self.user_employee.partner_id)
|
||||
self.assertEqual(message.subject, 'Re: %s' % self.test_record.name)
|
||||
self.assertEqual(message.subtype_id, self.env.ref('mail.mt_comment'))
|
||||
self.assertEqual(message.partner_ids, self.partner_1 | self.partner_2)
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_composer_comment_parent(self):
|
||||
parent = self.test_record.message_post(body='Test')
|
||||
|
||||
self.env['mail.compose.message'].with_context({
|
||||
'default_composition_mode': 'comment',
|
||||
'default_parent_id': parent.id
|
||||
}).with_user(self.user_employee).create({
|
||||
'body': '<p>Mega</p>',
|
||||
}).send_mail()
|
||||
|
||||
message = self.test_record.message_ids[0]
|
||||
self.assertEqual(message.body, '<p>Mega</p>')
|
||||
self.assertEqual(message.parent_id, parent)
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_composer_mass_mail(self):
|
||||
test_record_2 = self.env['mail.test.simple'].with_context(self._test_context).create({'name': 'Test2'})
|
||||
|
||||
composer = self.env['mail.compose.message'].with_context({
|
||||
'default_composition_mode': 'mass_mail',
|
||||
'default_model': self.test_record._name,
|
||||
'default_res_id': False,
|
||||
'active_ids': [self.test_record.id, test_record_2.id]
|
||||
}).with_user(self.user_employee).create({
|
||||
'subject': 'Testing ${object.name}',
|
||||
'body': '<p>${object.name}</p>',
|
||||
'partner_ids': [(4, self.partner_1.id), (4, self.partner_2.id)]
|
||||
})
|
||||
composer.with_context({
|
||||
'default_res_id': -1,
|
||||
'active_ids': [self.test_record.id, test_record_2.id]
|
||||
}).send_mail()
|
||||
|
||||
# check mail_mail
|
||||
mails = self.env['mail.mail'].search([('subject', 'ilike', 'Testing')])
|
||||
for mail in mails:
|
||||
self.assertEqual(mail.recipient_ids, self.partner_1 | self.partner_2,
|
||||
'compose wizard: mail_mail mass mailing: mail.mail in mass mail incorrect recipients')
|
||||
|
||||
# check message on test_record
|
||||
message1 = self.test_record.message_ids[0]
|
||||
self.assertEqual(message1.subject, 'Testing %s' % self.test_record.name)
|
||||
self.assertEqual(message1.body, '<p>%s</p>' % self.test_record.name)
|
||||
|
||||
# check message on test_record_2
|
||||
message1 = test_record_2.message_ids[0]
|
||||
self.assertEqual(message1.subject, 'Testing %s' % test_record_2.name)
|
||||
self.assertEqual(message1.body, '<p>%s</p>' % test_record_2.name)
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_composer_mass_mail_active_domain(self):
|
||||
test_record_2 = self.env['mail.test.simple'].with_context(self._test_context).create({'name': 'Test2'})
|
||||
|
||||
self.env['mail.compose.message'].with_context({
|
||||
'default_composition_mode': 'mass_mail',
|
||||
'default_model': self.test_record._name,
|
||||
'default_use_active_domain': True,
|
||||
'active_ids': [self.test_record.id],
|
||||
'active_domain': [('name', 'in', ['%s' % self.test_record.name, '%s' % test_record_2.name])],
|
||||
}).with_user(self.user_employee).create({
|
||||
'subject': 'From Composer Test',
|
||||
'body': '${object.name}',
|
||||
}).send_mail()
|
||||
|
||||
self.assertEqual(self.test_record.message_ids[0].subject, 'From Composer Test')
|
||||
self.assertEqual(test_record_2.message_ids[0].subject, 'From Composer Test')
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_message_compose_mass_mail_no_active_domain(self):
|
||||
test_record_2 = self.env['mail.test.simple'].with_context(self._test_context).create({'name': 'Test2'})
|
||||
|
||||
self.env['mail.compose.message'].with_context({
|
||||
'default_composition_mode': 'mass_mail',
|
||||
'default_model': self.test_record._name,
|
||||
'default_use_active_domain': False,
|
||||
'active_ids': [self.test_record.id],
|
||||
'active_domain': [('name', 'in', ['%s' % self.test_record.name, '%s' % test_record_2.name])],
|
||||
}).with_user(self.user_employee).create({
|
||||
'subject': 'From Composer Test',
|
||||
'body': '${object.name}',
|
||||
}).send_mail()
|
||||
|
||||
self.assertEqual(self.test_record.message_ids[0].subject, 'From Composer Test')
|
||||
self.assertFalse(test_record_2.message_ids.ids)
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_message_compose_portal_ok(self):
|
||||
portal_user = mail_new_test_user(self.env, login='chell', groups='base.group_portal', name='Chell Gladys')
|
||||
|
||||
with patch.object(MailTestSimple, 'check_access_rights', return_value=True):
|
||||
ComposerPortal = self.env['mail.compose.message'].with_user(portal_user)
|
||||
|
||||
ComposerPortal.with_context({
|
||||
'default_composition_mode': 'comment',
|
||||
'default_model': self.test_record._name,
|
||||
'default_res_id': self.test_record.id,
|
||||
}).create({
|
||||
'subject': 'Subject',
|
||||
'body': '<p>Body text</p>',
|
||||
'partner_ids': []}).send_mail()
|
||||
|
||||
self.assertEqual(self.test_record.message_ids[0].body, '<p>Body text</p>')
|
||||
self.assertEqual(self.test_record.message_ids[0].author_id, portal_user.partner_id)
|
||||
|
||||
ComposerPortal.with_context({
|
||||
'default_composition_mode': 'comment',
|
||||
'default_parent_id': self.test_record.message_ids.ids[0],
|
||||
}).create({
|
||||
'subject': 'Subject',
|
||||
'body': '<p>Body text 2</p>'}).send_mail()
|
||||
|
||||
self.assertEqual(self.test_record.message_ids[0].body, '<p>Body text 2</p>')
|
||||
self.assertEqual(self.test_record.message_ids[0].author_id, portal_user.partner_id)
|
||||
+39
-161
@@ -7,18 +7,18 @@ from email.utils import formataddr
|
||||
from unittest.mock import patch
|
||||
|
||||
from odoo.addons.test_mail.tests.common import BaseFunctionalTest, MockEmails, TestRecipients
|
||||
from odoo.addons.test_mail.tests.common import mail_new_test_user
|
||||
from odoo.addons.test_mail.data.test_mail_data import MAIL_TEMPLATE_PLAINTEXT
|
||||
from odoo.addons.test_mail.models.test_mail_models import MailTestSimple
|
||||
from odoo.exceptions import AccessError
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
|
||||
class TestMessagePost(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
class TestMessagePost(BaseFunctionalTest, TestRecipients, MockEmails):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestMessagePost, cls).setUpClass()
|
||||
cls._create_portal_user()
|
||||
cls.test_record = cls.env['mail.test.simple'].with_context(cls._test_context).create({'name': 'Test', 'email_from': 'ignasse@example.com'})
|
||||
|
||||
# configure mailing
|
||||
@@ -27,9 +27,42 @@ class TestMessagePost(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
cls.env['ir.config_parameter'].set_param('mail.catchall.domain', cls.alias_domain)
|
||||
cls.env['ir.config_parameter'].set_param('mail.catchall.alias', cls.alias_catchall)
|
||||
|
||||
# admin should not receive emails
|
||||
cls.user_admin.write({'notification_type': 'email'})
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_post_needaction(self):
|
||||
(self.user_employee | self.user_admin).write({'notification_type': 'inbox'})
|
||||
with self.assertNotifications(partner_employee=(1, 'inbox', 'unread'), partner_admin=(0, '', '')):
|
||||
self.test_record.message_post(
|
||||
body='Test', message_type='comment', subtype='mail.mt_comment',
|
||||
partner_ids=[self.user_employee.partner_id.id])
|
||||
|
||||
self.test_record.message_subscribe([self.partner_1.id])
|
||||
with self.assertNotifications(partner_employee=(1, 'inbox', 'unread'), partner_admin=(0, '', ''), partner_1=(1, 'email', 'read')):
|
||||
self.test_record.message_post(
|
||||
body='Test', message_type='comment', subtype='mail.mt_comment',
|
||||
partner_ids=[self.user_employee.partner_id.id])
|
||||
|
||||
with self.assertNotifications(partner_admin=(0, '', ''), partner_1=(1, 'email', 'read'), partner_portal=(1, 'email', 'read')):
|
||||
self.test_record.message_post(
|
||||
body='Test', message_type='comment', subtype='mail.mt_comment',
|
||||
partner_ids=[self.partner_portal.id])
|
||||
|
||||
def test_post_inactive_follower(self):
|
||||
# In some case odoobot is follower of a record.
|
||||
# Even if it shouldn't be the case, we want to be sure that odoobot is not notified
|
||||
(self.user_employee | self.user_admin).write({'notification_type': 'inbox'})
|
||||
self.test_record._message_subscribe(self.user_employee.partner_id.ids)
|
||||
with self.assertNotifications(partner_employee=(1, 'inbox', 'unread')):
|
||||
self.test_record.message_post(
|
||||
body='Test', message_type='comment', subtype='mail.mt_comment')
|
||||
self.user_employee.active = False
|
||||
# at this point, partner is still active and would receive an email notification
|
||||
self.user_employee.partner_id._write({'active': False})
|
||||
with self.assertNotifications(partner_employee=(0, '', '')):
|
||||
self.test_record.message_post(
|
||||
body='Test', message_type='comment', subtype='mail.mt_comment')
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_post_notifications(self):
|
||||
_body, _body_alt, _subject = '<p>Test Body</p>', 'Test Body', 'Test Subject'
|
||||
@@ -155,22 +188,18 @@ class TestMessagePost(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_post_portal_ok(self):
|
||||
portal_user = mail_new_test_user(self.env, login='chell', groups='base.group_portal', name='Chell Gladys')
|
||||
|
||||
with patch.object(MailTestSimple, 'check_access_rights', return_value=True):
|
||||
self.test_record.message_subscribe((self.partner_1 | self.user_employee.partner_id).ids)
|
||||
new_msg = self.test_record.with_user(portal_user).message_post(
|
||||
new_msg = self.test_record.with_user(self.user_portal).message_post(
|
||||
body='<p>Test</p>', subject='Subject',
|
||||
message_type='comment', subtype='mt_comment')
|
||||
|
||||
self.assertEqual(new_msg.sudo().notified_partner_ids, (self.partner_1 | self.user_employee.partner_id))
|
||||
self.assertEmails(portal_user.partner_id, [[self.partner_1], [self.user_employee.partner_id]])
|
||||
self.assertEmails(self.user_portal.partner_id, [[self.partner_1], [self.user_employee.partner_id]])
|
||||
|
||||
def test_post_portal_crash(self):
|
||||
portal_user = mail_new_test_user(self.env, login='chell', groups='base.group_portal', name='Chell Gladys')
|
||||
|
||||
with self.assertRaises(AccessError):
|
||||
self.test_record.with_user(portal_user).message_post(
|
||||
self.test_record.with_user(self.user_portal).message_post(
|
||||
body='<p>Test</p>', subject='Subject',
|
||||
message_type='comment', subtype='mt_comment')
|
||||
|
||||
@@ -221,154 +250,3 @@ class TestMessagePost(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
self.assertEqual(new_notification.notified_partner_ids, self.partner_1 | self.user_employee.partner_id)
|
||||
self.assertNotIn(new_notification, self.test_record.message_ids)
|
||||
# todo xdo add test message_notify on thread with followers and stuff
|
||||
|
||||
|
||||
class TestComposer(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestComposer, cls).setUpClass()
|
||||
cls.test_record = cls.env['mail.test.simple'].with_context(cls._test_context).create({'name': 'Test', 'email_from': 'ignasse@example.com'})
|
||||
|
||||
# configure mailing
|
||||
cls.alias_domain = 'schlouby.fr'
|
||||
cls.alias_catchall = 'test+catchall'
|
||||
cls.env['ir.config_parameter'].set_param('mail.catchall.domain', cls.alias_domain)
|
||||
cls.env['ir.config_parameter'].set_param('mail.catchall.alias', cls.alias_catchall)
|
||||
|
||||
# admin should not receive emails
|
||||
cls.user_admin.write({'notification_type': 'email'})
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_composer_comment(self):
|
||||
composer = self.env['mail.compose.message'].with_context({
|
||||
'default_composition_mode': 'comment',
|
||||
'default_model': self.test_record._name,
|
||||
'default_res_id': self.test_record.id,
|
||||
}).with_user(self.user_employee).create({
|
||||
'body': '<p>Test Body</p>',
|
||||
'partner_ids': [(4, self.partner_1.id), (4, self.partner_2.id)]
|
||||
})
|
||||
composer.send_mail()
|
||||
|
||||
message = self.test_record.message_ids[0]
|
||||
self.assertEqual(message.body, '<p>Test Body</p>')
|
||||
self.assertEqual(message.author_id, self.user_employee.partner_id)
|
||||
self.assertEqual(message.subject, 'Re: %s' % self.test_record.name)
|
||||
self.assertEqual(message.subtype_id, self.env.ref('mail.mt_comment'))
|
||||
self.assertEqual(message.partner_ids, self.partner_1 | self.partner_2)
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_composer_comment_parent(self):
|
||||
parent = self.test_record.message_post(body='Test')
|
||||
|
||||
self.env['mail.compose.message'].with_context({
|
||||
'default_composition_mode': 'comment',
|
||||
'default_parent_id': parent.id
|
||||
}).with_user(self.user_employee).create({
|
||||
'body': '<p>Mega</p>',
|
||||
}).send_mail()
|
||||
|
||||
message = self.test_record.message_ids[0]
|
||||
self.assertEqual(message.body, '<p>Mega</p>')
|
||||
self.assertEqual(message.parent_id, parent)
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_composer_mass_mail(self):
|
||||
test_record_2 = self.env['mail.test.simple'].with_context(self._test_context).create({'name': 'Test2'})
|
||||
|
||||
composer = self.env['mail.compose.message'].with_context({
|
||||
'default_composition_mode': 'mass_mail',
|
||||
'default_model': self.test_record._name,
|
||||
'default_res_id': False,
|
||||
'active_ids': [self.test_record.id, test_record_2.id]
|
||||
}).with_user(self.user_employee).create({
|
||||
'subject': 'Testing ${object.name}',
|
||||
'body': '<p>${object.name}</p>',
|
||||
'partner_ids': [(4, self.partner_1.id), (4, self.partner_2.id)]
|
||||
})
|
||||
composer.with_context({
|
||||
'default_res_id': -1,
|
||||
'active_ids': [self.test_record.id, test_record_2.id]
|
||||
}).send_mail()
|
||||
|
||||
# check mail_mail
|
||||
mails = self.env['mail.mail'].search([('subject', 'ilike', 'Testing')])
|
||||
for mail in mails:
|
||||
self.assertEqual(mail.recipient_ids, self.partner_1 | self.partner_2,
|
||||
'compose wizard: mail_mail mass mailing: mail.mail in mass mail incorrect recipients')
|
||||
|
||||
# check message on test_record
|
||||
message1 = self.test_record.message_ids[0]
|
||||
self.assertEqual(message1.subject, 'Testing %s' % self.test_record.name)
|
||||
self.assertEqual(message1.body, '<p>%s</p>' % self.test_record.name)
|
||||
|
||||
# check message on test_record_2
|
||||
message1 = test_record_2.message_ids[0]
|
||||
self.assertEqual(message1.subject, 'Testing %s' % test_record_2.name)
|
||||
self.assertEqual(message1.body, '<p>%s</p>' % test_record_2.name)
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_composer_mass_mail_active_domain(self):
|
||||
test_record_2 = self.env['mail.test.simple'].with_context(self._test_context).create({'name': 'Test2'})
|
||||
|
||||
self.env['mail.compose.message'].with_context({
|
||||
'default_composition_mode': 'mass_mail',
|
||||
'default_model': self.test_record._name,
|
||||
'default_use_active_domain': True,
|
||||
'active_ids': [self.test_record.id],
|
||||
'active_domain': [('name', 'in', ['%s' % self.test_record.name, '%s' % test_record_2.name])],
|
||||
}).with_user(self.user_employee).create({
|
||||
'subject': 'From Composer Test',
|
||||
'body': '${object.name}',
|
||||
}).send_mail()
|
||||
|
||||
self.assertEqual(self.test_record.message_ids[0].subject, 'From Composer Test')
|
||||
self.assertEqual(test_record_2.message_ids[0].subject, 'From Composer Test')
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_message_compose_mass_mail_no_active_domain(self):
|
||||
test_record_2 = self.env['mail.test.simple'].with_context(self._test_context).create({'name': 'Test2'})
|
||||
|
||||
self.env['mail.compose.message'].with_context({
|
||||
'default_composition_mode': 'mass_mail',
|
||||
'default_model': self.test_record._name,
|
||||
'default_use_active_domain': False,
|
||||
'active_ids': [self.test_record.id],
|
||||
'active_domain': [('name', 'in', ['%s' % self.test_record.name, '%s' % test_record_2.name])],
|
||||
}).with_user(self.user_employee).create({
|
||||
'subject': 'From Composer Test',
|
||||
'body': '${object.name}',
|
||||
}).send_mail()
|
||||
|
||||
self.assertEqual(self.test_record.message_ids[0].subject, 'From Composer Test')
|
||||
self.assertFalse(test_record_2.message_ids.ids)
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_message_compose_portal_ok(self):
|
||||
portal_user = mail_new_test_user(self.env, login='chell', groups='base.group_portal', name='Chell Gladys')
|
||||
|
||||
with patch.object(MailTestSimple, 'check_access_rights', return_value=True):
|
||||
ComposerPortal = self.env['mail.compose.message'].with_user(portal_user)
|
||||
|
||||
ComposerPortal.with_context({
|
||||
'default_composition_mode': 'comment',
|
||||
'default_model': self.test_record._name,
|
||||
'default_res_id': self.test_record.id,
|
||||
}).create({
|
||||
'subject': 'Subject',
|
||||
'body': '<p>Body text</p>',
|
||||
'partner_ids': []}).send_mail()
|
||||
|
||||
self.assertEqual(self.test_record.message_ids[0].body, '<p>Body text</p>')
|
||||
self.assertEqual(self.test_record.message_ids[0].author_id, portal_user.partner_id)
|
||||
|
||||
ComposerPortal.with_context({
|
||||
'default_composition_mode': 'comment',
|
||||
'default_parent_id': self.test_record.message_ids.ids[0],
|
||||
}).create({
|
||||
'subject': 'Subject',
|
||||
'body': '<p>Body text 2</p>'}).send_mail()
|
||||
|
||||
self.assertEqual(self.test_record.message_ids[0].body, '<p>Body text 2</p>')
|
||||
self.assertEqual(self.test_record.message_ids[0].author_id, portal_user.partner_id)
|
||||
Reference in New Issue
Block a user