diff --git a/mail_parent_recipient/tests/test_mail_parent_recipient.py b/mail_parent_recipient/tests/test_mail_parent_recipient.py index a6823c94..d98a7d99 100644 --- a/mail_parent_recipient/tests/test_mail_parent_recipient.py +++ b/mail_parent_recipient/tests/test_mail_parent_recipient.py @@ -7,13 +7,14 @@ from odoo.addons.mail.tests.common import TestMail class TestMailTemplate(TestMail): - def setUp(self): - super(TestMailTemplate, self).setUp() + @classmethod + def setUpClass(cls): + super(TestMailTemplate, cls).setUpClass() - self.Users = self.env['res.users'] - self.res_partner = self.env['res.partner'] - self.mail_template = self.env['mail.template'] - self.mail_comp_msg = self.env['mail.compose.message'] + cls.Users = cls.env['res.users'] + cls.res_partner = cls.env['res.partner'] + cls.mail_template = cls.env['mail.template'] + cls.mail_comp_msg = cls.env['mail.compose.message'] # Company company_vals = { @@ -21,29 +22,29 @@ class TestMailTemplate(TestMail): 'email': 'company.mail.test@company' } - self.company_test = self.res_partner.create(company_vals) + cls.company_test = cls.res_partner.create(company_vals) # Partners test 1 without email partner_no_mail_vals = { 'name': 'partner_1', - 'parent_id': self.company_test.id, + 'parent_id': cls.company_test.id, } # Partners test 2 with email partner_with_mail_vals = { 'name': 'partner_2', 'email': 'partner.2.mail.test@company', - 'parent_id': self.company_test.id, + 'parent_id': cls.company_test.id, } - self.partner_no_mail = self.res_partner.create(partner_no_mail_vals) - self.partner_with_mail = self.res_partner.create( + cls.partner_no_mail = cls.res_partner.create(partner_no_mail_vals) + cls.partner_with_mail = cls.res_partner.create( partner_with_mail_vals ) - def create_mail_composer(self, partner_to_send_id): - email_template = self.env['mail.template'].create({ - 'model_id': self.env['ir.model'].search([ + def create_mail_composer(cls, partner_to_send_id): + email_template = cls.env['mail.template'].create({ + 'model_id': cls.env['ir.model'].search([ ('model', '=', 'mail.channel') ], limit=1).id, 'name': 'Pigs Template', @@ -53,7 +54,7 @@ class TestMailTemplate(TestMail): 'partner_to': '%s' % (partner_to_send_id), }) - composer = self.mail_comp_msg.with_context({ + composer = cls.mail_comp_msg.with_context({ 'default_composition_mode': 'comment', 'default_model': 'mail.channel', 'default_use_template': True, @@ -64,7 +65,7 @@ class TestMailTemplate(TestMail): }) values = composer.onchange_template_id( email_template.id, - 'comment', 'mail.channel', self.group_pigs.id + 'comment', 'mail.channel', cls.group_pigs.id )['value'] # use _convert_to_cache to return a browse record list from command @@ -76,26 +77,26 @@ class TestMailTemplate(TestMail): return recipients - def test_1_mail_send_to_partner_no_mail(self): + def test_1_mail_send_to_partner_no_mail(cls): """Use company mail if recipient partner has no email.""" - recipients = self.create_mail_composer(self.partner_no_mail.id) + recipients = cls.create_mail_composer(cls.partner_no_mail.id) - self.assertEqual(recipients.email, self.company_test.email) - self.assertNotEqual(recipients.email, self.partner_no_mail.email) - self.assertNotEqual(recipients.email, self.partner_with_mail.email) + cls.assertEqual(recipients.email, cls.company_test.email) + cls.assertNotEqual(recipients.email, cls.partner_no_mail.email) + cls.assertNotEqual(recipients.email, cls.partner_with_mail.email) - def test_2_mail_send_to_partner_with_mail(self): + def test_2_mail_send_to_partner_with_mail(cls): """Use partner mail if recipient partner has an email.""" - recipients = self.create_mail_composer(self.partner_with_mail.id) + recipients = cls.create_mail_composer(cls.partner_with_mail.id) - self.assertNotEqual(recipients.email, self.company_test.email) - self.assertNotEqual(recipients.email, self.partner_no_mail.email) - self.assertEqual(recipients.email, self.partner_with_mail.email) + cls.assertNotEqual(recipients.email, cls.company_test.email) + cls.assertNotEqual(recipients.email, cls.partner_no_mail.email) + cls.assertEqual(recipients.email, cls.partner_with_mail.email) - def test_3_mail_send_to_company_test(self): + def test_3_mail_send_to_company_test(cls): """Use company mail if recipient is the company.""" - recipients = self.create_mail_composer(self.company_test.id) + recipients = cls.create_mail_composer(cls.company_test.id) - self.assertEqual(recipients.email, self.company_test.email) - self.assertNotEqual(recipients.email, self.partner_no_mail.email) - self.assertNotEqual(recipients.email, self.partner_with_mail.email) + cls.assertEqual(recipients.email, cls.company_test.email) + cls.assertNotEqual(recipients.email, cls.partner_no_mail.email) + cls.assertNotEqual(recipients.email, cls.partner_with_mail.email)