From 7fa36b4c8079ba959d3108cbdee7b4b9d127de0f Mon Sep 17 00:00:00 2001 From: Jonathan Green Date: Thu, 8 Feb 2024 16:16:59 -0400 Subject: [PATCH] Add one more test --- tests/core/service/email/__init__.py | 0 tests/core/service/email/test_container.py | 44 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 tests/core/service/email/__init__.py create mode 100644 tests/core/service/email/test_container.py diff --git a/tests/core/service/email/__init__.py b/tests/core/service/email/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/core/service/email/test_container.py b/tests/core/service/email/test_container.py new file mode 100644 index 0000000000..3f908513b2 --- /dev/null +++ b/tests/core/service/email/test_container.py @@ -0,0 +1,44 @@ +from unittest.mock import create_autospec + +import pytest +from redmail import EmailSender + +from core.service.email.container import Email + + +@pytest.fixture +def container() -> Email: + email = Email() + email.config.from_dict( + { + "server": "test_server.com", + "port": 587, + "username": "username", + "password": "password", + "sender": "test@test.com", + } + ) + return email + + +def test_emailer(container: Email): + emailer = container.emailer() + assert isinstance(emailer, EmailSender) + assert emailer.host == "test_server.com" + assert emailer.port == 587 + assert emailer.username == "username" + assert emailer.password == "password" + + +def test_send_email(container: Email): + mock_emailer = create_autospec(EmailSender) + container.emailer.override(mock_emailer) + container.send_email(subject="subject", receivers=["x@y.com", "a@b.com"]) + mock_emailer.send.assert_called_once_with( + subject="subject", + sender="test@test.com", + receivers=["x@y.com", "a@b.com"], + text=None, + html=None, + attachments=None, + )