[IMP] test_mail: add test for reply_to computation on records

Purpose is to assert current behavior as this may change in master. Two
kind of tests are added: performance and multi company.

Task-2661036 (Performance tests data cleanup)
Prepares Task-36879 (MultiCompany Aliases)

closes odoo/odoo#77845

Related: odoo/enterprise#21456
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
Thibault Delavallée
2021-10-05 16:53:46 +00:00
parent 201d6bf771
commit 9146b68b3f
4 changed files with 120 additions and 0 deletions
+1
View File
@@ -933,6 +933,7 @@ class MailCommon(common.TransactionCase, MailCase):
cls.env, login='employee_c2',
groups='base.group_user',
company_id=cls.company_2.id,
company_ids=[(4, cls.company_2.id)],
name='Enguerrand Employee C2',
notification_type='inbox',
signature='--\nEnguerrand'
+1
View File
@@ -9,6 +9,7 @@ from . import test_mail_followers
from . import test_mail_message
from . import test_mail_mail
from . import test_mail_gateway
from . import test_mail_multicompany
from . import test_mail_thread_internals
from . import test_mail_template
from . import test_mail_template_preview
@@ -0,0 +1,92 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import socket
from odoo.addons.test_mail.tests.common import TestMailCommon, TestRecipients
from odoo.tests import tagged
from odoo.tests.common import users
from odoo.tools import formataddr
@tagged('multi_company')
class TestMultiCompanySetup(TestMailCommon, TestRecipients):
@classmethod
def setUpClass(cls):
super(TestMultiCompanySetup, cls).setUpClass()
cls._activate_multi_company()
cls.test_model = cls.env['ir.model']._get('mail.test.gateway')
cls.email_from = '"Sylvie Lelitre" <test.sylvie.lelitre@agrolait.com>'
cls.test_record = cls.env['mail.test.gateway'].with_context(cls._test_context).create({
'name': 'Test',
'email_from': 'ignasse@example.com',
}).with_context({})
cls.partner_1 = cls.env['res.partner'].with_context(cls._test_context).create({
'name': 'Valid Lelitre',
'email': 'valid.lelitre@agrolait.com',
})
# groups@.. will cause the creation of new mail.test.gateway
cls.alias = cls.env['mail.alias'].create({
'alias_name': 'groups',
'alias_user_id': False,
'alias_model_id': cls.test_model.id,
'alias_contact': 'everyone'})
# Set a first message on public group to test update and hierarchy
cls.fake_email = cls.env['mail.message'].create({
'model': 'mail.test.gateway',
'res_id': cls.test_record.id,
'subject': 'Public Discussion',
'message_type': 'email',
'subtype_id': cls.env.ref('mail.mt_comment').id,
'author_id': cls.partner_1.id,
'message_id': '<123456-openerp-%s-mail.test.gateway@%s>' % (cls.test_record.id, socket.gethostname()),
})
cls._init_mail_gateway()
@users('employee')
def test_notify_reply_to_computation(self):
test_record = self.env['mail.test.gateway'].browse(self.test_record.ids)
res = test_record._notify_get_reply_to()
self.assertEqual(
res[test_record.id],
formataddr((
"%s %s" % (self.user_employee.company_id.name, test_record.name),
"%s@%s" % (self.alias_catchall, self.alias_domain)))
)
@users('employee_c2')
def test_notify_reply_to_computation_mc(self):
""" Test reply-to computation in multi company mode. Add notably tests
depending on user company_id / company_ids. """
# Test1: no company_id field
test_record = self.env['mail.test.gateway'].browse(self.test_record.ids)
res = test_record._notify_get_reply_to()
self.assertEqual(
res[test_record.id],
formataddr((
"%s %s" % (self.user_employee_c2.company_id.name, test_record.name),
"%s@%s" % (self.alias_catchall, self.alias_domain)))
)
# Test2: company_id field, MC environment
self.user_employee_c2.write({'company_ids': [(4, self.user_employee.company_id.id)]})
test_records = self.env['mail.test.multi.company'].create([
{'name': 'Test',
'company_id': self.user_employee.company_id.id},
{'name': 'Test',
'company_id': self.user_employee_c2.company_id.id},
])
res = test_records._notify_get_reply_to()
for test_record in test_records:
self.assertEqual(
res[test_record.id],
formataddr((
"%s %s" % (self.user_employee_c2.company_id.name, test_record.name),
"%s@%s" % (self.alias_catchall, self.alias_domain)))
)
@@ -466,6 +466,32 @@ class TestMailAPIPerformance(BaseMailPerformance):
record.write({'field_%s' % (i): 'Field With Cache %s' % (i) for i in range(3)})
record.flush()
@users('__system__', 'employee')
@warmup
def test_notification_reply_to_batch(self):
test_records_sudo = self.env['mail.test.container'].sudo().create([
{'alias_name': 'alias.test.%s.%d' % (self.env.user.name, index),
'customer_id': self.customer.id,
'name': 'Test_%d' % index,
} for index in range(10)
])
with self.assertQueryCount(__system__=1, employee=1):
test_records = self.env['mail.test.container'].browse(test_records_sudo.ids)
reply_to = test_records._notify_get_reply_to(
default=self.env.user.email_formatted
)
for record in test_records:
self.assertEqual(
reply_to[record.id],
formataddr(
("%s %s" % (self.env.user.company_id.name, record.name),
"%s@%s" % (record.alias_name, self.alias_domain)
)
)
)
@tagged('mail_performance')
class TestMailComplexPerformance(BaseMailPerformance):