From f438f14d13feaf3cd68386609aaefc4e10745185 Mon Sep 17 00:00:00 2001 From: Dhaval Mehta <20968146+dhaval-mehta@users.noreply.github.com> Date: Wed, 19 Feb 2020 23:18:48 +0530 Subject: [PATCH] add test case for method override use case --- tests/schemas/test_openapi.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/schemas/test_openapi.py b/tests/schemas/test_openapi.py index e9f851533..c5322cdf5 100644 --- a/tests/schemas/test_openapi.py +++ b/tests/schemas/test_openapi.py @@ -708,6 +708,28 @@ class TestOperationIntrospection(TestCase): schema = generator.get_schema(request=create_request('/')) assert schema['paths']['/test/{id}/']['get']['tags'] == ['example1', 'example2'] + def test_overridden_get_tags_method(self): + class MySchema(AutoSchema): + def get_tags(self, path, method): + if path.endswith('/new/'): + tags = ['tag1', 'tag2'] + elif path.endswith('/old/'): + tags = ['tag2', 'tag3'] + else: + tags = ['tag4', 'tag5'] + + return tags + + class ExampleStringTagsViewSet(views.ExampleGenericViewSet): + schema = MySchema() + + router = routers.SimpleRouter() + router.register('example', ExampleStringTagsViewSet, basename="example") + generator = SchemaGenerator(patterns=router.urls) + schema = generator.get_schema(request=create_request('/')) + assert schema['paths']['/example/new/']['get']['tags'] == ['tag1', 'tag2'] + assert schema['paths']['/example/old/']['get']['tags'] == ['tag2', 'tag3'] + def test_auto_generated_viewset_tags(self): class ExampleIPViewSet(views.ExampleTagsViewSet): pass