From 10877a35de605b0a554558de56f1aae92b39df71 Mon Sep 17 00:00:00 2001 From: Tulio Casagrande Date: Wed, 2 Nov 2016 13:49:59 -0200 Subject: [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. --- tests/unit/mail/outgoing/test_service.py | 54 ++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/unit/mail/outgoing/test_service.py (limited to 'tests') 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 . + +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) -- cgit v1.2.3