Add test for new setting

This commit is contained in:
Carlton Gibson 2017-12-05 09:09:07 +01:00
parent 4a200d5e66
commit 4b09e82402

View File

@ -516,6 +516,11 @@ class Test4605Regression(TestCase):
assert prefix == '/' assert prefix == '/'
class CustomViewInspector(AutoSchema):
"""A dummy AutoSchema subclass"""
pass
class TestAutoSchema(TestCase): class TestAutoSchema(TestCase):
def test_apiview_schema_descriptor(self): def test_apiview_schema_descriptor(self):
@ -523,6 +528,18 @@ class TestAutoSchema(TestCase):
assert hasattr(view, 'schema') assert hasattr(view, 'schema')
assert isinstance(view.schema, AutoSchema) 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.test_schemas.CustomViewInspector'}):
view = APIView()
assert isinstance(view.schema, CustomViewInspector)
def test_get_link_requires_instance(self): def test_get_link_requires_instance(self):
descriptor = APIView.schema # Accessed from class descriptor = APIView.schema # Accessed from class
with pytest.raises(AssertionError): with pytest.raises(AssertionError):