On Fri, Mar 26, 2010 at 11:29 PM, Ben Gerdemann <gerd...@gmail.com> wrote:
> I found the Django documentation about testing E-mail services
> confusing. It says here 
> http://docs.djangoproject.com/en/1.1/topics/testing/#e-mail-services
> "Django's test runner automatically redirects all Django-sent e-mail
> to a dummy outbox", but the example code shows using the 'mail' object
> directly in the TestCase and not in the view like the documentation
> states.
>
> I am using "manage.py testserver" and Selenium to drive the browser.
> When I have a test that triggers an email event, the email is sent and
> not collected in the dummy outbox. Is this the expected behavior?
> Would the behavior be different if I loaded the view using
> django.test.client instead of through the testserver?
>
> It would be nice of the testserver also used the dummy outbox, but at
> a minimum I think the documentation should be clearer and perhaps give
> a better example?

As noted by Phlip, the behaviour you're seeing is caused because
testserver isn't running in the test environment; it's just using the
test database.

However, if you're using trunk (soon to be 1.2), there is a way around
your problem.

One of the new features that has been added is the ability to control
the mail sending backend. One of the available backends is the locmem
backend, which is the same memory-backed mail sending interface that
the test framework uses to send mail. There are also console and file
based backends, if you're looking for other ways to avoid SMTP but
retain the ability to check mail output.

See the release notes [1] and feature docs [2] for more details.

[1] http://docs.djangoproject.com/en/dev/releases/1.2/#e-mail-backends
[2] http://docs.djangoproject.com/en/dev/topics/email/#topic-email-backends

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to