2011-07-06 50 views
5

我想弄清楚是否有一種快速方法來測試我的Django視圖函數形式的python或Django殼。我將如何去實例化並傳入人造HTTPrequest對象?Django視圖測試

回答

5

django.test.client將是要走的路。

django docs

from django.test.client import Client 
c = Client() 
response = c.post('/login/', {'username': 'john', 'password': 'smith'}) 
response.status_code