[MERGE] forward porting fixes from saas-3
[odoo/odoo.git] / addons / email_template / tests / test_ir_actions.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Business Applications
5 #    Copyright (c) 2013-TODAY OpenERP S.A. <http://www.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.base.tests.test_ir_actions import TestServerActionsBase
23
24
25 class TestServerActionsEmail(TestServerActionsBase):
26
27     def test_00_state_email(self):
28         """ Test ir.actions.server email type """
29         cr, uid = self.cr, self.uid
30
31         # create email_template
32         template_id = self.registry('email.template').create(cr, uid, {
33             'name': 'TestTemplate',
34             'email_from': 'myself@example.com',
35             'email_to': 'brigitte@example.com',
36             'partner_to': '%s' % self.test_partner_id,
37             'model_id': self.res_partner_model_id,
38             'subject': 'About ${object.name}',
39             'body_html': '<p>Dear ${object.name}, your parent is ${object.parent_id and object.parent_id.name or "False"}</p>',
40         })
41
42         self.ir_actions_server.write(cr, uid, self.act_id, {
43             'state': 'email',
44             'template_id': template_id,
45         })
46         run_res = self.ir_actions_server.run(cr, uid, [self.act_id], context=self.context)
47         self.assertFalse(run_res, 'ir_actions_server: email server action correctly finished should return False')
48
49         # check an email is waiting for sending
50         mail_ids = self.registry('mail.mail').search(cr, uid, [('subject', '=', 'About TestingPartner')])
51         self.assertEqual(len(mail_ids), 1, 'ir_actions_server: TODO')
52         # check email content
53         mail = self.registry('mail.mail').browse(cr, uid, mail_ids[0])
54         self.assertEqual(mail.body, '<p>Dear TestingPartner, your parent is False</p>',
55                          'ir_actions_server: TODO')