-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: joseph-sentry <[email protected]>
- Loading branch information
1 parent
1803145
commit 105ed31
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
SMTPResponseException, | ||
SMTPSenderRefused, | ||
SMTPServerDisconnected, | ||
SMTPConnectError, | ||
) | ||
from unittest.mock import MagicMock, call, patch | ||
|
||
|
@@ -180,6 +181,52 @@ def test_smtp_disconnected(self, mocker, mock_configuration, dbsession): | |
smtp.connection.noop.assert_has_calls([call()]) | ||
smtp.connection.send_message(call(email.message)) | ||
|
||
def test_smtp_init_connect_fail( | ||
self, mocker, mock_configuration, dbsession, reset_connection_at_start | ||
): | ||
m = MagicMock() | ||
mocker.patch("smtplib.SMTP", side_effect=SMTPConnectError(123, "abc")) | ||
email = Email( | ||
to_addr="[email protected]", | ||
from_addr="[email protected]", | ||
subject="Test subject", | ||
text="test text", | ||
html="test html", | ||
) | ||
|
||
with pytest.raises( | ||
SMTPServiceError, match="Error starting connection for SMTPService" | ||
): | ||
smtp = SMTPService() | ||
|
||
def test_smtp_disconnected_fail( | ||
self, mocker, mock_configuration, dbsession, reset_connection_at_start | ||
): | ||
m = MagicMock() | ||
m.configure_mock( | ||
**{ | ||
"noop.side_effect": SMTPServerDisconnected(), | ||
"connect.side_effect": SMTPConnectError(123, "abc"), | ||
} | ||
) | ||
mocker.patch( | ||
"smtplib.SMTP", | ||
return_value=m, | ||
) | ||
email = Email( | ||
to_addr="[email protected]", | ||
from_addr="[email protected]", | ||
subject="Test subject", | ||
text="test text", | ||
html="test html", | ||
) | ||
|
||
with pytest.raises( | ||
SMTPServiceError, match="Error starting connection for SMTPService" | ||
): | ||
smtp = SMTPService() | ||
smtp.send(email) | ||
|
||
@pytest.mark.parametrize( | ||
"fn, err_msg, side_effect", | ||
[ | ||
|