From 6ccaae1b2f3fbbbd686de976e10439c45f7804de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 6 Sep 2019 11:42:50 +0000 Subject: [PATCH] [MOV] test_mail: split cc tests to either discuss or mailgateway tests PURPOSE In order to rewrite some tests, remove low-level tests and add coverage first step is to reorganize a bit test_mail content. Several tests cases are spread among several files and finding back some feature coverage tests is not easy. SPECIFICATIONS Split cc tests to either discuss or mail gateway tests. It allows to remove an unnecessary file. LINKS Task 1958697 --- addons/test_mail/tests/__init__.py | 3 +- addons/test_mail/tests/test_discuss.py | 10 ++++ addons/test_mail/tests/test_mail_cc.py | 63 --------------------- addons/test_mail/tests/test_mail_gateway.py | 49 ++++++++++++++-- 4 files changed, 56 insertions(+), 69 deletions(-) delete mode 100644 addons/test_mail/tests/test_mail_cc.py diff --git a/addons/test_mail/tests/__init__.py b/addons/test_mail/tests/__init__.py index 75891bb0e8d..78d3b1516b6 100644 --- a/addons/test_mail/tests/__init__.py +++ b/addons/test_mail/tests/__init__.py @@ -7,12 +7,11 @@ from . import test_mail_activity from . import test_mail_followers from . import test_mail_message from . import test_mail_mail -from . import test_mail_cc from . import test_mail_channel from . import test_mail_gateway from . import test_mail_redirect from . import test_mail_template -from . import test_message_composerr +from . import test_message_composer from . import test_message_management from . import test_message_post from . import test_message_track diff --git a/addons/test_mail/tests/test_discuss.py b/addons/test_mail/tests/test_discuss.py index d81f989383e..be255274ea3 100644 --- a/addons/test_mail/tests/test_discuss.py +++ b/addons/test_mail/tests/test_discuss.py @@ -120,3 +120,13 @@ class TestDiscuss(BaseFunctionalTest, TestRecipients, MockEmails): msg.toggle_message_starred() self.assertFalse(msg.starred) self.assertTrue(msg_emp.starred) + + @mute_logger('odoo.addons.mail.models.mail_mail') + def test_mail_cc_recipient_suggestion(self): + record = self.env['mail.test.cc'].create({'email_cc': 'cc1@example.com, cc2@example.com, cc3 '}) + suggestions = record._message_get_suggested_recipients()[record.id] + self.assertEqual(sorted(suggestions), [ + (False, 'cc1@example.com', 'CC Email'), + (False, 'cc2@example.com', 'CC Email'), + (False, 'cc3 ', 'CC Email') + ], 'cc should be in suggestions') diff --git a/addons/test_mail/tests/test_mail_cc.py b/addons/test_mail/tests/test_mail_cc.py deleted file mode 100644 index 45503d3b649..00000000000 --- a/addons/test_mail/tests/test_mail_cc.py +++ /dev/null @@ -1,63 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo.addons.test_mail.tests import common -from odoo.tests import tagged -from odoo.tools import mute_logger, email_split_and_format -from odoo.addons.test_mail.data.test_mail_data import MAIL_TEMPLATE - - -@tagged('mail_thread_cc') -class TestMailCc(common.BaseFunctionalTest, common.MockEmails): - - @classmethod - def setUpClass(cls): - super(TestMailCc, cls).setUpClass() - - cls.email_from = 'Sylvie Lelitre ' - cls.alias = cls.env['mail.alias'].create({ - 'alias_name': 'cc_record', - 'alias_user_id': False, - 'alias_model_id': cls.env['ir.model']._get('mail.test.cc').id, - 'alias_contact': 'everyone'}) - - cls.env['ir.config_parameter'].set_param('mail.bounce.alias', 'bounce.test') - cls.env['ir.config_parameter'].set_param('mail.catchall.domain', 'test.com') - cls.env['ir.config_parameter'].set_param('mail.catchall.alias', 'catchall.test') - - @mute_logger('odoo.addons.mail.models.mail_thread') - def test_message_cc_new(self): - record = self.format_and_process(MAIL_TEMPLATE, self.email_from, 'cc_record@test.com', - cc='cc1@example.com, cc2@example.com', target_model='mail.test.cc') - cc = email_split_and_format(record.email_cc) - self.assertEqual(sorted(cc), ['cc1@example.com', 'cc2@example.com']) - - @mute_logger('odoo.addons.mail.models.mail_thread') - def test_message_cc_update_with_old(self): - record = self.env['mail.test.cc'].create({'email_cc': 'cc1 , cc2@example.com'}) - self.alias.write({'alias_force_thread_id': record.id}) - - self.format_and_process(MAIL_TEMPLATE, self.email_from, 'cc_record@test.com', - cc='cc2 , cc3@example.com', target_model='mail.test.cc') - cc = email_split_and_format(record.email_cc) - self.assertEqual(sorted(cc), ['cc1 ', 'cc2@example.com', 'cc3@example.com'], 'new cc should have been added on record (unique)') - - @mute_logger('odoo.addons.mail.models.mail_thread') - def test_message_cc_update_no_old(self): - record = self.env['mail.test.cc'].create({}) - self.alias.write({'alias_force_thread_id': record.id}) - - self.format_and_process(MAIL_TEMPLATE, self.email_from, 'cc_record@test.com', - cc='cc2 , cc3@example.com', target_model='mail.test.cc') - cc = email_split_and_format(record.email_cc) - self.assertEqual(sorted(cc), ['cc2 ', 'cc3@example.com'], 'new cc should have been added on record (unique)') - - @mute_logger('odoo.addons.mail.models.mail_mail') - def test_mail_cc_recipient_suggestion(self): - record = self.env['mail.test.cc'].create({'email_cc': 'cc1@example.com, cc2@example.com, cc3 '}) - suggestions = record._message_get_suggested_recipients()[record.id] - self.assertEqual(sorted(suggestions), [ - (False, 'cc1@example.com', 'CC Email'), - (False, 'cc2@example.com', 'CC Email'), - (False, 'cc3 ', 'CC Email') - ], 'cc should be in suggestions') diff --git a/addons/test_mail/tests/test_mail_gateway.py b/addons/test_mail/tests/test_mail_gateway.py index 9848b26f0c7..52ed239bc0e 100644 --- a/addons/test_mail/tests/test_mail_gateway.py +++ b/addons/test_mail/tests/test_mail_gateway.py @@ -15,7 +15,7 @@ from odoo.addons.test_mail.models.test_mail_models import MailTestGateway from odoo.addons.test_mail.tests.common import BaseFunctionalTest, MockEmails from odoo.addons.test_mail.tests.common import mail_new_test_user from odoo.tests import tagged -from odoo.tools import mute_logger, pycompat +from odoo.tools import email_split_and_format, mute_logger, pycompat @tagged('mail_gateway') @@ -113,9 +113,7 @@ class TestMailgateway(BaseFunctionalTest, MockEmails): 'message_id': '<123456-openerp-%s-mail.test.gateway@%s>' % (cls.test_record.id, socket.gethostname()), }) - cls.env['ir.config_parameter'].set_param('mail.bounce.alias', 'bounce.test') - cls.env['ir.config_parameter'].set_param('mail.catchall.domain', 'test.com') - cls.env['ir.config_parameter'].set_param('mail.catchall.alias', 'catchall.test') + cls._init_mail_gateway() # -------------------------------------------------- # Base low-level tests @@ -748,3 +746,46 @@ class TestMailgateway(BaseFunctionalTest, MockEmails): self.assertEqual(len(record), 1) self.assertEqual(record.name, 'Spammy') self.assertEqual(record._name, 'mail.test.gateway') + + +class TestMailThreadCC(BaseFunctionalTest, MockEmails): + + @classmethod + def setUpClass(cls): + super(TestMailThreadCC, cls).setUpClass() + + cls.email_from = 'Sylvie Lelitre ' + cls.alias = cls.env['mail.alias'].create({ + 'alias_name': 'cc_record', + 'alias_user_id': False, + 'alias_model_id': cls.env['ir.model']._get('mail.test.cc').id, + 'alias_contact': 'everyone'}) + + cls._init_mail_gateway() + + @mute_logger('odoo.addons.mail.models.mail_thread') + def test_message_cc_new(self): + record = self.format_and_process(MAIL_TEMPLATE, self.email_from, 'cc_record@test.com', + cc='cc1@example.com, cc2@example.com', target_model='mail.test.cc') + cc = email_split_and_format(record.email_cc) + self.assertEqual(sorted(cc), ['cc1@example.com', 'cc2@example.com']) + + @mute_logger('odoo.addons.mail.models.mail_thread') + def test_message_cc_update_with_old(self): + record = self.env['mail.test.cc'].create({'email_cc': 'cc1 , cc2@example.com'}) + self.alias.write({'alias_force_thread_id': record.id}) + + self.format_and_process(MAIL_TEMPLATE, self.email_from, 'cc_record@test.com', + cc='cc2 , cc3@example.com', target_model='mail.test.cc') + cc = email_split_and_format(record.email_cc) + self.assertEqual(sorted(cc), ['cc1 ', 'cc2@example.com', 'cc3@example.com'], 'new cc should have been added on record (unique)') + + @mute_logger('odoo.addons.mail.models.mail_thread') + def test_message_cc_update_no_old(self): + record = self.env['mail.test.cc'].create({}) + self.alias.write({'alias_force_thread_id': record.id}) + + self.format_and_process(MAIL_TEMPLATE, self.email_from, 'cc_record@test.com', + cc='cc2 , cc3@example.com', target_model='mail.test.cc') + cc = email_split_and_format(record.email_cc) + self.assertEqual(sorted(cc), ['cc2 ', 'cc3@example.com'], 'new cc should have been added on record (unique)')