File tree Expand file tree Collapse file tree 2 files changed +44
-2
lines changed Expand file tree Collapse file tree 2 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -398,10 +398,11 @@ def metadata(self, request):
398
398
if method not in self .allowed_methods :
399
399
continue
400
400
401
- cloned_request = clone_request (request , method )
401
+ original_request = self .request
402
+ self .request = clone_request (request , method )
402
403
try :
403
404
# Test global permissions
404
- self .check_permissions (cloned_request )
405
+ self .check_permissions (self . request )
405
406
# Test object permissions
406
407
if method == 'PUT' :
407
408
try :
@@ -419,6 +420,8 @@ def metadata(self, request):
419
420
# appropriate metadata about the fields that should be supplied.
420
421
serializer = self .get_serializer ()
421
422
actions [method ] = serializer .metadata ()
423
+ finally :
424
+ self .request = original_request
422
425
423
426
if actions :
424
427
ret ['actions' ] = actions
Original file line number Diff line number Diff line change @@ -681,3 +681,42 @@ def test_dynamic_serializer_form_in_browsable_api(self):
681
681
response = view (request ).render ()
682
682
self .assertContains (response , 'field_b' )
683
683
self .assertNotContains (response , 'field_a' )
684
+
685
+ def test_options_with_dynamic_serializer (self ):
686
+ """
687
+ Ensure that OPTIONS returns correct POST json schema:
688
+ DynamicSerializer with single field 'field_b'
689
+ """
690
+ request = factory .options ('/' )
691
+ view = DynamicSerializerView .as_view ()
692
+
693
+ with self .assertNumQueries (0 ):
694
+ response = view (request ).render ()
695
+
696
+ expected = {
697
+ 'name' : 'Dynamic Serializer' ,
698
+ 'description' : '' ,
699
+ 'renders' : [
700
+ 'text/html' ,
701
+ 'application/json'
702
+ ],
703
+ 'parses' : [
704
+ 'application/json' ,
705
+ 'application/x-www-form-urlencoded' ,
706
+ 'multipart/form-data'
707
+ ],
708
+ 'actions' : {
709
+ 'POST' : {
710
+ 'field_b' : {
711
+ 'type' : u'string' ,
712
+ 'required' : True ,
713
+ 'read_only' : False ,
714
+ 'label' : u'field b' ,
715
+ 'max_length' : 100
716
+ }
717
+ }
718
+ }
719
+ }
720
+
721
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
722
+ self .assertEqual (response .data , expected )
You can’t perform that action at this time.
0 commit comments