[FIX] test_mail_*: fix query counters tests and runbot builds
Ensure everything is flushed before running tests. Update counters. Check no-demo mode. Task-3871642 Runbot-55365 Runbot-55366 Runbot-55367 closes odoo/odoo#162022 Related: odoo/enterprise#60844 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
@@ -1259,6 +1259,7 @@ class MailCommon(common.TransactionCase, MailCase):
|
||||
cls.partner_admin = cls.env.ref('base.partner_admin')
|
||||
cls.company_admin = cls.user_admin.company_id
|
||||
cls.company_admin.write({
|
||||
'country_id': cls.env.ref("base.be").id,
|
||||
'email': 'your.company@example.com', # ensure email for various fallbacks
|
||||
'name': 'YourTestCompany', # force for reply_to computation
|
||||
})
|
||||
|
||||
@@ -231,7 +231,14 @@ class SMSCase(MockSMS):
|
||||
number = partner._phone_format()
|
||||
|
||||
notif = notifications.filtered(lambda n: n.res_partner_id == partner and n.sms_number == number and n.notification_status == state)
|
||||
self.assertTrue(notif, 'SMS: not found notification for %s (number: %s, state: %s)' % (partner, number, state))
|
||||
|
||||
debug_info = ''
|
||||
if not notif:
|
||||
debug_info = '\n'.join(
|
||||
f'To: {notif.sms_number} ({notif.res_partner_id}) - (State: {notif.notification_status})'
|
||||
for notif in notifications
|
||||
)
|
||||
self.assertTrue(notif, 'SMS: not found notification for %s (number: %s, state: %s)\n%s' % (partner, number, state, debug_info))
|
||||
self.assertEqual(notif.author_id, notif.mail_message_id.author_id, 'SMS: Message and notification should have the same author')
|
||||
|
||||
if state not in {'process', 'sent', 'ready', 'canceled', 'pending'}:
|
||||
|
||||
@@ -112,46 +112,47 @@ class BaseMailPerformance(MailCommon, TransactionCaseWithUserDemo):
|
||||
@tagged('mail_performance', 'post_install', '-at_install')
|
||||
class TestBaseMailPerformance(BaseMailPerformance):
|
||||
|
||||
def setUp(self):
|
||||
super(TestBaseMailPerformance, self).setUp()
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
|
||||
self.res_partner_3 = self.env['res.partner'].create({
|
||||
cls.res_partner_3 = cls.env['res.partner'].create({
|
||||
'name': 'Gemini Furniture',
|
||||
'email': 'gemini.furniture39@example.com',
|
||||
})
|
||||
self.res_partner_4 = self.env['res.partner'].create({
|
||||
cls.res_partner_4 = cls.env['res.partner'].create({
|
||||
'name': 'Ready Mat',
|
||||
'email': 'ready.mat28@example.com',
|
||||
})
|
||||
self.res_partner_10 = self.env['res.partner'].create({
|
||||
cls.res_partner_10 = cls.env['res.partner'].create({
|
||||
'name': 'The Jackson Group',
|
||||
'email': 'jackson.group82@example.com',
|
||||
})
|
||||
self.res_partner_12 = self.env['res.partner'].create({
|
||||
cls.res_partner_12 = cls.env['res.partner'].create({
|
||||
'name': 'Azure Interior',
|
||||
'email': 'azure.Interior24@example.com',
|
||||
})
|
||||
self.env['mail.performance.thread'].create([
|
||||
cls.env['mail.performance.thread'].create([
|
||||
{
|
||||
'name': 'Object 0',
|
||||
'value': 0,
|
||||
'partner_id': self.res_partner_3.id,
|
||||
'partner_id': cls.res_partner_3.id,
|
||||
}, {
|
||||
'name': 'Object 1',
|
||||
'value': 10,
|
||||
'partner_id': self.res_partner_3.id,
|
||||
'partner_id': cls.res_partner_3.id,
|
||||
}, {
|
||||
'name': 'Object 2',
|
||||
'value': 20,
|
||||
'partner_id': self.res_partner_4.id,
|
||||
'partner_id': cls.res_partner_4.id,
|
||||
}, {
|
||||
'name': 'Object 3',
|
||||
'value': 30,
|
||||
'partner_id': self.res_partner_10.id,
|
||||
'partner_id': cls.res_partner_10.id,
|
||||
}, {
|
||||
'name': 'Object 4',
|
||||
'value': 40,
|
||||
'partner_id': self.res_partner_12.id,
|
||||
'partner_id': cls.res_partner_12.id,
|
||||
}
|
||||
])
|
||||
|
||||
@@ -253,11 +254,12 @@ class TestBaseMailPerformance(BaseMailPerformance):
|
||||
@tagged('mail_performance', 'post_install', '-at_install')
|
||||
class TestBaseAPIPerformance(BaseMailPerformance):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
|
||||
# automatically follow activities, for backward compatibility concerning query count
|
||||
self.env.ref('mail.mt_activities').write({'default': True})
|
||||
cls.env.ref('mail.mt_activities').write({'default': True})
|
||||
|
||||
@users('admin', 'employee')
|
||||
@warmup
|
||||
@@ -480,7 +482,7 @@ class TestBaseAPIPerformance(BaseMailPerformance):
|
||||
'default_template_id': test_template.id,
|
||||
}).create({})
|
||||
|
||||
with self.assertQueryCount(admin=41, employee=41): # com 36/36
|
||||
with self.assertQueryCount(admin=41, employee=41):
|
||||
composer._action_send_mail()
|
||||
|
||||
# notifications
|
||||
@@ -504,7 +506,7 @@ class TestBaseAPIPerformance(BaseMailPerformance):
|
||||
'default_template_id': test_template.id,
|
||||
}).create({})
|
||||
|
||||
with self.assertQueryCount(admin=50, employee=50): # com 43/43
|
||||
with self.assertQueryCount(admin=50, employee=50):
|
||||
composer._action_send_mail()
|
||||
|
||||
# notifications
|
||||
@@ -536,7 +538,7 @@ class TestBaseAPIPerformance(BaseMailPerformance):
|
||||
)
|
||||
composer = composer_form.save()
|
||||
|
||||
with self.assertQueryCount(admin=51, employee=51): # com 45/45
|
||||
with self.assertQueryCount(admin=51, employee=51):
|
||||
composer._action_send_mail()
|
||||
|
||||
# notifications
|
||||
@@ -1316,56 +1318,57 @@ class TestMailFormattersPerformance(BaseMailPerformance):
|
||||
@tagged('mail_performance', 'post_install', '-at_install')
|
||||
class TestPerformance(BaseMailPerformance):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
|
||||
# record
|
||||
self.record_container = self.env['mail.test.container'].with_context(mail_create_nosubscribe=True).create({
|
||||
cls.record_container = cls.env['mail.test.container'].with_context(mail_create_nosubscribe=True).create({
|
||||
'name': 'Test record',
|
||||
'customer_id': self.customer.id,
|
||||
'customer_id': cls.customer.id,
|
||||
'alias_name': 'test-alias',
|
||||
})
|
||||
# followers
|
||||
self.user_follower_email = self.env['res.users'].with_context(self._test_context).create({
|
||||
cls.user_follower_email = cls.env['res.users'].with_context(cls._test_context).create({
|
||||
'name': 'user_follower_email',
|
||||
'login': 'user_follower_email',
|
||||
'email': 'user_follower_email@example.com',
|
||||
'notification_type': 'email',
|
||||
'groups_id': [(6, 0, [self.env.ref('base.group_user').id])],
|
||||
'groups_id': [(6, 0, [cls.env.ref('base.group_user').id])],
|
||||
})
|
||||
self.user_follower_inbox = self.env['res.users'].with_context(self._test_context).create({
|
||||
cls.user_follower_inbox = cls.env['res.users'].with_context(cls._test_context).create({
|
||||
'name': 'user_follower_inbox',
|
||||
'login': 'user_follower_inbox',
|
||||
'email': 'user_follower_inbox@example.com',
|
||||
'notification_type': 'inbox',
|
||||
'groups_id': [(6, 0, [self.env.ref('base.group_user').id])],
|
||||
'groups_id': [(6, 0, [cls.env.ref('base.group_user').id])],
|
||||
})
|
||||
self.partner_follower = self.env['res.partner'].with_context(self._test_context).create({
|
||||
cls.partner_follower = cls.env['res.partner'].with_context(cls._test_context).create({
|
||||
'name': 'partner_follower',
|
||||
'email': 'partner_follower@example.com',
|
||||
})
|
||||
self.record_container.message_subscribe([
|
||||
self.partner_follower.id,
|
||||
self.user_follower_inbox.partner_id.id,
|
||||
self.user_follower_email.partner_id.id
|
||||
cls.record_container.message_subscribe([
|
||||
cls.partner_follower.id,
|
||||
cls.user_follower_inbox.partner_id.id,
|
||||
cls.user_follower_email.partner_id.id
|
||||
])
|
||||
|
||||
# partner_ids
|
||||
self.user_inbox = self.env['res.users'].with_context(self._test_context).create({
|
||||
cls.user_inbox = cls.env['res.users'].with_context(cls._test_context).create({
|
||||
'name': 'user_inbox',
|
||||
'login': 'user_inbox',
|
||||
'email': 'user_inbox@example.com',
|
||||
'notification_type': 'inbox',
|
||||
'groups_id': [(6, 0, [self.env.ref('base.group_user').id])],
|
||||
'groups_id': [(6, 0, [cls.env.ref('base.group_user').id])],
|
||||
})
|
||||
self.user_email = self.env['res.users'].with_context(self._test_context).create({
|
||||
cls.user_email = cls.env['res.users'].with_context(cls._test_context).create({
|
||||
'name': 'user_email',
|
||||
'login': 'user_email',
|
||||
'email': 'user_email@example.com',
|
||||
'notification_type': 'email',
|
||||
'groups_id': [(6, 0, [self.env.ref('base.group_user').id])],
|
||||
'groups_id': [(6, 0, [cls.env.ref('base.group_user').id])],
|
||||
})
|
||||
self.partner = self.env['res.partner'].with_context(self._test_context).create({
|
||||
cls.partner = cls.env['res.partner'].with_context(cls._test_context).create({
|
||||
'name': 'partner',
|
||||
'email': 'partner@example.com',
|
||||
})
|
||||
|
||||
@@ -91,7 +91,7 @@ class TestMailPerformance(FullBaseMailPerformance):
|
||||
record_ticket = self.env['mail.test.ticket.mc'].browse(self.record_ticket.ids)
|
||||
attachments = self.env['ir.attachment'].create(self.test_attachments_vals)
|
||||
|
||||
with self.assertQueryCount(employee=99): # test_mail_full: 95
|
||||
with self.assertQueryCount(employee=99): # test_mail_full: 98
|
||||
new_message = record_ticket.message_post(
|
||||
attachment_ids=attachments.ids,
|
||||
body=Markup('<p>Test Content</p>'),
|
||||
|
||||
@@ -11,6 +11,7 @@ from odoo.tools import mute_logger
|
||||
|
||||
|
||||
class TestRatingCommon(TestMailFullCommon, TestSMSRecipients):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestRatingCommon, cls).setUpClass()
|
||||
@@ -147,6 +148,7 @@ class TestRatingMixin(TestRatingCommon):
|
||||
|
||||
@tagged('rating', 'mail_performance', 'post_install', '-at_install')
|
||||
class TestRatingPerformance(TestRatingCommon):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
@@ -172,25 +174,25 @@ class TestRatingPerformance(TestRatingCommon):
|
||||
@users('employee')
|
||||
@warmup
|
||||
def test_rating_last_value_perfs(self):
|
||||
with self.assertQueryCount(employee=1617): # tmf 1313 / com 1313
|
||||
with self.assertQueryCount(employee=1617): # tmf 1612 / com 1313
|
||||
self.create_ratings('mail.test.rating.thread')
|
||||
|
||||
with self.assertQueryCount(employee=2101): # tmf 1901
|
||||
with self.assertQueryCount(employee=2101):
|
||||
self.apply_ratings(1)
|
||||
|
||||
with self.assertQueryCount(employee=1900): # tmf 1800
|
||||
with self.assertQueryCount(employee=1900):
|
||||
self.apply_ratings(5)
|
||||
|
||||
@users('employee')
|
||||
@warmup
|
||||
def test_rating_last_value_perfs_with_rating_mixin(self):
|
||||
with self.assertQueryCount(employee=1724): # tmf 1419 / com 1419
|
||||
with self.assertQueryCount(employee=1724): # tmf 1715 / com 1419
|
||||
self.create_ratings('mail.test.rating')
|
||||
|
||||
with self.assertQueryCount(employee=2304): # tmf 2104
|
||||
with self.assertQueryCount(employee=2304):
|
||||
self.apply_ratings(1)
|
||||
|
||||
with self.assertQueryCount(employee=2203): # tmf 2103
|
||||
with self.assertQueryCount(employee=2203):
|
||||
self.apply_ratings(5)
|
||||
|
||||
with self.assertQueryCount(employee=1):
|
||||
|
||||
@@ -11,21 +11,22 @@ from odoo.tools import mute_logger
|
||||
@tagged('mail_performance', 'post_install', '-at_install')
|
||||
class TestSMSPerformance(BaseMailPerformance, sms_common.SMSCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestSMSPerformance, self).setUp()
|
||||
self.env.company.country_id = self.env.ref('base.us')
|
||||
self.test_record = self.env['mail.test.sms'].with_context(self._test_context).create({
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.test_record = cls.env['mail.test.sms'].with_context(cls._test_context).create({
|
||||
'name': 'Test',
|
||||
'customer_id': self.customer.id,
|
||||
'customer_id': cls.customer.id,
|
||||
'phone_nbr': '0456999999',
|
||||
})
|
||||
|
||||
# prepare recipients to test for more realistic workload
|
||||
self.partners = self.env['res.partner'].with_context(self._test_context).create([
|
||||
{'name': 'Test %s' % x,
|
||||
'email': 'test%s@example.com' % x,
|
||||
'mobile': '0456%s%s0000' % (x, x),
|
||||
'country_id': self.env.ref('base.be').id,
|
||||
cls.partners = cls.env['res.partner'].with_context(cls._test_context).create([
|
||||
{
|
||||
'country_id': cls.env.ref('base.be').id,
|
||||
'email': 'test%s@example.com' % x,
|
||||
'mobile': '0456%s%s0000' % (x, x),
|
||||
'name': 'Test %s' % x,
|
||||
} for x in range(0, 10)
|
||||
])
|
||||
|
||||
@@ -35,7 +36,7 @@ class TestSMSPerformance(BaseMailPerformance, sms_common.SMSCase):
|
||||
def test_message_sms_record_1_partner(self):
|
||||
record = self.test_record.with_user(self.env.user)
|
||||
pids = self.customer.ids
|
||||
with self.subTest("QueryCount"), self.mockSMSGateway(sms_allow_unlink=True), self.assertQueryCount(employee=31):
|
||||
with self.subTest("QueryCount"), self.mockSMSGateway(sms_allow_unlink=True), self.assertQueryCount(employee=24): # tms: 24
|
||||
messages = record._message_sms(
|
||||
body='Performance Test',
|
||||
partner_ids=pids,
|
||||
@@ -50,7 +51,7 @@ class TestSMSPerformance(BaseMailPerformance, sms_common.SMSCase):
|
||||
def test_message_sms_record_10_partners(self):
|
||||
record = self.test_record.with_user(self.env.user)
|
||||
pids = self.partners.ids
|
||||
with self.subTest("QueryCount"), self.mockSMSGateway(sms_allow_unlink=True), self.assertQueryCount(employee=31):
|
||||
with self.subTest("QueryCount"), self.mockSMSGateway(sms_allow_unlink=True), self.assertQueryCount(employee=24): # tms: 24
|
||||
messages = record._message_sms(
|
||||
body='Performance Test',
|
||||
partner_ids=pids,
|
||||
@@ -64,43 +65,44 @@ class TestSMSPerformance(BaseMailPerformance, sms_common.SMSCase):
|
||||
@warmup
|
||||
def test_message_sms_record_default(self):
|
||||
record = self.test_record.with_user(self.env.user)
|
||||
with self.subTest("QueryCount"), self.mockSMSGateway(sms_allow_unlink=True), self.assertQueryCount(employee=32):
|
||||
with self.subTest("QueryCount"), self.mockSMSGateway(sms_allow_unlink=True), self.assertQueryCount(employee=25): # tms: 25
|
||||
messages = record._message_sms(
|
||||
body='Performance Test',
|
||||
)
|
||||
|
||||
self.assertEqual(record.message_ids[0].body, '<p>Performance Test</p>')
|
||||
self.assertSMSNotification([{'partner': self.customer}], 'Performance Test', messages, sent_unlink=True)
|
||||
self.assertSMSNotification([{'number': '+32456999999', 'partner': self.customer}], 'Performance Test', messages, sent_unlink=True)
|
||||
|
||||
|
||||
@tagged('mail_performance', 'post_install', '-at_install')
|
||||
class TestSMSMassPerformance(BaseMailPerformance, sms_common.MockSMS):
|
||||
|
||||
def setUp(self):
|
||||
super(TestSMSMassPerformance, self).setUp()
|
||||
be_country_id = self.env.ref('base.be').id
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
be_country_id = cls.env.ref('base.be').id
|
||||
|
||||
self._test_body = 'MASS SMS'
|
||||
cls._test_body = 'MASS SMS'
|
||||
|
||||
records = self.env['mail.test.sms']
|
||||
partners = self.env['res.partner']
|
||||
records = cls.env['mail.test.sms']
|
||||
partners = cls.env['res.partner']
|
||||
for x in range(50):
|
||||
partners += self.env['res.partner'].with_context(**self._test_context).create({
|
||||
partners += cls.env['res.partner'].with_context(**cls._test_context).create({
|
||||
'name': 'Partner_%s' % (x),
|
||||
'email': '_test_partner_%s@example.com' % (x),
|
||||
'country_id': be_country_id,
|
||||
'mobile': '047500%02d%02d' % (x, x)
|
||||
})
|
||||
records += self.env['mail.test.sms'].with_context(**self._test_context).create({
|
||||
records += cls.env['mail.test.sms'].with_context(**cls._test_context).create({
|
||||
'name': 'Test_%s' % (x),
|
||||
'customer_id': partners[x].id,
|
||||
})
|
||||
self.partners = partners
|
||||
self.records = records
|
||||
cls.partners = partners
|
||||
cls.records = records
|
||||
|
||||
self.sms_template = self.env['sms.template'].create({
|
||||
cls.sms_template = cls.env['sms.template'].create({
|
||||
'name': 'Test Template',
|
||||
'model_id': self.env['ir.model']._get('mail.test.sms').id,
|
||||
'model_id': cls.env['ir.model']._get('mail.test.sms').id,
|
||||
'body': 'Dear {{ object.display_name }} this is an SMS.',
|
||||
})
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ class TestMassMailPerformance(TestMassMailPerformanceBase):
|
||||
})
|
||||
|
||||
# runbot needs +51 compared to local
|
||||
with self.assertQueryCount(__system__=1622, marketing=1623):
|
||||
with self.assertQueryCount(__system__=1622, marketing=1623): # 1522, 1523
|
||||
mailing.action_send_mail()
|
||||
|
||||
self.assertEqual(mailing.sent, 50)
|
||||
@@ -90,7 +90,7 @@ class TestMassMailBlPerformance(TestMassMailPerformanceBase):
|
||||
})
|
||||
|
||||
# runbot needs +51 compared to local
|
||||
with self.assertQueryCount(__system__=1694, marketing=1695):
|
||||
with self.assertQueryCount(__system__=1694, marketing=1695): # 1594, 1595
|
||||
mailing.action_send_mail()
|
||||
|
||||
self.assertEqual(mailing.sent, 50)
|
||||
|
||||
Reference in New Issue
Block a user