Add test for non-GET methods to api_view decorator

This commit is contained in:
Tom Christie 2012-10-05 15:55:45 +01:00
parent 2a89cb4fb7
commit 7218bcbade
2 changed files with 16 additions and 1 deletions

View File

@ -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)

View File

@ -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'])