diff --git a/tests/celery/test_tasks.py b/tests/celery/test_tasks.py index ce75dab..531d407 100644 --- a/tests/celery/test_tasks.py +++ b/tests/celery/test_tasks.py @@ -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 = "john.doe@example.com" - 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 = "john.doe@example.com" - 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.""" diff --git a/tests/test_mail.py b/tests/test_mail.py index e69de29..0f24426 100644 --- a/tests/test_mail.py +++ b/tests/test_mail.py @@ -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 = "john.doe@example.com" + 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 = "john.doe@example.com" + test_username = "JohnDoe" + + with pytest.raises(EmailSendError, match="Failed sending an email"): + send_email(email_address=test_address, username=test_username)