[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;
This commit is contained in:
Thibault Delavallée
2017-11-29 10:05:01 +01:00
parent 12fd198bcf
commit 15e131907f
+15 -25
View File
@@ -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)