From 8d9ae9a77790776dcc6a84dd858374e0017bfaef Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Sun, 9 Jun 2019 14:22:02 +0200 Subject: [PATCH] =?UTF-8?q?Add=20test=20for=20generateschema=20=E2=80=94ge?= =?UTF-8?q?nerator=5Fclass=20flag.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/schemas/test_managementcommand.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/schemas/test_managementcommand.py b/tests/schemas/test_managementcommand.py index 42e0e99d1..6cdf7f8b1 100644 --- a/tests/schemas/test_managementcommand.py +++ b/tests/schemas/test_managementcommand.py @@ -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__) @pytest.mark.skipif(not uritemplate, reason='uritemplate is not installed') class GenerateSchemaTests(TestCase): @@ -56,6 +66,13 @@ class GenerateSchemaTests(TestCase): out_json = json.loads(self.out.getvalue()) 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.') @override_settings(REST_FRAMEWORK={'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.AutoSchema'}) def test_coreapi_renders_default_schema_with_custom_title_url_and_description(self):