[MERGE][FIX] test(_mass)_mail: simulate email sending in performance tests
Commit 356a421 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.
Performance counters are updated to match current runbot state for both
community and enterprise.
Mass mailing performance class is made a direc child of TransactionCase
to ease manipulation and be able to use patch.
This merge is related to task ID 1902307 and is mainly a fix and better use
of https://github.com/odoo-dev/odoo/commit/356a42166082f9448b7e82393caeb00839be8c8f.
closes odoo/odoo#28027
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,
|
||||
|
||||
@@ -1,14 +1,33 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.addons.test_mass_mailing.tests import common
|
||||
from odoo.tests.common import users, warmup
|
||||
from odoo.addons.test_mail.tests.common import mail_new_test_user
|
||||
from odoo.tests.common import TransactionCase, users, warmup
|
||||
from odoo.tests import tagged
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
|
||||
class TestMassMailPerformanceBase(TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestMassMailPerformanceBase, self).setUp()
|
||||
|
||||
self.user_employee = mail_new_test_user(
|
||||
self.env, login='emp',
|
||||
groups='base.group_user',
|
||||
name='Ernest Employee', notification_type='inbox')
|
||||
|
||||
self.user_marketing = mail_new_test_user(
|
||||
self.env, login='marketing',
|
||||
groups='base.group_user,mass_mailing.group_mass_mailing_user',
|
||||
name='Martial Marketing', signature='--\nMartial')
|
||||
|
||||
# patch registry to simulate a ready environment
|
||||
self.patch(self.env.registry, 'ready', True)
|
||||
|
||||
|
||||
@tagged('mail_performance')
|
||||
class TestMassMailPerformance(common.MassMailingCase):
|
||||
class TestMassMailPerformance(TestMassMailPerformanceBase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestMassMailPerformance, self).setUp()
|
||||
@@ -20,7 +39,7 @@ class TestMassMailPerformance(common.MassMailingCase):
|
||||
|
||||
@users('__system__', 'marketing')
|
||||
@warmup
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail', 'odoo.models.unlink')
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail', 'odoo.models.unlink', 'odoo.tests')
|
||||
def test_send_mailing(self):
|
||||
mailing = self.env['mail.mass_mailing'].create({
|
||||
'name': 'Test',
|
||||
@@ -38,7 +57,7 @@ class TestMassMailPerformance(common.MassMailingCase):
|
||||
|
||||
|
||||
@tagged('mail_performance')
|
||||
class TestMassMailBlPerformance(common.MassMailingCase):
|
||||
class TestMassMailBlPerformance(TestMassMailPerformanceBase):
|
||||
|
||||
def setUp(self):
|
||||
""" In this setup we prepare 20 blacklist entries. We therefore add
|
||||
@@ -57,7 +76,7 @@ class TestMassMailBlPerformance(common.MassMailingCase):
|
||||
|
||||
@users('__system__', 'marketing')
|
||||
@warmup
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail', 'odoo.models.unlink')
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail', 'odoo.models.unlink', 'odoo.tests')
|
||||
def test_send_mailing_w_bl(self):
|
||||
mailing = self.env['mail.mass_mailing'].create({
|
||||
'name': 'Test',
|
||||
|
||||
Reference in New Issue
Block a user