8
8
from django .test .utils import override_settings
9
9
from django .urls import path
10
10
11
- from rest_framework .compat import uritemplate , yaml
11
+ from rest_framework .compat import coreapi , uritemplate , yaml
12
12
from rest_framework .management .commands import generateschema
13
13
from rest_framework .utils import formatting , json
14
14
from rest_framework .views import APIView
@@ -35,20 +35,23 @@ def get_schema(self, **kwargs):
35
35
36
36
37
37
@override_settings (ROOT_URLCONF = __name__ )
38
+ @pytest .mark .skipif (not coreapi , reason = 'coreapi is not installed' )
38
39
@pytest .mark .skipif (not uritemplate , reason = 'uritemplate is not installed' )
39
40
class GenerateSchemaTests (TestCase ):
40
41
"""Tests for management command generateschema."""
41
42
42
43
def setUp (self ):
43
44
self .out = io .StringIO ()
44
45
46
+ @pytest .mark .skipif (not coreapi , reason = 'coreapi is not installed' )
45
47
def test_command_detects_schema_generation_mode (self ):
46
48
"""Switching between CoreAPI & OpenAPI"""
47
49
command = generateschema .Command ()
48
50
assert command .get_mode () == generateschema .OPENAPI_MODE
49
51
with override_settings (REST_FRAMEWORK = {'DEFAULT_SCHEMA_CLASS' : 'rest_framework.schemas.AutoSchema' }):
50
52
assert command .get_mode () == generateschema .COREAPI_MODE
51
53
54
+ @pytest .mark .skipif (not coreapi , reason = 'coreapi is not installed' )
52
55
@pytest .mark .skipif (yaml is None , reason = 'PyYAML is required.' )
53
56
def test_renders_default_schema_with_custom_title_url_and_description (self ):
54
57
call_command ('generateschema' ,
@@ -91,6 +94,7 @@ def test_writes_schema_to_file_on_parameter(self):
91
94
os .remove (path )
92
95
93
96
@pytest .mark .skipif (yaml is None , reason = 'PyYAML is required.' )
97
+ @pytest .mark .skipif (not coreapi , reason = 'coreapi is not installed' )
94
98
@override_settings (REST_FRAMEWORK = {'DEFAULT_SCHEMA_CLASS' : 'rest_framework.schemas.AutoSchema' })
95
99
def test_coreapi_renders_default_schema_with_custom_title_url_and_description (self ):
96
100
expected_out = """info:
@@ -113,6 +117,7 @@ def test_coreapi_renders_default_schema_with_custom_title_url_and_description(se
113
117
114
118
self .assertIn (formatting .dedent (expected_out ), self .out .getvalue ())
115
119
120
+ @pytest .mark .skipif (not coreapi , reason = 'coreapi is not installed' )
116
121
@override_settings (REST_FRAMEWORK = {'DEFAULT_SCHEMA_CLASS' : 'rest_framework.schemas.AutoSchema' })
117
122
def test_coreapi_renders_openapi_json_schema (self ):
118
123
expected_out = {
@@ -142,6 +147,7 @@ def test_coreapi_renders_openapi_json_schema(self):
142
147
143
148
self .assertDictEqual (out_json , expected_out )
144
149
150
+ @pytest .mark .skipif (not coreapi , reason = 'coreapi is not installed' )
145
151
@override_settings (REST_FRAMEWORK = {'DEFAULT_SCHEMA_CLASS' : 'rest_framework.schemas.AutoSchema' })
146
152
def test_renders_corejson_schema (self ):
147
153
expected_out = """{"_type":"document","":{"list":{"_type":"link","url":"/","action":"get"}}}"""
0 commit comments