Skip to content

Commit

Permalink
Test more in test_smtp.py
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 27, 2023
1 parent fec392a commit 62d15b6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions services/tests/test_smtp.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
from ssl import create_default_context
from unittest.mock import MagicMock, call

from helpers.email import Email
from services.smtp import get_smtp_service


class TestSMTP(object):
def test_correct_init(self, mocker, mock_configuration):
mocker.patch("smtplib.SMTP")
mock_configuration._params["services"]["smtp"]["username"] = "test_username"
mock_configuration._params["services"]["smtp"]["password"] = "test_password"
m = mocker.patch("ssl.create_default_context", return_value=MagicMock())
service = get_smtp_service()
service._conn.starttls.assert_called_with(context=m.return_value)
service._conn.login.assert_called_with("test_username", "test_password")

def test_idempotent_service(self, mocker, mock_configuration):
mocker.patch("smtplib.SMTP")
Expand All @@ -24,3 +28,17 @@ def test_idempotent_connection(self, mocker, mock_configuration):
second = get_smtp_service()
second_conn = second._conn
assert id(first_conn) == id(second_conn)

def test_send(self, mocker, mock_configuration):
email = Email(
to_addr="[email protected]",
from_addr="[email protected]",
subject="Test subject",
text="test text",
html="test html",
)

smtp = get_smtp_service()
smtp.send(email=email)

smtp._conn.send_message.assert_called_with(email.message)

0 comments on commit 62d15b6

Please sign in to comment.