Move ViewInspector descriptor tests to own module.

This commit is contained in:
Carlton Gibson 2018-08-09 14:05:20 +02:00
parent eefc08a72f
commit 47a4526c6d
2 changed files with 38 additions and 27 deletions

View File

@ -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):
"""

View File

@ -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)