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
e8c01ecd
Commit
e8c01ecd
authored
Sep 23, 2014
by
José Padilla
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Correctly propagate cloned_request for OPTIONS
Update to fix pending changes in #1507
parent
8495cd89
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
2 deletions
+44
-2
rest_framework/generics.py
+5
-2
tests/test_generics.py
+39
-0
No files found.
rest_framework/generics.py
View file @
e8c01ecd
...
@@ -398,10 +398,11 @@ class GenericAPIView(views.APIView):
...
@@ -398,10 +398,11 @@ class GenericAPIView(views.APIView):
if
method
not
in
self
.
allowed_methods
:
if
method
not
in
self
.
allowed_methods
:
continue
continue
cloned_request
=
clone_request
(
request
,
method
)
original_request
=
self
.
request
self
.
request
=
clone_request
(
request
,
method
)
try
:
try
:
# Test global permissions
# Test global permissions
self
.
check_permissions
(
cloned_
request
)
self
.
check_permissions
(
self
.
request
)
# Test object permissions
# Test object permissions
if
method
==
'PUT'
:
if
method
==
'PUT'
:
try
:
try
:
...
@@ -419,6 +420,8 @@ class GenericAPIView(views.APIView):
...
@@ -419,6 +420,8 @@ class GenericAPIView(views.APIView):
# appropriate metadata about the fields that should be supplied.
# appropriate metadata about the fields that should be supplied.
serializer
=
self
.
get_serializer
()
serializer
=
self
.
get_serializer
()
actions
[
method
]
=
serializer
.
metadata
()
actions
[
method
]
=
serializer
.
metadata
()
finally
:
self
.
request
=
original_request
if
actions
:
if
actions
:
ret
[
'actions'
]
=
actions
ret
[
'actions'
]
=
actions
...
...
tests/test_generics.py
View file @
e8c01ecd
...
@@ -681,3 +681,42 @@ class TestFilterBackendAppliedToViews(TestCase):
...
@@ -681,3 +681,42 @@ class TestFilterBackendAppliedToViews(TestCase):
response
=
view
(
request
)
.
render
()
response
=
view
(
request
)
.
render
()
self
.
assertContains
(
response
,
'field_b'
)
self
.
assertContains
(
response
,
'field_b'
)
self
.
assertNotContains
(
response
,
'field_a'
)
self
.
assertNotContains
(
response
,
'field_a'
)
def
test_options_with_dynamic_serializer
(
self
):
"""
Ensure that OPTIONS returns correct POST json schema:
DynamicSerializer with single field 'field_b'
"""
request
=
factory
.
options
(
'/'
)
view
=
DynamicSerializerView
.
as_view
()
with
self
.
assertNumQueries
(
0
):
response
=
view
(
request
)
.
render
()
expected
=
{
'name'
:
'Dynamic Serializer'
,
'description'
:
''
,
'renders'
:
[
'text/html'
,
'application/json'
],
'parses'
:
[
'application/json'
,
'application/x-www-form-urlencoded'
,
'multipart/form-data'
],
'actions'
:
{
'POST'
:
{
'field_b'
:
{
'type'
:
u'string'
,
'required'
:
True
,
'read_only'
:
False
,
'label'
:
u'field b'
,
'max_length'
:
100
}
}
}
}
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEqual
(
response
.
data
,
expected
)
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