class RequestFactory
[source]
The RequestFactory
shares the same API as the test client. However, instead of behaving like a browser, the RequestFactory provides a way to generate a request instance that can be used as the first argument to any view. This means you can test a view function the same way as you would test any other function – as a black box, with exactly known inputs, testing for specific outputs.
The API for the RequestFactory
is a slightly restricted subset of the test client API:
- It only has access to the HTTP methods
get()
,post()
,put()
,delete()
,head()
,options()
, andtrace()
. - These methods accept all the same arguments except for
follows
. Since this is just a factory for producing requests, it’s up to you to handle the response. - It does not support middleware. Session and authentication attributes must be supplied by the test itself if required for the view to function properly.
Please login to continue.