[IMP][FIX] test_mail: correctly simulate email send in performance tests
Commit 356a421660 introduced a hook to avoid sending emails while
installing application data. However we have to carefully re-activate email
sending in tests that depend on them especially performance tests.
This commit also update performance counters to match the current state of
counters as it was not totally updated.
Commit linked to task ID 1902307.
This commit is contained in:
@@ -26,6 +26,9 @@ class TestMailPerformance(TransactionCase):
|
||||
'groups_id': [(6, 0, [self.env.ref('base.group_user').id])],
|
||||
})
|
||||
|
||||
# patch registry to simulate a ready environment
|
||||
self.patch(self.env.registry, 'ready', True)
|
||||
|
||||
@users('__system__', 'demo')
|
||||
@warmup
|
||||
def test_read_mail(self):
|
||||
@@ -146,6 +149,9 @@ class TestAdvMailPerformance(TransactionCase):
|
||||
'groups_id': [(6, 0, [self.env.ref('base.group_user').id])],
|
||||
})
|
||||
|
||||
# patch registry to simulate a ready environment
|
||||
self.patch(self.env.registry, 'ready', True)
|
||||
|
||||
# automatically follow activities, for backward compatibility concerning query count
|
||||
self.env.ref('mail.mt_activities').write({'default': True})
|
||||
|
||||
@@ -154,7 +160,7 @@ class TestAdvMailPerformance(TransactionCase):
|
||||
def test_adv_activity(self):
|
||||
model = self.env['mail.test.activity']
|
||||
|
||||
with self.assertQueryCount(__system__=9, emp=8): # test_mail only: 8 - 8
|
||||
with self.assertQueryCount(__system__=9, emp=8): # test_mail only: 9 - 8
|
||||
model.create({'name': 'Test'})
|
||||
|
||||
@users('__system__', 'emp')
|
||||
@@ -166,7 +172,7 @@ class TestAdvMailPerformance(TransactionCase):
|
||||
'default_res_model': 'mail.test.activity',
|
||||
})
|
||||
|
||||
with self.assertQueryCount(__system__=10, emp=15): # test_mail only: 9 - 13
|
||||
with self.assertQueryCount(__system__=10, emp=15): # com runbot: 9 - 15 // test_mail only: 10 - 14
|
||||
activity = MailActivity.create({
|
||||
'summary': 'Test Activity',
|
||||
'res_id': record.id,
|
||||
@@ -176,7 +182,7 @@ class TestAdvMailPerformance(TransactionCase):
|
||||
#voip module read activity_type during create leading to one less query in enterprise on action_feedback
|
||||
category = activity.activity_type_id.category
|
||||
|
||||
with self.assertQueryCount(__system__=26, emp=46): # test_mail only: 27 - 47
|
||||
with self.assertQueryCount(__system__=26, emp=46): # com runbot: 25 - 46 // test_mail only: 26 - 46
|
||||
activity.action_feedback(feedback='Zizisse Done !')
|
||||
|
||||
@users('__system__', 'emp')
|
||||
@@ -185,7 +191,7 @@ class TestAdvMailPerformance(TransactionCase):
|
||||
def test_adv_activity_mixin(self):
|
||||
record = self.env['mail.test.activity'].create({'name': 'Test'})
|
||||
|
||||
with self.assertQueryCount(__system__=10, emp=15): # test_mail only: 9 - 13
|
||||
with self.assertQueryCount(__system__=10, emp=15): # com runbot: 9 - 15 // test_mail only: 10 - 14
|
||||
activity = record.action_start('Test Start')
|
||||
#read activity_type to normalize cache between enterprise and community
|
||||
#voip module read activity_type during create leading to one less query in enterprise on action_close
|
||||
@@ -193,7 +199,7 @@ class TestAdvMailPerformance(TransactionCase):
|
||||
|
||||
record.write({'name': 'Dupe write'})
|
||||
|
||||
with self.assertQueryCount(__system__=28, emp=48): # test_mail only: 29 - 49
|
||||
with self.assertQueryCount(__system__=28, emp=48): # com runbot: 27 - 86 // test_mail only: 28 - 48
|
||||
record.action_close('Dupe feedback')
|
||||
|
||||
self.assertEqual(record.activity_ids, self.env['mail.activity'])
|
||||
@@ -205,7 +211,7 @@ class TestAdvMailPerformance(TransactionCase):
|
||||
self.user_test.write({'notification_type': 'email'})
|
||||
record = self.env['mail.test.track'].create({'name': 'Test'})
|
||||
|
||||
with self.assertQueryCount(__system__=58, emp=77): # com runbot: 56 - 75 // test_mail only: 56 - 75
|
||||
with self.assertQueryCount(__system__=58, emp=77): # com runbot: 58 - 77 // test_mail only: 56 - 70
|
||||
record.write({
|
||||
'user_id': self.user_test.id,
|
||||
})
|
||||
@@ -215,7 +221,7 @@ class TestAdvMailPerformance(TransactionCase):
|
||||
def test_message_assignation_inbox(self):
|
||||
record = self.env['mail.test.track'].create({'name': 'Test'})
|
||||
|
||||
with self.assertQueryCount(__system__=36, emp=47): # test_mail only: 43 - 54
|
||||
with self.assertQueryCount(__system__=36, emp=47): # test_mail only: 36 - 43
|
||||
record.write({
|
||||
'user_id': self.user_test.id,
|
||||
})
|
||||
@@ -259,7 +265,7 @@ class TestAdvMailPerformance(TransactionCase):
|
||||
def test_message_post_one_email_notification(self):
|
||||
record = self.env['mail.test.simple'].create({'name': 'Test'})
|
||||
|
||||
with self.assertQueryCount(__system__=50, emp=70): # com runbot: 45 - 65 // test_mail only: 48 - 68
|
||||
with self.assertQueryCount(__system__=50, emp=70): # com runbot: 47 - 67 // test_mail only: 50 - 67
|
||||
record.message_post(
|
||||
body='<p>Test Post Performances with an email ping</p>',
|
||||
partner_ids=self.customer.ids,
|
||||
@@ -284,10 +290,10 @@ class TestAdvMailPerformance(TransactionCase):
|
||||
def test_message_subscribe_default(self):
|
||||
record = self.env['mail.test.simple'].create({'name': 'Test'})
|
||||
|
||||
with self.assertQueryCount(__system__=7, emp=7): # test_mail only: 6 - 6
|
||||
with self.assertQueryCount(__system__=7, emp=7): # test_mail only: 7 - 7
|
||||
record.message_subscribe(partner_ids=self.user_test.partner_id.ids)
|
||||
|
||||
with self.assertQueryCount(__system__=3, emp=3): # test_mail only: 2 - 2
|
||||
with self.assertQueryCount(__system__=3, emp=3): # test_mail only: 3 - 3
|
||||
record.message_subscribe(partner_ids=self.user_test.partner_id.ids)
|
||||
|
||||
@mute_logger('odoo.models.unlink')
|
||||
@@ -297,10 +303,10 @@ class TestAdvMailPerformance(TransactionCase):
|
||||
record = self.env['mail.test.simple'].create({'name': 'Test'})
|
||||
subtype_ids = (self.env.ref('test_mail.st_mail_test_simple_external') | self.env.ref('mail.mt_comment')).ids
|
||||
|
||||
with self.assertQueryCount(__system__=6, emp=6): # test_mail only: 5 - 5
|
||||
with self.assertQueryCount(__system__=6, emp=6): # test_mail only: 6 - 6
|
||||
record.message_subscribe(partner_ids=self.user_test.partner_id.ids, subtype_ids=subtype_ids)
|
||||
|
||||
with self.assertQueryCount(__system__=2, emp=2): # test_mail only: 1 - 1
|
||||
with self.assertQueryCount(__system__=2, emp=2): # test_mail only: 2 - 2
|
||||
record.message_subscribe(partner_ids=self.user_test.partner_id.ids, subtype_ids=subtype_ids)
|
||||
|
||||
|
||||
@@ -382,7 +388,7 @@ class TestHeavyMailPerformance(TransactionCase):
|
||||
})
|
||||
mail_ids = mail.ids
|
||||
|
||||
with self.assertQueryCount(__system__=14, emp=21): # test_mail only: 13 - 20
|
||||
with self.assertQueryCount(__system__=14, emp=21): # test_mail only: 14 - 21
|
||||
self.env['mail.mail'].browse(mail_ids).send()
|
||||
|
||||
self.assertEqual(mail.body_html, '<p>Test</p>')
|
||||
@@ -395,7 +401,7 @@ class TestHeavyMailPerformance(TransactionCase):
|
||||
self.umbrella.message_subscribe(self.user_portal.partner_id.ids)
|
||||
record = self.umbrella.sudo(self.env.user)
|
||||
|
||||
with self.assertQueryCount(__system__=84, emp=107): # com runbot 90 - 113 // test_mail only: 97 - 120
|
||||
with self.assertQueryCount(__system__=84, emp=107): # com runbot 81 - 104 // test_mail only: 84 - 104
|
||||
record.message_post(
|
||||
body='<p>Test Post Performances</p>',
|
||||
message_type='comment',
|
||||
@@ -412,7 +418,7 @@ class TestHeavyMailPerformance(TransactionCase):
|
||||
record = self.umbrella.sudo(self.env.user)
|
||||
template_id = self.env.ref('test_mail.mail_test_tpl').id
|
||||
|
||||
with self.assertQueryCount(__system__=103, emp=138): # com runbot 109 - 144 // test_mail only: 116 - 151
|
||||
with self.assertQueryCount(__system__=103, emp=138): # com runbot 100 - 135 // test_mail only: 103 - 135
|
||||
record.message_post_with_template(template_id, message_type='comment', composition_mode='comment')
|
||||
|
||||
self.assertEqual(record.message_ids[0].body, '<p>Adding stuff on %s</p>' % record.name)
|
||||
@@ -437,7 +443,7 @@ class TestHeavyMailPerformance(TransactionCase):
|
||||
self.assertEqual(rec.message_channel_ids, self.env['mail.channel'])
|
||||
|
||||
# subscribe new followers with forced given subtypes
|
||||
with self.assertQueryCount(__system__=9, emp=9): # test_mail only: 8 - 8
|
||||
with self.assertQueryCount(__system__=9, emp=9): # test_mail only: 9 - 9
|
||||
rec.message_subscribe(
|
||||
partner_ids=pids[:4],
|
||||
channel_ids=cids,
|
||||
@@ -448,7 +454,7 @@ class TestHeavyMailPerformance(TransactionCase):
|
||||
self.assertEqual(rec.message_channel_ids, self.channel)
|
||||
|
||||
# subscribe existing and new followers with force=False, meaning only some new followers will be added
|
||||
with self.assertQueryCount(__system__=7, emp=7): # test_mail only: 6 - 6
|
||||
with self.assertQueryCount(__system__=7, emp=7): # test_mail only: 7 - 7
|
||||
rec.message_subscribe(
|
||||
partner_ids=pids[:6],
|
||||
channel_ids=cids,
|
||||
@@ -459,7 +465,7 @@ class TestHeavyMailPerformance(TransactionCase):
|
||||
self.assertEqual(rec.message_channel_ids, self.channel)
|
||||
|
||||
# subscribe existing and new followers with force=True, meaning all will have the same subtypes
|
||||
with self.assertQueryCount(__system__=8, emp=8): # test_mail only: 7 - 7
|
||||
with self.assertQueryCount(__system__=8, emp=8): # test_mail only: 8 - 8
|
||||
rec.message_subscribe(
|
||||
partner_ids=pids,
|
||||
channel_ids=cids,
|
||||
@@ -482,7 +488,7 @@ class TestHeavyMailPerformance(TransactionCase):
|
||||
})
|
||||
self.assertEqual(rec.message_partner_ids, self.partners | self.env.user.partner_id)
|
||||
|
||||
with self.assertQueryCount(__system__=60, emp=79): # com runbot: 65 - 83 // test_mail only: 66 - 84
|
||||
with self.assertQueryCount(__system__=60, emp=79): # com runbot: 60 - 75 // test_mail only: 60 - 72
|
||||
rec.write({'user_id': self.user_portal.id})
|
||||
|
||||
self.assertEqual(rec.message_partner_ids, self.partners | self.env.user.partner_id | self.user_portal.partner_id)
|
||||
@@ -505,7 +511,7 @@ class TestHeavyMailPerformance(TransactionCase):
|
||||
customer_id = self.customer.id
|
||||
user_id = self.user_portal.id
|
||||
|
||||
with self.assertQueryCount(__system__=162, emp=198): # com runbot: 156 - 190 // test_mail only: 156 - 190
|
||||
with self.assertQueryCount(__system__=162, emp=198): # com runbot: 161 - 198 // test_mail only: 161 - 191
|
||||
rec = self.env['mail.test.full'].create({
|
||||
'name': 'Test',
|
||||
'umbrella_id': umbrella_id,
|
||||
@@ -534,7 +540,7 @@ class TestHeavyMailPerformance(TransactionCase):
|
||||
})
|
||||
self.assertEqual(rec.message_partner_ids, self.user_portal.partner_id | self.env.user.partner_id)
|
||||
|
||||
with self.assertQueryCount(__system__=99, emp=119): # com runbot: 104 - 123 // test_mail only: 105 - 124
|
||||
with self.assertQueryCount(__system__=99, emp=119): # com runbot: 98 - 119 // test_mail only: 98 - 116
|
||||
rec.write({
|
||||
'name': 'Test2',
|
||||
'umbrella_id': self.umbrella.id,
|
||||
@@ -572,7 +578,7 @@ class TestHeavyMailPerformance(TransactionCase):
|
||||
})
|
||||
self.assertEqual(rec.message_partner_ids, self.user_portal.partner_id | self.env.user.partner_id)
|
||||
|
||||
with self.assertQueryCount(__system__=104, emp=126): # test_mail only: 111 - 134
|
||||
with self.assertQueryCount(__system__=104, emp=126): # test_mail only: 104 - 122
|
||||
rec.write({
|
||||
'name': 'Test2',
|
||||
'umbrella_id': umbrella_id,
|
||||
@@ -606,7 +612,7 @@ class TestHeavyMailPerformance(TransactionCase):
|
||||
})
|
||||
self.assertEqual(rec.message_partner_ids, self.partners | self.env.user.partner_id | self.user_portal.partner_id)
|
||||
|
||||
with self.assertQueryCount(__system__=55, emp=77): # test_mail only: 54 - 75
|
||||
with self.assertQueryCount(__system__=55, emp=75): # test_mail only: 55 - 75
|
||||
rec.write({
|
||||
'name': 'Test2',
|
||||
'customer_id': customer_id,
|
||||
|
||||
Reference in New Issue
Block a user