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
3b466fab
Commit
3b466fab
authored
Mar 13, 2017
by
Tom Christie
Committed by
GitHub
Mar 13, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4973 from tomchristie/support-head-in-viewsets
Support HEAD in viewsets
parents
e94011eb
43b38964
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 @
3b466fab
...
...
@@ -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 @
3b466fab
...
...
@@ -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 @
3b466fab
...
...
@@ -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