Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django view testing

Tags:

python

django

I'm trying to figure out if there is a quick way to test my django view functions form either the python or django shell. How would I go about instantiating and passing in faux HTTPrequest object?

like image 660
Karthik Ramachandran Avatar asked Jul 06 '11 16:07

Karthik Ramachandran


1 Answers

The django.test.client would be the way to go.

From the django docs

from django.test.client import Client
c = Client()
response = c.post('/login/', {'username': 'john', 'password': 'smith'})
response.status_code
like image 84
domino Avatar answered Sep 22 '22 12:09

domino