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

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

Open
benoitbryon opened this issue Mar 28, 2013 · 4 comments

Comments

@benoitbryon
Copy link
Contributor

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).

@benoitbryon
Copy link
Contributor Author

I used such tools in django-downloadview: shortcuts to check that download views actually return expected responses. Since it is a common task to override and configure custom download views, test utilities are really helpful.

See:

@Natim
Copy link
Collaborator

Natim commented Mar 28, 2013

This looks to me to be a mail-factory features doesn't it?

https://github.com/novagile/django-mail-factory/blob/master/mail_factory/mails.py#L37

@benoitbryon
Copy link
Contributor Author

I was thinking of checks like:

  • is the expected template used to render mails?
  • does templates succesfully render? Involves: do templates exist?
  • did my custom function called mail factory to send emails?
  • who were the recipients (to)? sender (from)? ...
  • does the mail have attachments? with expected content? filenames? mime-types?
  • ... and maybe more, or perhaps less, questions... depending on what is supposed to be overriden/configured/tested by a typical mail_factory user.

Little code may be needed for each check, but if every user is supposed to write this little code, perhaps some shortcuts would help. And perhaps test utilities would encourage users to write tests.

@Natim
Copy link
Collaborator

Natim commented Nov 29, 2013

That sounds good to me.
Did you need to do that for one of your project? If yes do you mind doing a PR?

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

2 participants