mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-11 04:07:39 +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)
|
||||
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)
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue
Block a user