views:

381

answers:

1

When I run the test suite of django I get errors on the auth application. I have (obviously) not written any of auth code and I have not written tests for auth. yet the auth tests fail. Here are some of the errors I get, the whole stacktrace is too big to put here: Does someone has dealt with this before?

AttributeError: 'module' object has no attribute 'handler500'

DoesNotExist: UserProfile matching query does not exist.

----------------------------------------------------------------------
Ran 30 tests in 3.813s

FAILED (errors=17)
Destroying test database...
+2  A: 

I figured it out. Failed tests in auth tests happen if the auth app uses complicated templates to render the default auth template-views. The auth app tests itself with the templates which are used by your application. I have changed the defaults to templates which look the same as the rest of my website.

The mistake I made in my templates:

  • usage of variables and reverse urls which are not known by the auth app. In my case it where user profile usage (which are not to be found when you are not logged in ofcourse) in auth templates and bad url reverse tags which caused errors in the auth app tests.

When I dropped out everything which was useless anyways on the basic auth templates all auth tests succeeded again.

because of this I learned another lesson:

It is usefull to separate content and structure in your templates. This is easy todo by creating a base.html template file which only defines a basic html page structure and contains a bunch of content blocks. The next step is to create a base_content.html which extends base.html and only defines content blocks you use to render content into the pages. All app you use extend the base_content.html and fill up the remaining empty content blocks. Using this technice it is very easy to create auth templates which extend base_content.html for the very basic authentication templates so most of the (useless) content is left out.

Stephan