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
0e5d26fa
Commit
0e5d26fa
authored
Jun 22, 2017
by
Venelin Stoykov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed #5228 Set ViewSet args/kwargs/request before dispatch
parent
506ec859
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
0 deletions
+27
-0
rest_framework/viewsets.py
+4
-0
tests/test_viewsets.py
+23
-0
No files found.
rest_framework/viewsets.py
View file @
0e5d26fa
...
@@ -82,6 +82,10 @@ class ViewSetMixin(object):
...
@@ -82,6 +82,10 @@ class ViewSetMixin(object):
if
hasattr
(
self
,
'get'
)
and
not
hasattr
(
self
,
'head'
):
if
hasattr
(
self
,
'get'
)
and
not
hasattr
(
self
,
'head'
):
self
.
head
=
self
.
get
self
.
head
=
self
.
get
self
.
request
=
request
self
.
args
=
args
self
.
kwargs
=
kwargs
# And continue as usual
# And continue as usual
return
self
.
dispatch
(
request
,
*
args
,
**
kwargs
)
return
self
.
dispatch
(
request
,
*
args
,
**
kwargs
)
...
...
tests/test_viewsets.py
View file @
0e5d26fa
...
@@ -13,6 +13,15 @@ class BasicViewSet(GenericViewSet):
...
@@ -13,6 +13,15 @@ class BasicViewSet(GenericViewSet):
return
Response
({
'ACTION'
:
'LIST'
})
return
Response
({
'ACTION'
:
'LIST'
})
class
InstanceViewSet
(
GenericViewSet
):
def
dispatch
(
self
,
request
,
*
args
,
**
kwargs
):
return
self
.
dummy
(
request
,
*
args
,
**
kwargs
)
def
dummy
(
self
,
request
,
*
args
,
**
kwargs
):
return
Response
({
'view'
:
self
})
class
InitializeViewSetsTestCase
(
TestCase
):
class
InitializeViewSetsTestCase
(
TestCase
):
def
test_initialize_view_set_with_actions
(
self
):
def
test_initialize_view_set_with_actions
(
self
):
request
=
factory
.
get
(
'/'
,
''
,
content_type
=
'application/json'
)
request
=
factory
.
get
(
'/'
,
''
,
content_type
=
'application/json'
)
...
@@ -42,3 +51,17 @@ class InitializeViewSetsTestCase(TestCase):
...
@@ -42,3 +51,17 @@ class InitializeViewSetsTestCase(TestCase):
"For example `.as_view({'get': 'list'})`"
)
"For example `.as_view({'get': 'list'})`"
)
else
:
else
:
self
.
fail
(
"actions must not be empty."
)
self
.
fail
(
"actions must not be empty."
)
def
test_args_kwargs_request_action_map_on_self
(
self
):
"""
Test a view only has args, kwargs, request, action_map
once `as_view` has been called.
"""
bare_view
=
InstanceViewSet
()
view
=
InstanceViewSet
.
as_view
(
actions
=
{
'get'
:
'dummy'
,
})(
factory
.
get
(
'/'
))
.
data
[
'view'
]
for
attribute
in
(
'args'
,
'kwargs'
,
'request'
,
'action_map'
):
self
.
assertNotIn
(
attribute
,
dir
(
bare_view
))
self
.
assertIn
(
attribute
,
dir
(
view
))
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