Test Utilities

test_utils is a grab-bag of testing utilities that are pretty specific to our Django, Jinja2, and nose setup.

class test_utils.runner.RadicalTestSuiteRunner(verbosity=1, interactive=True, failfast=True)

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.

class test_utils.ExtraAppTestCase(*args, **kwargs)

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 test_utils.RequestFactory(**defaults)

Class that lets you create mock Request objects for use in testing.


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.


Return the request object as soon as it’s created.
class test_utils.TestCase(*args, **kwargs)
Subclass of django.test.TestCase that sets up Jinja template hijacking.
test_utils.locale_eq(a, b)
Compare two locales.
Our own setup that hijacks Jinja template rendering.

This Page