summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorTulio Casagrande <tcasagra@thoughtworks.com>2016-11-02 13:49:59 -0200
committerKali Kaneko (leap communications) <kali@leap.se>2016-11-04 14:21:07 +0100
commit10877a35de605b0a554558de56f1aae92b39df71 (patch)
treea50e25fce641eae24467fb8098e1ad36d4bbcc6a /tests/unit
parent5788b3fc99fcd8d975000fc9f69874a9fa336943 (diff)
[bug] add tests for outgoing service
This commit originall contained a fix for a wrong variable name that avoided the outgoing service to be launched. This had been fixed in a concurrent mr that got merged before this one. However, this MR contained a couple of tests for the OutgoingService, and I'm merging those tests now.
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/mail/outgoing/test_service.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/unit/mail/outgoing/test_service.py b/tests/unit/mail/outgoing/test_service.py
new file mode 100644
index 0000000..30518cc
--- /dev/null
+++ b/tests/unit/mail/outgoing/test_service.py
@@ -0,0 +1,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)