Commit 7218bcba by Tom Christie

Add test for non-GET methods to api_view decorator

parent 2a89cb4f
...@@ -379,7 +379,8 @@ class HyperlinkedIdentityField(Field): ...@@ -379,7 +379,8 @@ class HyperlinkedIdentityField(Field):
A field that represents the model's identity using a hyperlink. A field that represents the model's identity using a hyperlink.
""" """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
# TODO: Make this mandatory # TODO: Make this mandatory, and have the HyperlinkedModelSerializer
# set it on-the-fly
self.view_name = kwargs.pop('view_name', None) self.view_name = kwargs.pop('view_name', None)
super(HyperlinkedIdentityField, self).__init__(*args, **kwargs) super(HyperlinkedIdentityField, self).__init__(*args, **kwargs)
......
...@@ -49,6 +49,20 @@ class DecoratorTestCase(TestCase): ...@@ -49,6 +49,20 @@ class DecoratorTestCase(TestCase):
response = view(request) response = view(request)
self.assertEqual(response.status_code, 405) self.assertEqual(response.status_code, 405)
def test_calling_put_method(self):
@api_view(['GET', 'PUT'])
def view(request):
return Response({})
request = self.factory.put('/')
response = view(request)
self.assertEqual(response.status_code, 200)
request = self.factory.post('/')
response = view(request)
self.assertEqual(response.status_code, 405)
def test_renderer_classes(self): def test_renderer_classes(self):
@api_view(['GET']) @api_view(['GET'])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment