Andy McKay

Jan 27, 2009

Test client and simpletemplate

One of the nice things about Django tests is that if you are testing your views (and who doesn't) you can test the context that comes back. That is, when you make a call to a template, you could check the HTML if you wanted, but you could just check the right data was sent to the template.

Unless you are using my simpletemplate that is, since Django testing patches the internal Django templating to pass back the context. I've just added the same to simpletemplate, so that it does the same. At the top of your tests you need to add one line:

from django.contrib.simpletemplate import test

Then in a test we can do:

        c = Client()
        res = c.get("/")
        assert res.status_code == 200
        assert res.context != None, "Test that my simpletemplate patch is working"
        assert res.context["objects"], "Check that we have some objects"

That's in simpletemplate SVN.

Sigh, the more I use simpletemplate, the more I see all the silly things I did when I wrote it (like putting it in contrib) and need to clean that up one day .