Skip to content

Commit

Permalink
fixup! ✨(emails) use mjml to generate html and text emails
Browse files Browse the repository at this point in the history
  • Loading branch information
wilbrdt committed Aug 12, 2024
1 parent e703187 commit cf6f7fb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 37 deletions.
38 changes: 1 addition & 37 deletions tests/celery/test_tasks.py
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


Expand All @@ -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."""

Expand Down
39 changes: 39 additions & 0 deletions tests/test_mail.py
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)

0 comments on commit cf6f7fb

Please sign in to comment.