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 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:


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

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

comment:2 Changed 8 years ago by tobias

if request.POST:

comment:3 Changed 8 years ago by Alex

  • Resolution set to invalid
  • Status changed from new to 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':
Note: See TracTickets for help on using tickets.
Back to Top