Table Of Contents

Previous topic

Persistent Database Test Runner

Next topic

Available Settings

This Page

Mock Objects

Mock Requests

This mock allows you to make requests against a view that isn’t included in any URLConf.

RequestFactory

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.

Original Source

Taken from Djangosnippets.net, originally by Simon Willison.