Friday, April 10, 2009

Making Django's Built-in Auth Tests Pass

Django (web framework)Image via Wikipedia

I added the built in auth framework to a relatively fresh Django project today, and upon running my tests, I got a large number of failures coming from auth. This problem does not appear to be fully documented so this is what I did.

First, notice that most of the errors are template missing errors. Fix these by
  1. Installing the admin tool. Auth relies on some of its templates.
  2. Stub out any other missing templates (ie. login, logout).
Next, the test cases will complain about missing text in your new templates. Just add in exactly what its asking for as plain text.

Finally, some of the password reset tests were complaining about getting redirect (301) codes instead of success (200) codes. This was an error on my part. They're looking for a link in the password reset email and GETting it. I wrapped the link in an HTML anchor, and the regex in the test was grabbing the closing HTML tag. Removing the HTML fixed that problem. Finally, I just had to add some missing text as above, and all the tests passed.
Reblog this post [with Zemanta]