diff options
| author | Thibault Delavallée <tde@odoo.com> | 2018-01-04 12:47:24 +0100 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2018-01-08 17:04:57 +0100 |
| commit | 5c3e0391acda99c50bf1db4f46022726bfc739ac (patch) | |
| tree | 6a7431193a02d4301aeace976b0e9013c2353ff6 | |
| parent | 314353bf439b3836e95ea86d042459dbf6e02d21 (diff) | |
[IMP] test_mail: correctly set aliases when performing tests
In order to really test a production environment we have to ensure
some mail related config parameters are set. This has an impact on
some tests.
Which is strange is that it lessens query number of a test that
already uses those parameters. Maybe XMas spirit.
| -rw-r--r-- | addons/test_mail/tests/test_performance.py | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/addons/test_mail/tests/test_performance.py b/addons/test_mail/tests/test_performance.py index 75f40746f41..883b36b02e5 100644 --- a/addons/test_mail/tests/test_performance.py +++ b/addons/test_mail/tests/test_performance.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from email.utils import formataddr + from odoo.tests.common import TransactionCase, users, warmup from odoo.tools import mute_logger @@ -96,8 +98,7 @@ class TestMailPerformance(TransactionCase): @users('admin', 'emp') @warmup - def test_simple(self): - """ Create records inheriting from 'mail.thread' (simple models) """ + def test_create_mail_simple(self): with self.assertQueryCount(admin=32, emp=42): # test_mail only: 30 - 39 self.env['mail.test.simple'].create({'name': 'Test'}) @@ -123,7 +124,7 @@ class TestAdvMailPerformance(TransactionCase): @users('admin', 'emp') @warmup - def test_activity(self): + def test_adv_activity(self): model = self.env['mail.test.activity'] with self.assertQueryCount(admin=35, emp=45): # test_mail only: 33 - 42 @@ -131,13 +132,14 @@ class TestAdvMailPerformance(TransactionCase): @users('admin', 'emp') @warmup - def test_activity_full(self): + @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({ 'default_res_model': 'mail.test.activity', }) - with self.assertQueryCount(admin=47, emp=52): # test_mail only: 35 - 40 + with self.assertQueryCount(admin=47, emp=52): # com runbot 46 - 51 // test_mail only: 35 - 40 model.create({ 'summary': 'Test Activity', 'res_id': record.id, @@ -175,6 +177,12 @@ class TestHeavyMailPerformance(TransactionCase): self.admin = self.env.user self.admin.login = 'admin' + # setup mail gateway + self.env['ir.config_parameter'].sudo().set_param('mail.catchall.domain', 'example.com') + self.env['ir.config_parameter'].sudo().set_param('mail.catchall.alias', 'test-catchall') + self.env['ir.config_parameter'].sudo().set_param('mail.bounce.alias', 'test-bounce') + + # prepare recipients to test for more realistic workload self.customer = self.env['res.partner'].with_context(self._quick_create_ctx).create({ 'name': 'Test Customer', 'email': 'test@example.com' @@ -182,9 +190,8 @@ class TestHeavyMailPerformance(TransactionCase): self.umbrella = self.env['mail.test'].with_context(mail_create_nosubscribe=True).create({ 'name': 'Test Umbrella', 'customer_id': self.customer.id, - 'alias_name': 'test', + 'alias_name': 'test-alias', }) - Partners = self.env['res.partner'].with_context(self._quick_create_ctx) self.partners = self.env['res.partner'] for x in range(0, 10): @@ -197,10 +204,7 @@ class TestHeavyMailPerformance(TransactionCase): @mute_logger('odoo.tests', 'odoo.addons.mail.models.mail_mail', 'odoo.models.unlink') @users('admin', 'emp') @warmup - def test_mail_mail_send(self): - self.env['ir.config_parameter'].sudo().set_param('mail.catchall.domain', 'example.com') - self.env['ir.config_parameter'].sudo().set_param('mail.catchall.alias', 'test-catchall') - self.env['ir.config_parameter'].sudo().set_param('mail.bounce.alias', 'test-bounce') + def test_complex_mail_mail_send(self): message = self.env['mail.message'].sudo().with_context(message_create_from_mail_mail=True).create({ 'subject': 'Test', 'body': '<p>Test</p>', @@ -210,25 +214,30 @@ class TestHeavyMailPerformance(TransactionCase): 'res_id': self.umbrella.id, }) mail = self.env['mail.mail'].sudo().create({ + 'body_html': '<p>Test</p>', 'mail_message_id': message.id, 'recipient_ids': [(4, pid) for pid in self.partners.ids], }) mail_ids = mail.ids - with self.assertQueryCount(admin=24, emp=47): # test_mail only: 20 - 41 + with self.assertQueryCount(admin=17, emp=25): # com runbot 17 - 25 // test_mail only: 15 - 23 self.env['mail.mail'].browse(mail_ids).send() + self.assertEqual(mail.body_html, '<p>Test</p>') + self.assertEqual(mail.reply_to, formataddr(('%s %s' % (self.env.user.company_id.name, self.umbrella.name), 'test-alias@example.com'))) + @mute_logger('odoo.tests', 'odoo.addons.mail.models.mail_mail', 'odoo.models.unlink') @users('admin', 'emp') @warmup - def test_message_post(self): + def test_complex_message_post(self): self.umbrella.message_subscribe(self.user_portal.partner_id.ids) record = self.umbrella.sudo(self.env.user) - with self.assertQueryCount(admin=128, emp=160): # test_mail only: 120 - 151 + with self.assertQueryCount(admin=131, emp=163): # com runbot 129 - 161 // test_mail only: 125 - 156 record.message_post( body='<p>Test Post Performances</p>', - message_type='comment', subtype='mail.mt_comment') + message_type='comment', + subtype='mail.mt_comment') self.assertEqual(record.message_ids[0].body, '<p>Test Post Performances</p>') self.assertEqual(record.message_ids[0].needaction_partner_ids, self.partners | self.user_portal.partner_id) @@ -236,13 +245,13 @@ class TestHeavyMailPerformance(TransactionCase): @mute_logger('odoo.tests', 'odoo.addons.mail.models.mail_mail', 'odoo.models.unlink') @users('admin', 'emp') @warmup - def test_message_post_template(self): + def test_complex_message_post_template(self): self.umbrella.message_subscribe(self.user_portal.partner_id.ids) record = self.umbrella.sudo(self.env.user) - template = self.env.ref('test_mail.mail_test_tpl') + template_id = self.env.ref('test_mail.mail_test_tpl').id - with self.assertQueryCount(admin=186, emp=233): # test_mail only: 176 - 223 - record.message_post_with_template(template.id, message_type='comment', composition_mode='comment') + with self.assertQueryCount(admin=192, emp=239): # com runbot 190 - 237 // test_mail only: 182 - 227 + 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) self.assertEqual(record.message_ids[0].needaction_partner_ids, self.partners | self.user_portal.partner_id | self.customer) @@ -250,14 +259,14 @@ class TestHeavyMailPerformance(TransactionCase): @mute_logger('odoo.tests', 'odoo.addons.mail.models.mail_mail', 'odoo.models.unlink') @users('admin', 'emp') @warmup - def test_create_tracking_subscription(self): + def test_complex_create_tracking_subscription(self): """ Create record using most features: auto subscription, tracking and templates. """ umbrella_id = self.umbrella.id customer_id = self.customer.id user_id = self.user_portal.id - with self.assertQueryCount(admin=345, emp=418): # test_mail only: 327 - 397 + with self.assertQueryCount(admin=355, emp=428): # test_mail only: 337 - 407 rec = self.env['mail.test.full'].create({ 'name': 'Test', 'umbrella_id': umbrella_id, |
