Re: Testing email with the testserver

2010-03-26 Thread Russell Keith-Magee
On Fri, Mar 26, 2010 at 11:29 PM, Ben Gerdemann  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.



Re: Testing email with the testserver

2010-03-26 Thread Phlip
Ben Gerdemann wrote:

> I am using "manage.py testserver" and Selenium to drive the browser.

Therefor you are running thru the real webserver, not its mock.

And, incidentally, most testing effort should be in unit tests -
Selenium should _only_ test the last mile of integration, where stuff
like JS and Flash come together. Unit tests can trivially use
assert_mail(), available here:
http://github.com/cuker/django-test-extensions/blob/master/src/test_extensions/django_common.py
, to test mail into that mock inbox.

> 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?

Get a cheap SMTP implemention, such as Python's own library, and set
up a dummy email server. But, again, you are literally throwing good
money after bad without unit tests. That's why the documentation
assumed you started there.

--
  Phlip

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



Testing email with the testserver

2010-03-26 Thread Ben Gerdemann
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?

Cheers,
Ben

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