[ADD] test_mail: add some performances tests

This commit is contained in:
Thibault Delavallée
2017-11-29 10:11:15 +01:00
parent d040bfde89
commit 22cce3be9d
2 changed files with 46 additions and 1 deletions
@@ -6,6 +6,29 @@ from odoo.addons.test_performance.tests.test_performance import TestPerformance,
class TestMailPerformance(TestPerformance):
def setUp(self):
super(TestMailPerformance, self).setUp()
self.user_employee = self.env['res.users'].with_context({
'no_reset_password': True,
'mail_create_nolog': True,
'mail_create_nosubscribe': True,
'mail_notrack': True,
}).create({
'name': 'Ernest Employee',
'login': 'emp',
'email': 'e.e@example.com',
'signature': '--\nErnest',
'notification_type': 'inbox',
'groups_id': [(6, 0, [self.env.ref('base.group_user').id])],
})
# for performances test
self.admin = self.env.user
self.admin.login = 'admin'
self.test_record_activity = self.env['mail.test.activity'].create({'name': 'Zboobs'})
self.test_record_activity_id = self.test_record_activity.id
@queryCount(admin=3, demo=3)
def test_read_mail(self):
""" Read records inheriting from 'mail.thread'. """
@@ -63,3 +86,20 @@ class TestMailPerformance(TestPerformance):
""" Create records inheriting from 'mail.thread' (with field tracking). """
model = self.env['test_performance.mail']
model.create({'name': self.str('Y')})
@queryCount(admin=22, emp=29)
def test_simple(self):
self.env['mail.test.simple'].create({'name': 'Zboobs'})
@queryCount(admin=25, emp=32)
def test_activity(self):
self.env['mail.test.activity'].create({'name': 'Zboobs'})
@queryCount(admin=75, emp=75)
def test_activity_full(self):
self.env['mail.activity'].with_context({
'default_res_model': 'mail.test.activity',
}).create({
'summary': 'Test Activity',
'res_id': self.test_record_activity_id,
})
@@ -16,7 +16,12 @@ def queryCount(**counters):
def decorate(func):
@functools.wraps(func)
def wrapper(self):
for user in self.env.user + self.env.ref('base.user_demo'):
if hasattr(self, 'test_users'):
users = self.test_users.filtered(lambda user: user.login in counters.keys())
else:
users = self.env['res.users'].search([('login', 'in', list(counters.keys()))])
# for user in self.env.user + self.env.ref('base.user_demo'):
for user in users:
# switch user
self.uid = user.id
self.env = self.env(user=self.uid)