mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-31 10:30:01 +03:00
Add test for generateschema —generator_class flag.
This commit is contained in:
parent
e49a50c6c3
commit
8d9ae9a777
|
@ -22,6 +22,16 @@ urlpatterns = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class CustomSchemaGenerator:
|
||||||
|
SCHEMA = {"key": "value"}
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def get_schema(self, **kwargs):
|
||||||
|
return self.SCHEMA
|
||||||
|
|
||||||
|
|
||||||
@override_settings(ROOT_URLCONF=__name__)
|
@override_settings(ROOT_URLCONF=__name__)
|
||||||
@pytest.mark.skipif(not uritemplate, reason='uritemplate is not installed')
|
@pytest.mark.skipif(not uritemplate, reason='uritemplate is not installed')
|
||||||
class GenerateSchemaTests(TestCase):
|
class GenerateSchemaTests(TestCase):
|
||||||
|
@ -56,6 +66,13 @@ class GenerateSchemaTests(TestCase):
|
||||||
out_json = json.loads(self.out.getvalue())
|
out_json = json.loads(self.out.getvalue())
|
||||||
assert out_json['openapi'] == '3.0.2'
|
assert out_json['openapi'] == '3.0.2'
|
||||||
|
|
||||||
|
def test_accepts_custom_schema_generator(self):
|
||||||
|
call_command('generateschema',
|
||||||
|
'--generator_class={}.{}'.format(__name__, CustomSchemaGenerator.__name__),
|
||||||
|
stdout=self.out)
|
||||||
|
out_json = yaml.safe_load(self.out.getvalue())
|
||||||
|
assert out_json == CustomSchemaGenerator.SCHEMA
|
||||||
|
|
||||||
@pytest.mark.skipif(yaml is None, reason='PyYAML is required.')
|
@pytest.mark.skipif(yaml is None, reason='PyYAML is required.')
|
||||||
@override_settings(REST_FRAMEWORK={'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.AutoSchema'})
|
@override_settings(REST_FRAMEWORK={'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.AutoSchema'})
|
||||||
def test_coreapi_renders_default_schema_with_custom_title_url_and_description(self):
|
def test_coreapi_renders_default_schema_with_custom_title_url_and_description(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user