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
53f52765
Commit
53f52765
authored
Dec 02, 2014
by
BrickXu
Committed by
xulei
Dec 02, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Not allow to pass an empty actions to viewset.as_view(). Refs issue #2171
parent
81870b6e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
0 deletions
+41
-0
rest_framework/viewsets.py
+6
-0
tests/test_viewsets.py
+35
-0
No files found.
rest_framework/viewsets.py
View file @
53f52765
...
...
@@ -48,6 +48,12 @@ class ViewSetMixin(object):
# eg. 'List' or 'Instance'.
cls
.
suffix
=
None
# actions must not be empty
if
not
actions
:
raise
TypeError
(
"The `actions` argument must be provided when "
"calling `.as_view()` on a ViewSet. For example "
"`.as_view({'get': 'list'})`"
)
# sanitize keyword arguments
for
key
in
initkwargs
:
if
key
in
cls
.
http_method_names
:
...
...
tests/test_viewsets.py
0 → 100644
View file @
53f52765
from
django.test
import
TestCase
from
rest_framework
import
status
from
rest_framework.response
import
Response
from
rest_framework.test
import
APIRequestFactory
from
rest_framework.viewsets
import
GenericViewSet
factory
=
APIRequestFactory
()
class
BasicViewSet
(
GenericViewSet
):
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
return
Response
({
'ACTION'
:
'LIST'
})
class
InitializeViewSetsTestCase
(
TestCase
):
def
test_initialize_view_set_with_actions
(
self
):
request
=
factory
.
get
(
'/'
,
''
,
content_type
=
'application/json'
)
my_view
=
BasicViewSet
.
as_view
(
actions
=
{
'get'
:
'list'
,
})
response
=
my_view
(
request
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEqual
(
response
.
data
,
{
'ACTION'
:
'LIST'
})
def
test_initialize_view_set_with_empty_actions
(
self
):
try
:
BasicViewSet
.
as_view
()
except
TypeError
as
e
:
self
.
assertEqual
(
str
(
e
),
"The `actions` argument must be provided "
"when calling `.as_view()` on a ViewSet. "
"For example `.as_view({'get': 'list'})`"
)
else
:
self
.
fail
(
"actions must not be empty."
)
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