mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-09 08:00:52 +03:00
Merge pull request #1076 from edmondwong/master
Allow OPTIONS to retrieve PUT field metadata on empty objects
This commit is contained in:
commit
196a895fe4
|
@ -356,8 +356,15 @@ class GenericAPIView(views.APIView):
|
||||||
self.check_permissions(cloned_request)
|
self.check_permissions(cloned_request)
|
||||||
# Test object permissions
|
# Test object permissions
|
||||||
if method == 'PUT':
|
if method == 'PUT':
|
||||||
self.get_object()
|
try:
|
||||||
except (exceptions.APIException, PermissionDenied, Http404):
|
self.get_object()
|
||||||
|
except Http404:
|
||||||
|
# Http404 should be acceptable and the serializer
|
||||||
|
# metadata should be populated. Except this so the
|
||||||
|
# outer "else" clause of the try-except-else block
|
||||||
|
# will be executed.
|
||||||
|
pass
|
||||||
|
except (exceptions.APIException, PermissionDenied):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
# If user has appropriate permissions for the view, include
|
# If user has appropriate permissions for the view, include
|
||||||
|
|
|
@ -272,6 +272,48 @@ class TestInstanceView(TestCase):
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
self.assertEqual(response.data, expected)
|
self.assertEqual(response.data, expected)
|
||||||
|
|
||||||
|
def test_options_before_instance_create(self):
|
||||||
|
"""
|
||||||
|
OPTIONS requests to RetrieveUpdateDestroyAPIView should return metadata
|
||||||
|
before the instance has been created
|
||||||
|
"""
|
||||||
|
request = factory.options('/999')
|
||||||
|
with self.assertNumQueries(1):
|
||||||
|
response = self.view(request, pk=999).render()
|
||||||
|
expected = {
|
||||||
|
'parses': [
|
||||||
|
'application/json',
|
||||||
|
'application/x-www-form-urlencoded',
|
||||||
|
'multipart/form-data'
|
||||||
|
],
|
||||||
|
'renders': [
|
||||||
|
'application/json',
|
||||||
|
'text/html'
|
||||||
|
],
|
||||||
|
'name': 'Instance',
|
||||||
|
'description': 'Example description for OPTIONS.',
|
||||||
|
'actions': {
|
||||||
|
'PUT': {
|
||||||
|
'text': {
|
||||||
|
'max_length': 100,
|
||||||
|
'read_only': False,
|
||||||
|
'required': True,
|
||||||
|
'type': 'string',
|
||||||
|
'label': 'Text comes here',
|
||||||
|
'help_text': 'Text description.'
|
||||||
|
},
|
||||||
|
'id': {
|
||||||
|
'read_only': True,
|
||||||
|
'required': False,
|
||||||
|
'type': 'integer',
|
||||||
|
'label': 'ID',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
self.assertEqual(response.data, expected)
|
||||||
|
|
||||||
def test_get_instance_view_incorrect_arg(self):
|
def test_get_instance_view_incorrect_arg(self):
|
||||||
"""
|
"""
|
||||||
GET requests with an incorrect pk type, should raise 404, not 500.
|
GET requests with an incorrect pk type, should raise 404, not 500.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user