mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 20:40:14 +03:00
Merge 8843193ac6
into 48b66ec2a2
This commit is contained in:
commit
0798898ef1
|
@ -388,10 +388,11 @@ class GenericAPIView(views.APIView):
|
||||||
if method not in self.allowed_methods:
|
if method not in self.allowed_methods:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
cloned_request = clone_request(request, method)
|
original_request = clone_request(request, request.method)
|
||||||
|
self.request = clone_request(request, method)
|
||||||
try:
|
try:
|
||||||
# Test global permissions
|
# Test global permissions
|
||||||
self.check_permissions(cloned_request)
|
self.check_permissions(self.request)
|
||||||
# Test object permissions
|
# Test object permissions
|
||||||
if method == 'PUT':
|
if method == 'PUT':
|
||||||
try:
|
try:
|
||||||
|
@ -409,6 +410,7 @@ class GenericAPIView(views.APIView):
|
||||||
# appropriate metadata about the fields that should be supplied.
|
# appropriate metadata about the fields that should be supplied.
|
||||||
serializer = self.get_serializer()
|
serializer = self.get_serializer()
|
||||||
actions[method] = serializer.metadata()
|
actions[method] = serializer.metadata()
|
||||||
|
self.request = original_request
|
||||||
|
|
||||||
if actions:
|
if actions:
|
||||||
ret['actions'] = actions
|
ret['actions'] = actions
|
||||||
|
|
|
@ -43,7 +43,6 @@ def main():
|
||||||
test_module_name = 'rest_framework.tests'
|
test_module_name = 'rest_framework.tests'
|
||||||
if django.VERSION[0] == 1 and django.VERSION[1] < 6:
|
if django.VERSION[0] == 1 and django.VERSION[1] < 6:
|
||||||
test_module_name = 'tests'
|
test_module_name = 'tests'
|
||||||
|
|
||||||
failures = test_runner.run_tests([test_module_name + test_case])
|
failures = test_runner.run_tests([test_module_name + test_case])
|
||||||
|
|
||||||
sys.exit(failures)
|
sys.exit(failures)
|
||||||
|
|
|
@ -681,3 +681,31 @@ class TestFilterBackendAppliedToViews(TestCase):
|
||||||
response = view(request).render()
|
response = view(request).render()
|
||||||
self.assertContains(response, 'field_b')
|
self.assertContains(response, 'field_b')
|
||||||
self.assertNotContains(response, 'field_a')
|
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': 'string',
|
||||||
|
'required': True,
|
||||||
|
'read_only': False,
|
||||||
|
'label': 'field b',
|
||||||
|
'max_length': 100
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
self.assertEqual(response.data, expected)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user