Added achtung images
[odoo/odoo.git] / addons / mail / tests / test_invite.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Business Applications
5 #    Copyright (c) 2012-TODAY OpenERP S.A. <http://openerp.com>
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 from openerp.addons.mail.tests.test_mail_base import TestMailBase
23
24
25 class test_invite(TestMailBase):
26
27     def test_00_basic_invite(self):
28         cr, uid = self.cr, self.uid
29         mail_invite = self.registry('mail.wizard.invite')
30
31         # Do: create a mail_wizard_invite, validate it
32         self._init_mock_build_email()
33         context = {'default_res_model': 'mail.group', 'default_res_id': self.group_pigs_id}
34         mail_invite_id = mail_invite.create(cr, self.user_raoul_id, {'partner_ids': [(4, self.partner_bert_id)], 'send_mail': True}, context)
35         mail_invite.add_followers(cr, self.user_raoul_id, [mail_invite_id], {'default_model': 'mail.group', 'default_res_id': 0})
36
37         # Test: Pigs followers should contain Admin, Bert
38         self.group_pigs.refresh()
39         follower_ids = [follower.id for follower in self.group_pigs.message_follower_ids]
40         self.assertEqual(set(follower_ids), set([self.partner_admin_id, self.partner_bert_id]), 'invite: Pigs followers after invite is incorrect')
41
42         # Test: (pretend to) send email and check subject, body
43         self.assertEqual(len(self._build_email_kwargs_list), 1, 'sent email number incorrect, should be only for Bert')
44         for sent_email in self._build_email_kwargs_list:
45             self.assertEqual(sent_email.get('subject'), 'Invitation to follow Discussion group: Pigs',
46                             'invite: subject of invitation email is incorrect')
47             self.assertIn('Raoul Grosbedon invited you to follow Discussion group document: Pigs', sent_email.get('body'),
48                             'invite: body of invitation email is incorrect')