mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-01 11:00:13 +03:00
Move ViewInspector descriptor tests to own module.
This commit is contained in:
parent
eefc08a72f
commit
47a4526c6d
|
@ -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):
|
||||
"""
|
||||
|
|
38
tests/schemas/test_view_inspector_descriptor.py
Normal file
38
tests/schemas/test_view_inspector_descriptor.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user