1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# -*- coding: utf-8 -*-
# test_service.py
# Copyright (C) 2016 LEAP
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import unittest
from mock import MagicMock
from leap.bitmask.mail.outgoing.service import OutgoingMail
class TestService(unittest.TestCase):
def setUp(self):
self.from_address = 'testing@address.com'
self.keymanager = MagicMock()
self.cert = u'cert'
self.key = u'key'
self.host = 'address.com'
self.port = 1234
def test_send_error_bounces_if_bouncer_is_provided(self):
bouncer = MagicMock()
outgoing_mail = OutgoingMail(self.from_address, self.keymanager,
self.cert, self.key, self.host, self.port,
bouncer)
failure = MagicMock()
origmsg = 'message'
outgoing_mail.sendError(failure, origmsg)
bouncer.bounce_message.assert_called()
def test_send_error_raises_exception_if_there_is_no_bouncer(self):
bouncer = None
outgoing_mail = OutgoingMail(self.from_address, self.keymanager,
self.cert, self.key, self.host, self.port,
bouncer)
failure = MagicMock(value=Exception('smtp error'))
origmsg = 'message'
with self.assertRaises(Exception):
outgoing_mail.sendError(failure, origmsg)
|