diff options
author | Folker Bernitt <fbernitt@thoughtworks.com> | 2015-02-05 11:21:48 +0100 |
---|---|---|
committer | Folker Bernitt <fbernitt@thoughtworks.com> | 2015-02-05 15:26:58 +0100 |
commit | 9893a5409560e1cc7123ec42d12b49e6edd6283c (patch) | |
tree | 3933147ea994a4ea71536d0c6be084827418f56d /service/test/unit/adapter/services | |
parent | a471b8e494b46fd85022b2105eee50fec4f84996 (diff) |
(Re-)added error handling for twisted smtp sender.
- Issue #249
- Fixed all tests with that rely on sendmail deferred.
Diffstat (limited to 'service/test/unit/adapter/services')
-rw-r--r-- | service/test/unit/adapter/services/__init__.py | 0 | ||||
-rw-r--r-- | service/test/unit/adapter/services/test_mail_sender.py | 63 |
2 files changed, 63 insertions, 0 deletions
diff --git a/service/test/unit/adapter/services/__init__.py b/service/test/unit/adapter/services/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/service/test/unit/adapter/services/__init__.py diff --git a/service/test/unit/adapter/services/test_mail_sender.py b/service/test/unit/adapter/services/test_mail_sender.py new file mode 100644 index 00000000..8536e5e3 --- /dev/null +++ b/service/test/unit/adapter/services/test_mail_sender.py @@ -0,0 +1,63 @@ +# +# Copyright (c) 2014 ThoughtWorks, Inc. +# +# Pixelated is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pixelated 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Pixelated. If not, see <http://www.gnu.org/licenses/>. +from twisted.trial import unittest + +from mockito import mock, when, verify, any, unstub +from pixelated.adapter.services.mail_sender import MailSender +from pixelated.adapter.model.mail import PixelatedMail, InputMail +from test.support.test_helper import mail_dict +from twisted.internet import reactor +from twisted.internet.defer import Deferred + + +class MailSenderTest(unittest.TestCase): + def test_sendmail(self): + when(reactor).connectTCP('localhost', 4650, any()).thenReturn(None) + input_mail = InputMail.from_dict(mail_dict()) + mail_sender = MailSender('someone@somedomain.tld') + + return self._succeed(mail_sender.sendmail(input_mail)) + + def tearDown(self): + unstub() + + def test_sendmail_uses_twisted(self): + when(reactor).connectTCP('localhost', 4650, any()).thenReturn(None) + + input_mail = InputMail.from_dict(mail_dict()) + mail_sender = MailSender('someone@somedomain.tld') + + sent_deferred = mail_sender.sendmail(input_mail) + + verify(reactor).connectTCP('localhost', 4650, any()) + + return self._succeed(sent_deferred) + + def test_senmail_returns_deffered(self): + when(reactor).connectTCP('localhost', 4650, any()).thenReturn(None) + input_mail = InputMail.from_dict(mail_dict()) + mail_sender = MailSender('someone@somedomain.tld') + + deferred = mail_sender.sendmail(input_mail) + + self.assertIsNotNone(deferred) + self.assertTrue(isinstance(deferred, Deferred)) + + return self._succeed(deferred) + + def _succeed(self, deferred): + deferred.callback(None) + return deferred |