test's client.post says post but request.method says GET

6 views
Skip to first unread message

Phlip

unread,
Jul 29, 2010, 8:18:10 PM7/29/10
to Django users
Django aficionados:

Here's my test code:

from django.test.client import Client
self.client = Client()
from django.core.files.base import ContentFile
file_content = ContentFile(sample_inventory_update_cvs())
file_content.name = 'response.csv'

response = self.client.post( self.url,
data={'csv_file':file_content} )

Disregard all that ContentFile nonsense (unless it's causing the bug).

Inside the action code, I want to distinguish GETting from POSTing.
One paints the page and the other absorbs new form data, as usual.

However, when I print request.method, I get GET.

Is this a bug in Client? or in (ahem) my comprehension?

--
Phlip
http://c2.com/cgi/wiki?ZeekLand

Phlip

unread,
Jul 29, 2010, 8:21:36 PM7/29/10
to Django users
forgot to mention Django 1.1.2

Daniel Roseman

unread,
Jul 30, 2010, 4:33:13 AM7/30/10
to Django users
What's the value of `self.url`? One possibility is that it doesn't end
with a slash, and you have the APPEND_SLASH setting set to True (the
default), so Django is redirecting from '/foo' to '/foo/'. A
redirected POST ends up as a GET.
--
DR.

Phlip

unread,
Jul 30, 2010, 6:28:36 AM7/30/10
to Django users
> What's the value of `self.url`? One possibility is that it doesn't end
> with a slash

Ends with a slash. I'm now checking the response goodies, like
response.status, to see if any other redirections happen!

Phlip

unread,
Jul 30, 2010, 11:22:40 AM7/30/10
to Django users
Yup - a redirect. My colleagues left SSL turned on. I won't ask how to
mock it in a test I'l just turn it off...
Reply all
Reply to author
Forward
0 new messages