Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
Signed-off-by: joseph-sentry <[email protected]>
  • Loading branch information
joseph-sentry committed Sep 29, 2023
1 parent 1803145 commit 105ed31
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions services/tests/test_smtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
SMTPResponseException,
SMTPSenderRefused,
SMTPServerDisconnected,
SMTPConnectError,
)
from unittest.mock import MagicMock, call, patch

Expand Down Expand Up @@ -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",
[
Expand Down

0 comments on commit 105ed31

Please sign in to comment.