|
2 | 2 | from twisted.python import log |
3 | 3 | from mock import patch, MagicMock |
4 | 4 | import mock |
| 5 | +from smtplib import SMTPAuthenticationError |
5 | 6 |
|
6 | 7 | from market.smtpnotification import SMTPNotification |
7 | 8 |
|
@@ -52,3 +53,25 @@ def test_MarketSmtp_send_disabled_not_sent(self, mock_smtp): |
52 | 53 | assert mock_smtp.call_count == 0 |
53 | 54 | assert instance.login.call_count == 0 |
54 | 55 | assert instance.sendmail.call_count == 0 |
| 56 | + |
| 57 | + @patch("smtplib.SMTP") |
| 58 | + def test_MarketSmtp_send_throw_smtpexception(self, mock_smtp): |
| 59 | + '''Email sent when enabled''' |
| 60 | + catcher = self.catcher |
| 61 | + mock_smtp.side_effect = SMTPAuthenticationError(50, 'Test error thrown') |
| 62 | + s = SMTPNotification(self.db) |
| 63 | + s.send('test_subject', 'test_body') |
| 64 | + mock_smtp.assert_called_once_with('test_server') |
| 65 | + catch_exception = catcher.pop() |
| 66 | + self.assertEquals(catch_exception["message"][0], "[ERROR] Authentication Error: (50, 'Test error thrown')") |
| 67 | + |
| 68 | + @patch("smtplib.SMTP") |
| 69 | + def test_MarketSmtp_send_throw_exception(self, mock_smtp): |
| 70 | + '''Email sent when enabled''' |
| 71 | + catcher = self.catcher |
| 72 | + mock_smtp.side_effect = Exception('Test exception thrown') |
| 73 | + s = SMTPNotification(self.db) |
| 74 | + s.send('test_subject', 'test_body') |
| 75 | + mock_smtp.assert_called_once_with('test_server') |
| 76 | + catch_exception = catcher.pop() |
| 77 | + self.assertEquals(catch_exception["message"][0], "[ERROR] Test exception thrown") |
0 commit comments