test_utils is a grab-bag of testing utilities that are pretty specific to our Django, Jinja2, and nose setup.
This is a test runner that monkeypatches connection.creation to skip database creation if it appears that the db already exists. Your tests will run much faster.
To force the normal database creation, define the environment variable FORCE_DB. It doesn’t really matter what the value is, we just check to see if it’s there.
TestCase subclass that lets you add extra apps just for testing.
Configure extra apps through the class attribute extra_apps, which is a sequence of ‘app.module’ strings.
class FunTest(ExtraAppTestCase):
extra_apps = ['fun.tests.testapp']
...
Class that lets you create mock Request objects for use in testing.
Usage:
rf = RequestFactory()
get_request = rf.get('/hello/')
post_request = rf.post('/submit/', {'foo': 'bar'})
This class re-uses the django.test.client.Client interface, docs here: http://www.djangoproject.com/documentation/testing/#the-test-client
Once you have a request object you can pass it to any view function, just as if that view had been hooked up using a URLconf.
http://www.djangosnippets.org/snippets/963/