From 010add290342ae1e2887450a381e0d1f0acd34e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 5 Dec 2017 17:02:32 +0100 Subject: [PATCH] [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; --- addons/test_mail/tests/test_performance.py | 42 +++++++++++++++---- .../tests/test_performance.py | 8 +++- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/addons/test_mail/tests/test_performance.py b/addons/test_mail/tests/test_performance.py index 980bea18fe9..7e981aad09f 100644 --- a/addons/test_mail/tests/test_performance.py +++ b/addons/test_mail/tests/test_performance.py @@ -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, }) diff --git a/odoo/addons/test_performance/tests/test_performance.py b/odoo/addons/test_performance/tests/test_performance.py index 6ef6c5a0c7b..005a68cc08e 100644 --- a/odoo/addons/test_performance/tests/test_performance.py +++ b/odoo/addons/test_performance/tests/test_performance.py @@ -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: