mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-09 23:04:47 +03:00
Test case should ensure view.request exists.
This commit is contained in:
parent
30bad6a453
commit
65f552d880
|
@ -263,19 +263,18 @@ class SchemaGenerator(object):
|
|||
if method not in ('PUT', 'PATCH', 'POST'):
|
||||
return []
|
||||
|
||||
if not hasattr(view, 'get_serializer_class'):
|
||||
if not hasattr(view, 'get_serializer'):
|
||||
return []
|
||||
|
||||
fields = []
|
||||
|
||||
serializer = view.get_serializer()
|
||||
|
||||
if isinstance(serializer, serializers.ListSerializer):
|
||||
return coreapi.Field(name='data', location='body', required=True)
|
||||
return [coreapi.Field(name='data', location='body', required=True)]
|
||||
|
||||
if not isinstance(serializer, serializers.Serializer):
|
||||
return []
|
||||
|
||||
fields = []
|
||||
for field in serializer.fields.values():
|
||||
if field.read_only:
|
||||
continue
|
||||
|
|
|
@ -43,6 +43,10 @@ class ExampleViewSet(ModelViewSet):
|
|||
def custom_action(self, request, pk):
|
||||
return super(ExampleSerializer, self).retrieve(self, request)
|
||||
|
||||
def get_serializer(self, *args, **kwargs):
|
||||
assert self.request
|
||||
return super(ExampleViewSet, self).get_serializer(*args, **kwargs)
|
||||
|
||||
|
||||
class ExampleView(APIView):
|
||||
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
|
||||
|
|
Loading…
Reference in New Issue
Block a user