Reputation: 59242
I'm trying to write a unit test for a Django view that involves submitting a form (written by someone else) that looks like this:
<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>
When using the Django test client, I'm not sure how to submit the value that corresponds to the "submit" input type. In particular, what should go in place of the ???
below:
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"})
Upvotes: 1
Views: 282
Reputation: 239420
The submit input type only passes a value to the request if it's named. So all you need to do is something like:
...
<input type="submit" name="_submit" value="123456">
...
It will then be available in the request as '_submit' (or whatever you want to call it).
Upvotes: 3