Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
6b3500b6
Commit
6b3500b6
authored
Oct 24, 2013
by
alexanderlukanin13
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed UnicodeEncodeError when POST JSON via web interface; added test
parent
f92d8bd9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
2 deletions
+32
-2
rest_framework/request.py
+1
-1
rest_framework/tests/test_request.py
+31
-1
No files found.
rest_framework/request.py
View file @
6b3500b6
...
@@ -334,7 +334,7 @@ class Request(object):
...
@@ -334,7 +334,7 @@ class Request(object):
self
.
_CONTENT_PARAM
in
self
.
_data
and
self
.
_CONTENT_PARAM
in
self
.
_data
and
self
.
_CONTENTTYPE_PARAM
in
self
.
_data
):
self
.
_CONTENTTYPE_PARAM
in
self
.
_data
):
self
.
_content_type
=
self
.
_data
[
self
.
_CONTENTTYPE_PARAM
]
self
.
_content_type
=
self
.
_data
[
self
.
_CONTENTTYPE_PARAM
]
self
.
_stream
=
BytesIO
(
self
.
_data
[
self
.
_CONTENT_PARAM
]
.
encode
(
HTTP_HEADER_ENCODING
))
self
.
_stream
=
BytesIO
(
self
.
_data
[
self
.
_CONTENT_PARAM
]
.
encode
(
self
.
parser_context
[
'encoding'
]
))
self
.
_data
,
self
.
_files
=
(
Empty
,
Empty
)
self
.
_data
,
self
.
_files
=
(
Empty
,
Empty
)
def
_parse
(
self
):
def
_parse
(
self
):
...
...
rest_framework/tests/test_request.py
View file @
6b3500b6
...
@@ -5,6 +5,7 @@ from __future__ import unicode_literals
...
@@ -5,6 +5,7 @@ from __future__ import unicode_literals
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.contrib.auth
import
authenticate
,
login
,
logout
from
django.contrib.auth
import
authenticate
,
login
,
logout
from
django.contrib.sessions.middleware
import
SessionMiddleware
from
django.contrib.sessions.middleware
import
SessionMiddleware
from
django.core.handlers.wsgi
import
WSGIRequest
from
django.test
import
TestCase
from
django.test
import
TestCase
from
rest_framework
import
status
from
rest_framework
import
status
from
rest_framework.authentication
import
SessionAuthentication
from
rest_framework.authentication
import
SessionAuthentication
...
@@ -15,12 +16,13 @@ from rest_framework.parsers import (
...
@@ -15,12 +16,13 @@ from rest_framework.parsers import (
MultiPartParser
,
MultiPartParser
,
JSONParser
JSONParser
)
)
from
rest_framework.request
import
Request
from
rest_framework.request
import
Request
,
Empty
from
rest_framework.response
import
Response
from
rest_framework.response
import
Response
from
rest_framework.settings
import
api_settings
from
rest_framework.settings
import
api_settings
from
rest_framework.test
import
APIRequestFactory
,
APIClient
from
rest_framework.test
import
APIRequestFactory
,
APIClient
from
rest_framework.views
import
APIView
from
rest_framework.views
import
APIView
from
rest_framework.compat
import
six
from
rest_framework.compat
import
six
from
io
import
BytesIO
import
json
import
json
...
@@ -146,6 +148,34 @@ class TestContentParsing(TestCase):
...
@@ -146,6 +148,34 @@ class TestContentParsing(TestCase):
request
.
parsers
=
(
JSONParser
(),
)
request
.
parsers
=
(
JSONParser
(),
)
self
.
assertEqual
(
request
.
DATA
,
json_data
)
self
.
assertEqual
(
request
.
DATA
,
json_data
)
def
test_form_POST_unicode
(
self
):
"""
JSON POST via default web interface with unicode data
"""
# Note: environ and other variables here have simplified content compared to real Request
CONTENT
=
b
'_content_type=application
%2
Fjson&_content=
%7
B
%22
request
%22%3
A+4
%2
C+
%22
firm
%22%3
A+1
%2
C+
%22
text
%22%3
A+
%22%
D0
%9
F
%
D1
%80%
D0
%
B8
%
D0
%
B2
%
D0
%
B5
%
D1
%82%21%22%7
D'
environ
=
{
'REQUEST_METHOD'
:
'POST'
,
'CONTENT_TYPE'
:
'application/x-www-form-urlencoded'
,
'CONTENT_LENGTH'
:
len
(
CONTENT
),
'wsgi.input'
:
BytesIO
(
CONTENT
),
}
wsgi_request
=
WSGIRequest
(
environ
=
environ
)
wsgi_request
.
_load_post_and_files
()
parsers
=
(
JSONParser
(),
FormParser
(),
MultiPartParser
())
parser_context
=
{
'encoding'
:
'utf-8'
,
'kwargs'
:
{},
'args'
:
(),
}
request
=
Request
(
wsgi_request
,
parsers
=
parsers
,
parser_context
=
parser_context
)
method
=
request
.
method
self
.
assertEqual
(
method
,
'POST'
)
self
.
assertEqual
(
request
.
_content_type
,
'application/json'
)
self
.
assertEqual
(
request
.
_stream
.
getvalue
(),
b
'{"request": 4, "firm": 1, "text": "
\xd0\x9f\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82
!"}'
)
self
.
assertEqual
(
request
.
_data
,
Empty
)
self
.
assertEqual
(
request
.
_files
,
Empty
)
# def test_accessing_post_after_data_form(self):
# def test_accessing_post_after_data_form(self):
# """
# """
# Ensures request.POST can be accessed after request.DATA in
# Ensures request.POST can be accessed after request.DATA in
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment