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
54d82f59
Commit
54d82f59
authored
Feb 09, 2015
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Py3 compat fix
parent
d13c8076
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
4 deletions
+24
-4
rest_framework/request.py
+4
-4
tests/test_request.py
+20
-0
No files found.
rest_framework/request.py
View file @
54d82f59
...
@@ -12,9 +12,9 @@ from __future__ import unicode_literals
...
@@ -12,9 +12,9 @@ from __future__ import unicode_literals
from
django.conf
import
settings
from
django.conf
import
settings
from
django.http
import
QueryDict
from
django.http
import
QueryDict
from
django.http.multipartparser
import
parse_header
from
django.http.multipartparser
import
parse_header
from
django.utils
import
six
from
django.utils.datastructures
import
MultiValueDict
from
django.utils.datastructures
import
MultiValueDict
from
django.utils.datastructures
import
MergeDict
as
DjangoMergeDict
from
django.utils.datastructures
import
MergeDict
as
DjangoMergeDict
from
django.utils.six
import
BytesIO
from
rest_framework
import
HTTP_HEADER_ENCODING
from
rest_framework
import
HTTP_HEADER_ENCODING
from
rest_framework
import
exceptions
from
rest_framework
import
exceptions
from
rest_framework.settings
import
api_settings
from
rest_framework.settings
import
api_settings
...
@@ -363,7 +363,7 @@ class Request(object):
...
@@ -363,7 +363,7 @@ class Request(object):
elif
hasattr
(
self
.
_request
,
'read'
):
elif
hasattr
(
self
.
_request
,
'read'
):
self
.
_stream
=
self
.
_request
self
.
_stream
=
self
.
_request
else
:
else
:
self
.
_stream
=
BytesIO
(
self
.
raw_post_data
)
self
.
_stream
=
six
.
BytesIO
(
self
.
raw_post_data
)
def
_perform_form_overloading
(
self
):
def
_perform_form_overloading
(
self
):
"""
"""
...
@@ -405,7 +405,7 @@ class Request(object):
...
@@ -405,7 +405,7 @@ class Request(object):
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
(
self
.
parser_context
[
'encoding'
]))
self
.
_stream
=
six
.
BytesIO
(
self
.
_data
[
self
.
_CONTENT_PARAM
]
.
encode
(
self
.
parser_context
[
'encoding'
]))
self
.
_data
,
self
.
_files
,
self
.
_full_data
=
(
Empty
,
Empty
,
Empty
)
self
.
_data
,
self
.
_files
,
self
.
_full_data
=
(
Empty
,
Empty
,
Empty
)
def
_parse
(
self
):
def
_parse
(
self
):
...
@@ -498,4 +498,4 @@ class Request(object):
...
@@ -498,4 +498,4 @@ class Request(object):
try
:
try
:
return
getattr
(
self
.
_request
,
attr
)
return
getattr
(
self
.
_request
,
attr
)
except
AttributeError
:
except
AttributeError
:
raise
info
[
0
],
info
[
1
],
info
[
2
]
.
tb_next
six
.
reraise
(
info
[
0
],
info
[
1
],
info
[
2
]
.
tb_next
)
tests/test_request.py
View file @
54d82f59
...
@@ -249,6 +249,26 @@ class TestUserSetter(TestCase):
...
@@ -249,6 +249,26 @@ class TestUserSetter(TestCase):
login
(
self
.
request
,
self
.
user
)
login
(
self
.
request
,
self
.
user
)
self
.
assertEqual
(
self
.
wrapped_request
.
user
,
self
.
user
)
self
.
assertEqual
(
self
.
wrapped_request
.
user
,
self
.
user
)
def
test_calling_user_fails_when_attribute_error_is_raised
(
self
):
"""
This proves that when an AttributeError is raised inside of the request.user
property, that we can handle this and report the true, underlying error.
"""
class
AuthRaisesAttributeError
(
object
):
def
authenticate
(
self
,
request
):
import
rest_framework
rest_framework
.
MISSPELLED_NAME_THAT_DOESNT_EXIST
self
.
request
=
Request
(
factory
.
get
(
'/'
),
authenticators
=
(
AuthRaisesAttributeError
(),))
SessionMiddleware
()
.
process_request
(
self
.
request
)
login
(
self
.
request
,
self
.
user
)
try
:
self
.
request
.
user
except
AttributeError
as
error
:
self
.
assertEqual
(
str
(
error
),
"'module' object has no attribute 'MISSPELLED_NAME_THAT_DOESNT_EXIST'"
)
else
:
assert
False
,
'AttributeError not raised'
class
TestAuthSetter
(
TestCase
):
class
TestAuthSetter
(
TestCase
):
...
...
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