Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocking email template for tests #444

Open
MariaMozgunova opened this issue Jul 10, 2023 · 0 comments
Open

Mocking email template for tests #444

MariaMozgunova opened this issue Jul 10, 2023 · 0 comments

Comments

@MariaMozgunova
Copy link

Hi,

When writing unit tests for our application, we use the following setup to prevent emails from being sent:

POST_OFFICE = {
    ...
    "BACKENDS": {"default": "django.core.mail.backends.dummy.EmailBackend"},
}

However, when I run tests I get an error that the email template does not exist:

post_office.models.EmailTemplate.DoesNotExist: EmailTemplate matching query does not exist.

So the question is, is there some recommended way to mock email templates for tests? As an alternative, we can use the fixture to mock mail.send function altogether:

@pytest.fixture(scope="session", autouse=True)
def send_email_mock():
    with mock.patch("post_office.mail.send", return_value=None) as _fixture:
        yield _fixture

What is the recommended approach here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant