diff --git a/addons/test_mail/data/subtype_demo.xml b/addons/test_mail/data/subtype_demo.xml index 20a486aace8..2645f3d1186 100644 --- a/addons/test_mail/data/subtype_demo.xml +++ b/addons/test_mail/data/subtype_demo.xml @@ -1,6 +1,14 @@ + + External subtype + External subtype + mail.test.simple + + + + Umbrella Changed Subtype Umbrella Changed diff --git a/addons/test_mail/tests/test_performance.py b/addons/test_mail/tests/test_performance.py index a544b447422..983686be809 100644 --- a/addons/test_mail/tests/test_performance.py +++ b/addons/test_mail/tests/test_performance.py @@ -131,6 +131,17 @@ class TestAdvMailPerformance(TransactionCase): 'notification_type': 'inbox', 'groups_id': [(6, 0, [self.env.ref('base.group_user').id])], }) + self.customer = self.env['res.partner'].with_context(self._quick_create_ctx).create({ + 'name': 'Test Customer', + 'email': 'test@example.com', + }) + self.user_test = self.env['res.users'].with_context(self._quick_create_ctx).create({ + 'name': 'Paulette Testouille', + 'login': 'paul', + 'email': 'p.p@example.com', + 'notification_type': 'inbox', + 'groups_id': [(6, 0, [self.env.ref('base.group_user').id])], + }) @users('admin', 'emp') @warmup @@ -145,17 +156,125 @@ class TestAdvMailPerformance(TransactionCase): @mute_logger('odoo.models.unlink') def test_adv_activity_full(self): record = self.env['mail.test.activity'].create({'name': 'Test'}) - model = self.env['mail.activity'].with_context({ + MailActivity = self.env['mail.activity'].with_context({ 'default_res_model': 'mail.test.activity', }) with self.assertQueryCount(admin=47, emp=54): # com runbot 46 - 52 // test_mail only: 35 - 41 - model.create({ + activity = MailActivity.create({ 'summary': 'Test Activity', 'res_id': record.id, 'activity_type_id': self.env.ref('mail.mail_activity_data_todo').id, }) + with self.assertQueryCount(admin=84, emp=116): # com runbot 84 - 116 // test_mail only: 68 - 96 + activity.action_feedback(feedback='Zizisse Done !') + + @mute_logger('odoo.addons.mail.models.mail_mail', 'odoo.models.unlink') + @users('admin', 'emp') + @warmup + def test_message_assignation_email(self): + self.user_test.write({'notification_type': 'email'}) + record = self.env['mail.test.track'].create({'name': 'Test'}) + + with self.assertQueryCount(admin=80, emp=109): # test_mail only: 69 - 96 + record.write({ + 'user_id': self.user_test.id, + }) + + @users('admin', 'emp') + @warmup + def test_message_assignation_inbox(self): + record = self.env['mail.test.track'].create({'name': 'Test'}) + + with self.assertQueryCount(admin=22, emp=28): # test_mail only: 20 - 26 + record.write({ + 'user_id': self.user_test.id, + }) + + @users('admin', 'emp') + @warmup + def test_message_log(self): + record = self.env['mail.test.simple'].create({'name': 'Test'}) + + with self.assertQueryCount(admin=5, emp=5): # test_mail only: 3 - 3 + record._message_log( + body='

Test _message_log

', + message_type='comment') + + @users('admin', 'emp') + @warmup + def test_message_log_with_post(self): + record = self.env['mail.test.simple'].create({'name': 'Test'}) + + with self.assertQueryCount(admin=31, emp=43): # test_mail only: 29 - 40 + record.message_post( + body='

Test message_post as log

', + subtype='mail.mt_note', + message_type='comment') + + @users('admin', 'emp') + @warmup + def test_message_post_no_notification(self): + record = self.env['mail.test.simple'].create({'name': 'Test'}) + + with self.assertQueryCount(admin=31, emp=43): # test_mail only: 29 - 40 + record.message_post( + body='

Test Post Performances basic

', + partner_ids=[], + message_type='comment', + subtype='mail.mt_comment') + + @mute_logger('odoo.addons.mail.models.mail_mail', 'odoo.models.unlink') + @users('admin', 'emp') + @warmup + def test_message_post_one_email_notification(self): + record = self.env['mail.test.simple'].create({'name': 'Test'}) + + with self.assertQueryCount(admin=85, emp=115): # com runbot 83 - 112 // test_mail only: 81 - 110 + record.message_post( + body='

Test Post Performances with an email ping

', + partner_ids=self.customer.ids, + message_type='comment', + subtype='mail.mt_comment') + + @users('admin', 'emp') + @warmup + def test_message_post_one_inbox_notification(self): + record = self.env['mail.test.simple'].create({'name': 'Test'}) + + with self.assertQueryCount(admin=44, emp=58): # com runbot 42 - 55 // test_mail only: 42 - 55 + record.message_post( + body='

Test Post Performances with an inbox ping

', + partner_ids=self.user_test.partner_id.ids, + message_type='comment', + subtype='mail.mt_comment') + + @mute_logger('odoo.models.unlink') + @users('admin', 'emp') + @warmup + def test_message_subscribe_default(self): + record = self.env['mail.test.simple'].create({'name': 'Test'}) + + with self.assertQueryCount(admin=7, emp=8): # test_mail only: 7 - 8 + record.message_subscribe(partner_ids=self.user_test.partner_id.ids) + + with self.assertQueryCount(admin=19, emp=19): # test_mail only: 19 - 19 + record.message_subscribe(partner_ids=self.user_test.partner_id.ids) + + @mute_logger('odoo.models.unlink') + @users('admin', 'emp') + @warmup + def test_message_subscribe_subtypes(self): + 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(admin=7, emp=8): # test_mail only: 7 - 8 + record.message_subscribe(partner_ids=self.user_test.partner_id.ids, subtype_ids=subtype_ids) + + with self.assertQueryCount(admin=19, emp=19): # test_mail only: 18 - 18 + record.message_subscribe(partner_ids=self.user_test.partner_id.ids, subtype_ids=subtype_ids) + class TestHeavyMailPerformance(TransactionCase): @@ -326,9 +445,35 @@ class TestHeavyMailPerformance(TransactionCase): @mute_logger('odoo.tests', 'odoo.addons.mail.models.mail_mail', 'odoo.models.unlink') @users('admin', 'emp') @warmup - def test_complex_create_tracking_subscription(self): - """ Create record using most features: auto subscription, tracking - and templates. """ + def test_complex_tracking_assignation(self): + """ Assignation performance test on already-created record """ + rec = self.env['mail.test.full'].create({ + 'name': 'Test', + 'umbrella_id': self.umbrella.id, + 'customer_id': self.customer.id, + 'user_id': self.env.uid, + }) + self.assertEqual(rec.message_partner_ids, self.partners | self.env.user.partner_id) + + with self.assertQueryCount(admin=87, emp=117): # test_mail only: 76 - 104 + 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) + # write tracking message + self.assertEqual(rec.message_ids[0].subtype_id, self.env.ref('mail.mt_note')) + self.assertEqual(rec.message_ids[0].needaction_partner_ids, self.env['res.partner']) + # create tracking message + self.assertEqual(rec.message_ids[1].subtype_id, self.env.ref('test_mail.st_mail_test_full_umbrella_upd')) + self.assertEqual(rec.message_ids[1].needaction_partner_ids, self.partners) + # creation message + self.assertEqual(rec.message_ids[2].subtype_id, self.env.ref('mail.mt_note')) + self.assertEqual(rec.message_ids[2].needaction_partner_ids, self.env['res.partner']) + + @mute_logger('odoo.tests', 'odoo.addons.mail.models.mail_mail', 'odoo.models.unlink') + @users('admin', 'emp') + @warmup + def test_complex_tracking_subscription_create(self): + """ Creation performance test involving auto subscription, assignation, tracking with subtype and template send. """ umbrella_id = self.umbrella.id customer_id = self.customer.id user_id = self.user_portal.id @@ -342,7 +487,7 @@ class TestHeavyMailPerformance(TransactionCase): }) self.assertEqual(rec.message_partner_ids, self.partners | self.env.user.partner_id | self.user_portal.partner_id) - # tracking message + # create tracking message self.assertEqual(rec.message_ids[0].subtype_id, self.env.ref('test_mail.st_mail_test_full_umbrella_upd')) self.assertEqual(rec.message_ids[0].needaction_partner_ids, self.partners | self.user_portal.partner_id) # creation message @@ -352,12 +497,40 @@ class TestHeavyMailPerformance(TransactionCase): @mute_logger('odoo.tests', 'odoo.addons.mail.models.mail_mail', 'odoo.models.unlink') @users('admin', 'emp') @warmup - def test_complex_write_tracking_subscription(self): - """ Create record using most features: auto subscription, tracking - and templates. """ + def test_complex_tracking_subscription_subtype(self): + """ Write performance test involving auto subscription, tracking with subtype """ + rec = self.env['mail.test.full'].create({ + 'name': 'Test', + 'umbrella_id': False, + 'customer_id': False, + 'user_id': self.user_portal.id, + }) + self.assertEqual(rec.message_partner_ids, self.user_portal.partner_id | self.env.user.partner_id) + + with self.assertQueryCount(admin=236, emp=275): # test_mail only: 230 - 268 + rec.write({ + 'name': 'Test2', + 'umbrella_id': self.umbrella.id, + }) + + self.assertEqual(rec.message_partner_ids, self.partners | self.env.user.partner_id | self.user_portal.partner_id) + # write tracking message + self.assertEqual(rec.message_ids[0].subtype_id, self.env.ref('test_mail.st_mail_test_full_umbrella_upd')) + self.assertEqual(rec.message_ids[0].needaction_partner_ids, self.partners | self.user_portal.partner_id) + # create tracking message + self.assertEqual(rec.message_ids[1].subtype_id, self.env.ref('mail.mt_note')) + self.assertEqual(rec.message_ids[1].needaction_partner_ids, self.env['res.partner']) + # creation message + self.assertEqual(rec.message_ids[2].subtype_id, self.env.ref('mail.mt_note')) + self.assertEqual(rec.message_ids[2].needaction_partner_ids, self.env['res.partner']) + + @mute_logger('odoo.tests', 'odoo.addons.mail.models.mail_mail', 'odoo.models.unlink') + @users('admin', 'emp') + @warmup + def test_complex_tracking_subscription_write(self): + """ Write performance test involving auto subscription, tracking with subtype and template send """ umbrella_id = self.umbrella.id customer_id = self.customer.id - user_id = self.user_portal.id umbrella2 = self.env['mail.test'].with_context(mail_create_nosubscribe=True).create({ 'name': 'Test Umbrella 2', 'customer_id': False, @@ -368,7 +541,7 @@ class TestHeavyMailPerformance(TransactionCase): 'name': 'Test', 'umbrella_id': umbrella2.id, 'customer_id': False, - 'user_id': user_id, + 'user_id': self.user_portal.id, }) self.assertEqual(rec.message_partner_ids, self.user_portal.partner_id | self.env.user.partner_id) @@ -389,3 +562,39 @@ class TestHeavyMailPerformance(TransactionCase): # creation message self.assertEqual(rec.message_ids[2].subtype_id, self.env.ref('mail.mt_note')) self.assertEqual(rec.message_ids[2].needaction_partner_ids, self.env['res.partner']) + + @mute_logger('odoo.tests', 'odoo.addons.mail.models.mail_mail', 'odoo.models.unlink') + @users('admin', 'emp') + @warmup + def test_complex_tracking_template(self): + """ Write performance test involving assignation, tracking with template """ + customer_id = self.customer.id + + rec = self.env['mail.test.full'].create({ + 'name': 'Test', + 'umbrella_id': self.umbrella.id, + 'customer_id': False, + 'user_id': self.user_portal.id, + 'mail_template': self.env.ref('test_mail.mail_test_full_tracking_tpl').id, + }) + self.assertEqual(rec.message_partner_ids, self.partners | self.env.user.partner_id | self.user_portal.partner_id) + + with self.assertQueryCount(admin=72, emp=101): # test_mail only: 64 - 91 + rec.write({ + 'name': 'Test2', + 'customer_id': customer_id, + 'user_id': self.env.uid, + }) + + # write template message (sent to customer, mass mailing kept for history) + self.assertEqual(rec.message_ids[0].subtype_id, self.env['mail.message.subtype']) + self.assertEqual(rec.message_ids[0].subject, 'Test Template') + # write tracking message + self.assertEqual(rec.message_ids[1].subtype_id, self.env.ref('mail.mt_note')) + self.assertEqual(rec.message_ids[1].needaction_partner_ids, self.env['res.partner']) + # create tracking message + self.assertEqual(rec.message_ids[2].subtype_id, self.env.ref('test_mail.st_mail_test_full_umbrella_upd')) + self.assertEqual(rec.message_ids[2].needaction_partner_ids, self.partners | self.user_portal.partner_id) + # creation message + self.assertEqual(rec.message_ids[3].subtype_id, self.env.ref('mail.mt_note')) + self.assertEqual(rec.message_ids[3].needaction_partner_ids, self.env['res.partner'])