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 o开发者_如何学JAVAbject?
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
If you're using Django 1.3, take a look at the included RequestFactory.
You should check out django.test.client.Client or django.test.client.RequestFactory which are documented in django's unit testing facility: https://docs.djangoproject.com/en/1.3/topics/testing/
I also suggest using template responses in your views since they let you inspect the context used to render the template: http://docs.djangoproject.com/en/1.3/ref/template-response/
Sounds like you want the django test client https://docs.djangoproject.com/en/dev/topics/testing/#module-django.test.client
精彩评论