-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! ✨(emails) use mjml to generate html and text emails
- Loading branch information
Showing
2 changed files
with
40 additions
and
37 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,12 +1,6 @@ | ||
"""Tests for Mork Celery tasks.""" | ||
|
||
import smtplib | ||
from unittest.mock import MagicMock | ||
|
||
import pytest | ||
|
||
from mork.celery.tasks import check_email_already_sent, mark_email_status, send_email | ||
from mork.exceptions import EmailSendError | ||
from mork.celery.tasks import check_email_already_sent, mark_email_status | ||
from mork.factories import EmailStatusFactory | ||
|
||
|
||
|
@@ -26,36 +20,6 @@ class MockMorkDB: | |
assert check_email_already_sent(email_address) | ||
|
||
|
||
def test_send_email(monkeypatch): | ||
"""Test the `send_email` function.""" | ||
|
||
mock_SMTP = MagicMock() | ||
monkeypatch.setattr("mork.celery.tasks.smtplib.SMTP", mock_SMTP) | ||
|
||
test_address = "[email protected]" | ||
test_username = "JohnDoe" | ||
send_email(email_address=test_address, username=test_username) | ||
|
||
assert mock_SMTP.return_value.__enter__.return_value.sendmail.call_count == 1 | ||
|
||
|
||
def test_send_email_with_smtp_exception(monkeypatch): | ||
"""Test the `send_email` function with an SMTP exception.""" | ||
|
||
mock_SMTP = MagicMock() | ||
mock_SMTP.return_value.__enter__.return_value.sendmail.side_effect = ( | ||
smtplib.SMTPException | ||
) | ||
|
||
monkeypatch.setattr("mork.celery.tasks.smtplib.SMTP", mock_SMTP) | ||
|
||
test_address = "[email protected]" | ||
test_username = "JohnDoe" | ||
|
||
with pytest.raises(EmailSendError, match="Failed sending an email"): | ||
send_email(email_address=test_address, username=test_username) | ||
|
||
|
||
def test_mark_email_status(monkeypatch, db_session): | ||
"""Test the `mark_email_status` function.""" | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""Tests for Mork mail functions.""" | ||
|
||
import smtplib | ||
from unittest.mock import MagicMock | ||
|
||
import pytest | ||
|
||
from mork.exceptions import EmailSendError | ||
from mork.mail import send_email | ||
|
||
|
||
def test_send_email(monkeypatch): | ||
"""Test the `send_email` function.""" | ||
|
||
mock_SMTP = MagicMock() | ||
monkeypatch.setattr("mork.celery.tasks.smtplib.SMTP", mock_SMTP) | ||
|
||
test_address = "[email protected]" | ||
test_username = "JohnDoe" | ||
send_email(email_address=test_address, username=test_username) | ||
|
||
assert mock_SMTP.return_value.__enter__.return_value.sendmail.call_count == 1 | ||
|
||
|
||
def test_send_email_with_smtp_exception(monkeypatch): | ||
"""Test the `send_email` function with an SMTP exception.""" | ||
|
||
mock_SMTP = MagicMock() | ||
mock_SMTP.return_value.__enter__.return_value.sendmail.side_effect = ( | ||
smtplib.SMTPException | ||
) | ||
|
||
monkeypatch.setattr("mork.celery.tasks.smtplib.SMTP", mock_SMTP) | ||
|
||
test_address = "[email protected]" | ||
test_username = "JohnDoe" | ||
|
||
with pytest.raises(EmailSendError, match="Failed sending an email"): | ||
send_email(email_address=test_address, username=test_username) |