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
43b38964
Commit
43b38964
authored
Mar 13, 2017
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support HEAD in viewsets
parent
df2adbb4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
0 deletions
+21
-0
rest_framework/viewsets.py
+3
-0
tests/test_generics.py
+9
-0
tests/test_viewsets.py
+9
-0
No files found.
rest_framework/viewsets.py
View file @
43b38964
...
...
@@ -79,6 +79,9 @@ class ViewSetMixin(object):
handler
=
getattr
(
self
,
action
)
setattr
(
self
,
method
,
handler
)
if
hasattr
(
self
,
'get'
)
and
not
hasattr
(
self
,
'head'
):
self
.
head
=
self
.
get
# And continue as usual
return
self
.
dispatch
(
request
,
*
args
,
**
kwargs
)
...
...
tests/test_generics.py
View file @
43b38964
...
...
@@ -101,6 +101,15 @@ class TestRootView(TestCase):
assert
response
.
status_code
==
status
.
HTTP_200_OK
assert
response
.
data
==
self
.
data
def
test_head_root_view
(
self
):
"""
HEAD requests to ListCreateAPIView should return 200.
"""
request
=
factory
.
head
(
'/'
)
with
self
.
assertNumQueries
(
1
):
response
=
self
.
view
(
request
)
.
render
()
assert
response
.
status_code
==
status
.
HTTP_200_OK
def
test_post_root_view
(
self
):
"""
POST requests to ListCreateAPIView should create a new object.
...
...
tests/test_viewsets.py
View file @
43b38964
...
...
@@ -24,6 +24,15 @@ class InitializeViewSetsTestCase(TestCase):
assert
response
.
status_code
==
status
.
HTTP_200_OK
assert
response
.
data
==
{
'ACTION'
:
'LIST'
}
def
testhead_request_against_viewset
(
self
):
request
=
factory
.
head
(
'/'
,
''
,
content_type
=
'application/json'
)
my_view
=
BasicViewSet
.
as_view
(
actions
=
{
'get'
:
'list'
,
})
response
=
my_view
(
request
)
assert
response
.
status_code
==
status
.
HTTP_200_OK
def
test_initialize_view_set_with_empty_actions
(
self
):
try
:
BasicViewSet
.
as_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