Opened 15 years ago
Closed 15 years ago
#7924 closed (invalid)
test client's post method does not actually post if no data or an empty dict is given
Reported by: | Tobias McNulty | Owned by: | nobody |
---|---|---|---|
Component: | Testing framework | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
from django.test.client import Client c = Client() c.post(reverse('my_view'))
in my_view, request.POST is false! I have to pass in bogus data, like {'a': 'b'} to force it to post. Posting empty data is useful in cases were the action and all necessary meta data are included in the URL, and you just want to "confirm" that the user wants to proceed.
Change History (3)
comment:1 Changed 15 years ago by
comment:3 Changed 15 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
That is your problem, you are checking for the contents of the request.POST dictionary instead of checking the method of the request. The correct way to do the test would be:
if request.method == 'POST': pass
Note: See
TracTickets for help on using
tickets.
How are you testing whether the method is POST in the view?