mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-26 19:43:59 +03:00
Merge pull request #4973 from tomchristie/support-head-in-viewsets
Support HEAD in viewsets
This commit is contained in:
commit
3b466fabe7
|
@ -79,6 +79,9 @@ class ViewSetMixin(object):
|
||||||
handler = getattr(self, action)
|
handler = getattr(self, action)
|
||||||
setattr(self, method, handler)
|
setattr(self, method, handler)
|
||||||
|
|
||||||
|
if hasattr(self, 'get') and not hasattr(self, 'head'):
|
||||||
|
self.head = self.get
|
||||||
|
|
||||||
# And continue as usual
|
# And continue as usual
|
||||||
return self.dispatch(request, *args, **kwargs)
|
return self.dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -101,6 +101,15 @@ class TestRootView(TestCase):
|
||||||
assert response.status_code == status.HTTP_200_OK
|
assert response.status_code == status.HTTP_200_OK
|
||||||
assert response.data == self.data
|
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):
|
def test_post_root_view(self):
|
||||||
"""
|
"""
|
||||||
POST requests to ListCreateAPIView should create a new object.
|
POST requests to ListCreateAPIView should create a new object.
|
||||||
|
|
|
@ -24,6 +24,15 @@ class InitializeViewSetsTestCase(TestCase):
|
||||||
assert response.status_code == status.HTTP_200_OK
|
assert response.status_code == status.HTTP_200_OK
|
||||||
assert response.data == {'ACTION': 'LIST'}
|
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):
|
def test_initialize_view_set_with_empty_actions(self):
|
||||||
try:
|
try:
|
||||||
BasicViewSet.as_view()
|
BasicViewSet.as_view()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user