diff options
author | Folker Bernitt <fbernitt@thoughtworks.com> | 2015-11-04 17:08:18 +0100 |
---|---|---|
committer | Folker Bernitt <fbernitt@thoughtworks.com> | 2015-11-04 17:08:18 +0100 |
commit | 9c2318ee52b70437cd4e834539d20ed00194280d (patch) | |
tree | bc082958ce522b48235e8ac5fe07b65ce8bc70f4 /service/test | |
parent | 1726b1ec3797b20b97adb184210c9e601a7c82b9 (diff) |
Add error handling to MailSender
- Issue #499
Diffstat (limited to 'service/test')
-rw-r--r-- | service/test/unit/adapter/services/test_mail_sender.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/service/test/unit/adapter/services/test_mail_sender.py b/service/test/unit/adapter/services/test_mail_sender.py index 20ddc2c6..38da726b 100644 --- a/service/test/unit/adapter/services/test_mail_sender.py +++ b/service/test/unit/adapter/services/test_mail_sender.py @@ -18,7 +18,8 @@ from twisted.mail.smtp import User from twisted.trial import unittest from mockito import mock, when, verify, any, unstub -from pixelated.adapter.services.mail_sender import LocalSmtpMailSender, SMTPDownException, MailSender +from pixelated.adapter.services.mail_sender import LocalSmtpMailSender, SMTPDownException, MailSender, \ + MailSenderException from pixelated.adapter.model.mail import InputMail from pixelated.bitmask_libraries.smtp import LeapSMTPConfig from pixelated.support.functional import flatten @@ -63,6 +64,20 @@ class MailSenderTest(unittest.TestCase): for recipient in flatten([input_mail.to, input_mail.cc, input_mail.bcc]): verify(OutgoingMail).send_message(any(), TwistedSmtpUserCapture(recipient)) + @defer.inlineCallbacks + def test_problem_with_email_raises_exception(self): + sender = MailSender(self._smtp_config, self._keymanager_mock) + input_mail = InputMail.from_dict(mail_dict()) + + when(OutgoingMail).send_message(any(), any()).thenAnswer(lambda: defer.fail(Exception('pretend something went wrong'))) + + try: + yield sender.sendmail(input_mail) + self.fail('Exception expected!') + except MailSenderException, e: + for recipient in flatten([input_mail.to, input_mail.cc, input_mail.bcc]): + self.assertTrue(recipient in e.email_error_map) + class LocalSmtpMailSenderTest(unittest.TestCase): def setUp(self): |