From 15e131907f3eff766b873a8bb2abf19d85b75fd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 8 Sep 2017 10:26:18 +0200 Subject: [PATCH] [IMP] mail: tests: clean invite wizard tests Purpose is to lessen noise and make tests less low-level. Including : * remove test of emails content as this is too low-level and not really interesting. Purpose of test is to check followers have been added and not the content of a template; * remove unnecessary fail string; * remove unnecessary low level checks; --- addons/mail/tests/test_invite.py | 40 ++++++++++++-------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/addons/mail/tests/test_invite.py b/addons/mail/tests/test_invite.py index 7d57973763b..bb50b3f1dc9 100644 --- a/addons/mail/tests/test_invite.py +++ b/addons/mail/tests/test_invite.py @@ -1,39 +1,29 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo.addons.mail.tests.common import TestMail +from odoo.addons.mail.tests import common from odoo.tools import mute_logger -class TestInvite(TestMail): +class TestInvite(common.BaseFunctionalTest, common.MockEmails): @mute_logger('odoo.addons.mail.models.mail_mail') def test_invite_email(self): + test_partner = self.env['res.partner'].with_context(self._quick_create_ctx).create({ + 'name': 'Valid Lelitre', + 'email': 'valid.lelitre@agrolait.com'}) + mail_invite = self.env['mail.wizard.invite'].with_context({ - 'default_res_model': 'mail.test', - 'default_res_id': self.test_pigs.id + 'default_res_model': 'mail.test.simple', + 'default_res_id': self.test_record.id }).sudo(self.user_employee.id).create({ - 'partner_ids': [(4, self.user_portal.partner_id.id), (4, self.partner_1.id)], + 'partner_ids': [(4, test_partner.id), (4, self.user_admin.partner_id.id)], 'send_mail': True}) mail_invite.add_followers() - # Test: Pigs followers should contain Admin, Bert - self.assertEqual(self.test_pigs.message_partner_ids, - self.user_portal.partner_id | self.partner_1, - 'invite wizard: Pigs followers after invite is incorrect, should be Admin + added follower') - self.assertEqual(self.test_pigs.message_follower_ids.mapped('channel_id'), - self.env['mail.channel'], - 'invite wizard: Pigs followers after invite is incorrect, should not have channels') - - # Test: (pretend to) send email and check subject, body - self.assertEqual(len(self._mails), 2, 'invite wizard: sent email number incorrect, should be only for Bert') - self.assertEqual(self._mails[0].get('subject'), 'Invitation to follow %s: Pigs' % self.env['mail.test']._description, - 'invite wizard: subject of invitation email is incorrect') - self.assertEqual(self._mails[1].get('subject'), 'Invitation to follow %s: Pigs' % self.env['mail.test']._description, - 'invite wizard: subject of invitation email is incorrect') - self.assertIn('%s invited you to follow %s document: Pigs' % (self.user_employee.name, self.env['mail.test']._description), - self._mails[0].get('body'), - 'invite wizard: body of invitation email is incorrect') - self.assertIn('%s invited you to follow %s document: Pigs' % (self.user_employee.name, self.env['mail.test']._description), - self._mails[1].get('body'), - 'invite wizard: body of invitation email is incorrect') + # check added followers and that emails were sent + self.assertEqual(self.test_record.message_partner_ids, + test_partner | self.user_admin.partner_id) + self.assertEqual(self.test_record.message_follower_ids.mapped('channel_id'), + self.env['mail.channel']) + self.assertEqual(len(self._mails), 2)