Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit 4f6933d

Browse files
author
Tom Galloway
committed
Further smtp tests.
1 parent f2c489d commit 4f6933d

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

market/smtpnotification.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,7 @@ class SMTPNotification(object):
1414

1515
def __init__(self, db):
1616
self.db = db
17-
self.server = 'localhost:25'
18-
self.sender = 'OpenBazaar'
19-
self.recipient = ''
20-
self.username = None
21-
self.password = None
22-
2317
self.log = Logger(system=self)
24-
2518
self.get_smtp_settings()
2619

2720
def get_smtp_settings(self):

market/tests/test_smtpnotification.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from twisted.python import log
33
from mock import patch, MagicMock
44
import mock
5+
from smtplib import SMTPAuthenticationError
56

67
from market.smtpnotification import SMTPNotification
78

@@ -52,3 +53,25 @@ def test_MarketSmtp_send_disabled_not_sent(self, mock_smtp):
5253
assert mock_smtp.call_count == 0
5354
assert instance.login.call_count == 0
5455
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

Comments
 (0)