From dd2c3892b16da0feeb5370998c4d9dd2bd62c56f Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Thu, 5 Oct 2017 14:17:29 +0200 Subject: [PATCH] =?UTF-8?q?Have=20`is=5Flist=5Fview`=20recognise=20Retriev?= =?UTF-8?q?eModel=E2=80=A6=20views?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #5165 --- rest_framework/schemas/utils.py | 3 +++ tests/test_schemas.py | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/rest_framework/schemas/utils.py b/rest_framework/schemas/utils.py index 1542b6154b..76437a20a6 100644 --- a/rest_framework/schemas/utils.py +++ b/rest_framework/schemas/utils.py @@ -3,6 +3,7 @@ See schemas.__init__.py for package overview. """ +from rest_framework.mixins import RetrieveModelMixin def is_list_view(path, method, view): @@ -15,6 +16,8 @@ def is_list_view(path, method, view): if method.lower() != 'get': return False + if isinstance(view, RetrieveModelMixin): + return False path_components = path.strip('/').split('/') if path_components and '{' in path_components[-1]: return False diff --git a/tests/test_schemas.py b/tests/test_schemas.py index 6555a13b8c..901f4c6c56 100644 --- a/tests/test_schemas.py +++ b/tests/test_schemas.py @@ -19,6 +19,7 @@ AutoSchema, ManualSchema, SchemaGenerator, get_schema_view ) from rest_framework.schemas.generators import EndpointEnumerator +from rest_framework.schemas.utils import is_list_view from rest_framework.test import APIClient, APIRequestFactory from rest_framework.utils import formatting from rest_framework.views import APIView @@ -808,3 +809,15 @@ def test_from_router(self): with pytest.raises(ValueError): generator.get_schema() + + +def test_is_list_view_recognises_retrieve_view_subclasses(): + class TestView(generics.RetrieveAPIView): + pass + + path = '/looks/like/a/list/view/' + method = 'get' + view = TestView() + + is_list = is_list_view(path, method, view) + assert not is_list, "RetrieveAPIView subclasses should not be classified as list views."