1
我想寫對於涉及提交表單(別人寫的)Django視圖單元測試,看起來像這樣輸入類型:POST值提交使用django.test.client.Client
<form method="post" action="/oauth2/token" class="authenticate">
<input type="hidden" name="grant_type" value="authorization_code">
<input type="hidden" name="code" value="73c2c13e4957331f4183bdfafd1f1c">
<input type="hidden" name="redirect_uri" value="http://127.0.0.1:8000/client/9e22123649f8cb8de8e85e70c64969/">
<input type="hidden" name="client_id" value="9e22123649f8cb8de8e85e70c64969">
<input type="submit" value="123456">
</form>
當使用Django測試客戶端時,我不確定如何提交對應於「提交」輸入類型的值。具體而言,又該何去何從到位以下???
的:
c = django.test.client.Client()
response = c.post('/oauth2/token', {"grant_type": "authorization_code",
"code": code,
"redirect_uri": "http://127.0.0.1:8000/client/9e22123649f8cb8de8e85e70c64969/",
"client_id": "9e22123649f8cb8de8e85e70c64969",
???: "123456"})
第1步。將打印語句添加到您要測試的視圖函數中。第2步。查看真實POST的結果。第3步。將真正的POST與您的單元測試POST進行比較。 – 2012-02-06 18:15:07