From 47a4526c6d32ec337f5e17493599c08cda9bf075 Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Thu, 9 Aug 2018 14:05:20 +0200 Subject: [PATCH] Move ViewInspector descriptor tests to own module. --- tests/schemas/test_schemas.py | 27 ------------- .../schemas/test_view_inspector_descriptor.py | 38 +++++++++++++++++++ 2 files changed, 38 insertions(+), 27 deletions(-) create mode 100644 tests/schemas/test_view_inspector_descriptor.py diff --git a/tests/schemas/test_schemas.py b/tests/schemas/test_schemas.py index 7c8a5ee89..dbec93c6e 100644 --- a/tests/schemas/test_schemas.py +++ b/tests/schemas/test_schemas.py @@ -517,35 +517,8 @@ class Test4605Regression(TestCase): assert prefix == '/' -class CustomViewInspector(AutoSchema): - """A dummy AutoSchema subclass""" - pass - - class TestAutoSchema(TestCase): - def test_apiview_schema_descriptor(self): - view = APIView() - assert hasattr(view, 'schema') - assert isinstance(view.schema, AutoSchema) - - def test_set_custom_inspector_class_on_view(self): - class CustomView(APIView): - schema = CustomViewInspector() - - view = CustomView() - assert isinstance(view.schema, CustomViewInspector) - - def test_set_custom_inspector_class_via_settings(self): - with override_settings(REST_FRAMEWORK={'DEFAULT_SCHEMA_CLASS': 'tests.schemas.test_schemas.CustomViewInspector'}): - view = APIView() - assert isinstance(view.schema, CustomViewInspector) - - def test_get_link_requires_instance(self): - descriptor = APIView.schema # Accessed from class - with pytest.raises(AssertionError): - descriptor.get_link(None, None, None) # ???: Do the dummy arguments require a tighter assert? - @pytest.mark.skipif(not coreapi, reason='coreapi is not installed') def test_update_fields(self): """ diff --git a/tests/schemas/test_view_inspector_descriptor.py b/tests/schemas/test_view_inspector_descriptor.py new file mode 100644 index 000000000..6bf2c2bf4 --- /dev/null +++ b/tests/schemas/test_view_inspector_descriptor.py @@ -0,0 +1,38 @@ +import pytest +from django.test import TestCase, override_settings + +from rest_framework.schemas.inspectors import AutoSchema, ViewInspector +from rest_framework.views import APIView + + +class CustomViewInspector(ViewInspector): + """A dummy ViewInspector subclass""" + pass + + +class TestViewInspector(TestCase): + """ + Tests for the descriptor behaviour of ViewInspector + (and subclasses.) + """ + def test_apiview_schema_descriptor(self): + view = APIView() + assert hasattr(view, 'schema') + assert isinstance(view.schema, AutoSchema) + + def test_set_custom_inspector_class_on_view(self): + class CustomView(APIView): + schema = CustomViewInspector() + + view = CustomView() + assert isinstance(view.schema, CustomViewInspector) + + def test_set_custom_inspector_class_via_settings(self): + with override_settings(REST_FRAMEWORK={'DEFAULT_SCHEMA_CLASS': 'tests.schemas.test_view_inspector_descriptor.CustomViewInspector'}): + view = APIView() + assert isinstance(view.schema, CustomViewInspector) + + def test_get_link_requires_instance(self): + descriptor = APIView.schema # Accessed from class + with pytest.raises(AssertionError): + descriptor.get_link(None, None, None)