-
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
fec392a
commit 62d15b6
Showing
1 changed file
with
18 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 |
---|---|---|
@@ -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") | ||
|
@@ -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) |