On 7/10/07, Mambaragi <[EMAIL PROTECTED]> wrote:
>
> ] client = Client()
> ] self.assertRaises(TemplateDoesNotExist, client.get, "/user/
> preferences/")
>
> Is is a bug or my mistake??

It's a mistake on your part.

assertRaises isn't a very effective test for the test Client, because
web browsers don't ever get exceptions - they get web pages with 5xx
error codes if something goes wrong. Since the test Client is trying
to act like a browser, it won't really see that many exceptions - and
it certainly won't see an exception raised in a view.

If you run your development server and visit '/user/', you should see
the Django error page. This is because your view is raising an
exception, which is caught by Django and turned into a 500 response
for the browser. The error message will report the
LoginRequiredException, but that's just the result of the default
template that Django uses when DEBUG=True is enabled in your settings.

When a test suite runs, DEBUG is turned off, and the default Django
error pages are not used. As a result, Django will look for a 500.html
template, and in your case, it isn't finding it. This is the error
supercedes the LoginRequired exception, and is the one that is
reported to the client.

You need to think a little more about what client behaviour you are
trying to test, and assert those conditions (e.g., response status
code, response content, etc).

Alternatively, you can create a fake HttpRequest, and call the view
manually. If you do this, you will be able to catch the exception
because the rest of the request serving code won't get in the way.

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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to