Correctly propagate cloned_request for OPTIONS

Update to fix pending changes in #1507
This commit is contained in:
José Padilla 2014-09-23 21:12:58 -04:00
parent 8495cd898a
commit e8c01ecdab
2 changed files with 44 additions and 2 deletions

View File

@ -398,10 +398,11 @@ class GenericAPIView(views.APIView):
if method not in self.allowed_methods:
continue
cloned_request = clone_request(request, method)
original_request = self.request
self.request = clone_request(request, method)
try:
# Test global permissions
self.check_permissions(cloned_request)
self.check_permissions(self.request)
# Test object permissions
if method == 'PUT':
try:
@ -419,6 +420,8 @@ class GenericAPIView(views.APIView):
# appropriate metadata about the fields that should be supplied.
serializer = self.get_serializer()
actions[method] = serializer.metadata()
finally:
self.request = original_request
if actions:
ret['actions'] = actions

View File

@ -681,3 +681,42 @@ class TestFilterBackendAppliedToViews(TestCase):
response = view(request).render()
self.assertContains(response, 'field_b')
self.assertNotContains(response, 'field_a')
def test_options_with_dynamic_serializer(self):
"""
Ensure that OPTIONS returns correct POST json schema:
DynamicSerializer with single field 'field_b'
"""
request = factory.options('/')
view = DynamicSerializerView.as_view()
with self.assertNumQueries(0):
response = view(request).render()
expected = {
'name': 'Dynamic Serializer',
'description': '',
'renders': [
'text/html',
'application/json'
],
'parses': [
'application/json',
'application/x-www-form-urlencoded',
'multipart/form-data'
],
'actions': {
'POST': {
'field_b': {
'type': u'string',
'required': True,
'read_only': False,
'label': u'field b',
'max_length': 100
}
}
}
}
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data, expected)