#20574: Django Client Put Method Data is not Send
-----------------------------------+-------------------------------------
Reporter: edwinlunando | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 1.5
Severity: Normal | Keywords: Test, Client, Put, Data
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+-------------------------------------
I want to test my REST API like this:
{{{
data = {
'access_token': access_token.token
}
response = self.client.put(reverse('api:update_user'), data)
}}}
The question is, how can I access my data or query string at request
object from my view? request.POST, request.GET, request.body, and
request.META QUERY_STRING is empty. After I looked into the client put
code like this.
{{{
def put(self, path, data='', content_type='application/octet-stream',
**extra):
"Construct a PUT request."
return self.generic('PUT', path, data, content_type, **extra)
def generic(self, method, path,
data='', content_type='application/octet-stream',
**extra):
parsed = urlparse(path)
data = force_bytes(data, settings.DEFAULT_CHARSET)
r = {
'PATH_INFO': self._get_path(parsed),
'QUERY_STRING': force_str(parsed[4]),
'REQUEST_METHOD': str(method),
}
if data:
r.update({
'CONTENT_LENGTH': len(data),
'CONTENT_TYPE': str(content_type),
'wsgi.input': FakePayload(data),
})
r.update(extra)
return self.request(**r)
}}}
The data parameter is not added to query string like get method like.
{{{
def get(self, path, data={}, **extra):
"Construct a GET request."
parsed = urlparse(path)
r = {
'CONTENT_TYPE': str('text/html; charset=utf-8'),
'PATH_INFO': self._get_path(parsed),
'QUERY_STRING': urlencode(data, doseq=True) or
force_str(parsed[4]),
'REQUEST_METHOD': str('GET'),
}
r.update(extra)
return self.request(**r)
}}}
So, I think the PUT and DELETE method should behave the same like GET and
POST method at client. The "'QUERY_STRING': urlencode(data, doseq=True)
or force_str(parsed[4])," should be used at PUT and DELETE method.
--
Ticket URL: <https://code.djangoproject.com/ticket/20574>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/055.cc8d8036ecc1ea60d004de2996fcb88f%40djangoproject.com?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.