Opened 16 years ago

Closed 16 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


from django.test.client import Client
c = Client()'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 by Alex Gaynor, 16 years ago

How are you testing whether the method is POST in the view?

comment:2 by Tobias McNulty, 16 years ago

if request.POST:

comment:3 by Alex Gaynor, 16 years ago

Resolution: invalid
Status: newclosed

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':
Note: See TracTickets for help on using tickets.
Back to Top