Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9e0b0a1

Browse files
author
Siddharta Govindaraj
committed
EmailAction - testing exception handling
1 parent adc9606 commit 9e0b0a1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

stock_alerter/tests/test_action.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,12 @@ def test_connection_closed_after_sending_mail(self, mock_smtp_class):
3030
mock_smtp.assert_has_calls([
3131
mock.call.send_message(mock.ANY),
3232
mock.call.quit()])
33+
34+
def test_connection_closed_if_send_gives_error(self, mock_smtp_class):
35+
mock_smtp = mock_smtp_class.return_value
36+
mock_smtp.send_message.side_effect = smtplib.SMTPServerDisconnected()
37+
try:
38+
self.action.execute("MSFT has crossed $10 price level")
39+
except Exception:
40+
pass
41+
self.assertTrue(mock_smtp.quit.called)

0 commit comments

Comments
 (0)