Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

In tests, add a shortcut to assert mails are sent with correct parameters #16

@benoitbryon

Description

@benoitbryon

As a django-mail-factory user, I setup Python functions (like views) that send email using mail_factory... thus I setup tests to check that mails are actually sent with expected parameters.
Since this is a common task, I would appreciate a shortcut that makes tests easier to write.

The feature is mainly for users.
Maybe it could also be used by django-mail-factory's own tests.

Here is an example of what I'm thinking of:

from django.test import TestCase

from mail_factory.tests import MailValidator

from myapp import send_notifications

class SomeTestCase(TestCase):
    def test_send_notifications(self):
        """send_notifications sends mails."""
        validator = MailValidator()  # Starts watching mail.outbox
        send_notifications('[email protected]')
        validator.assert_mail_sent(
            self,  // use TestCase API for assertions
            template_name='notification',
            to=['[email protected]'])

... where the "validator" is an helper to check result/usage of django-mail-factory, at least most common use cases.

Perhaps the example is not a good one, I'm not experienced enough to tell what is usually tested, or what should be tested.
I guess that, if mail_factory had test utilities, I would simply use them (and test what they cover).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions