[MERGE] Sunc with addons/trunk.
[odoo/odoo.git] / addons / mail / tests / test_mail_mockup.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.tests import common
23
24
25 class TestMailMockups(common.TransactionCase):
26
27     def _mock_smtp_gateway(self, *args, **kwargs):
28         return True
29
30     def _init_mock_build_email(self):
31         self._build_email_args_list = []
32         self._build_email_kwargs_list = []
33
34     def _mock_build_email(self, *args, **kwargs):
35         """ Mock build_email to be able to test its values. Store them into
36             some internal variable for latter processing. """
37         self._build_email_args_list.append(args)
38         self._build_email_kwargs_list.append(kwargs)
39         return self._build_email(*args, **kwargs)
40
41     def setUp(self):
42         super(TestMailMockups, self).setUp()
43         # Install mock SMTP gateway
44         self._init_mock_build_email()
45         self._build_email = self.registry('ir.mail_server').build_email
46         self.registry('ir.mail_server').build_email = self._mock_build_email
47         self._send_email = self.registry('ir.mail_server').send_email
48         self.registry('ir.mail_server').send_email = self._mock_smtp_gateway
49
50     def tearDown(self):
51         # Remove mocks
52         self.registry('ir.mail_server').build_email = self._build_email
53         self.registry('ir.mail_server').send_email = self._send_email
54         super(TestMailMockups, self).tearDown()