[FIX] test_(performance/mail): better use test_performance in test_mail and update counters
Containing * fix self._round not always existing; * fix counter for activity creation; * use self.str() in order to have some variation in test_mail; * separate base performance to mail feature specific performance tests;
This commit is contained in:
@@ -17,7 +17,6 @@ class TestMailPerformance(TestPerformance):
|
||||
'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])],
|
||||
})
|
||||
@@ -26,9 +25,6 @@ class TestMailPerformance(TestPerformance):
|
||||
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'. """
|
||||
@@ -89,17 +85,45 @@ class TestMailPerformance(TestPerformance):
|
||||
|
||||
@queryCount(admin=22, emp=29)
|
||||
def test_simple(self):
|
||||
self.env['mail.test.simple'].create({'name': 'Zboobs'})
|
||||
""" Create records inheriting from 'mail.thread' (simple models) """
|
||||
self.env['mail.test.simple'].create({'name': self.str('Test')})
|
||||
|
||||
|
||||
class TestAdvMailPerformance(TestPerformance):
|
||||
|
||||
def setUp(self):
|
||||
super(TestAdvMailPerformance, 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'
|
||||
|
||||
@queryCount(admin=25, emp=32)
|
||||
def test_activity(self):
|
||||
self.env['mail.test.activity'].create({'name': 'Zboobs'})
|
||||
self.env['mail.test.activity'].create({'name': self.str('Test')})
|
||||
|
||||
@queryCount(admin=75, emp=75)
|
||||
@queryCount(admin=45, emp=50)
|
||||
def test_activity_full(self):
|
||||
test_record_activity = self.env['mail.test.activity'].create({'name': self.str('Test')})
|
||||
res_id = test_record_activity.id
|
||||
self.resetQueryCount()
|
||||
|
||||
self.env['mail.activity'].with_context({
|
||||
'default_res_model': 'mail.test.activity',
|
||||
}).create({
|
||||
'summary': 'Test Activity',
|
||||
'res_id': self.test_record_activity_id,
|
||||
'summary': self.str('Test Activity'),
|
||||
'res_id': res_id,
|
||||
})
|
||||
|
||||
@@ -12,7 +12,8 @@ sql_logger = logging.getLogger('odoo.sql_db')
|
||||
|
||||
|
||||
def queryCount(**counters):
|
||||
""" Decorate a method to check the number of queries it makes. """
|
||||
""" Decorate a method to check the number of queries it makes. Counters
|
||||
is a dict { 'user_login': expected_query_count } """
|
||||
def decorate(func):
|
||||
@functools.wraps(func)
|
||||
def wrapper(self):
|
||||
@@ -20,7 +21,6 @@ def queryCount(**counters):
|
||||
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
|
||||
@@ -43,6 +43,10 @@ def queryCount(**counters):
|
||||
|
||||
class TestPerformance(TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestPerformance, self).setUp()
|
||||
self._round = False
|
||||
|
||||
def assertQueryCount(self, actual, expected, message):
|
||||
self.assertLessEqual(actual, expected, message)
|
||||
if actual < expected:
|
||||
|
||||
Reference in New Issue
Block a user