Opened 8 years ago

Closed 8 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: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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 8 years ago by Alex Gaynor

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

comment:2 Changed 8 years ago by Tobias McNulty

if request.POST:
    do_stuff()

comment:3 Changed 8 years ago by Alex Gaynor

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