From 92bb9ec3e99e9ff71de86b211e8a534f53c7f917 Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Thu, 17 May 2018 02:07:44 -0400 Subject: [PATCH] Add failing test for extra action schemas --- tests/test_schemas.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/test_schemas.py b/tests/test_schemas.py index f929fece5..c0d6deca1 100644 --- a/tests/test_schemas.py +++ b/tests/test_schemas.py @@ -720,6 +720,31 @@ class TestAutoSchema(TestCase): assert len(fields) == 2 assert "my_extra_field" in [f.name for f in fields] + @pytest.mark.skipif(not coreapi, reason='coreapi is not installed') + def test_viewset_action_with_schema(self): + class CustomViewSet(GenericViewSet): + @action(detail=True, schema=AutoSchema(manual_fields=[ + coreapi.Field( + "my_extra_field", + required=True, + location="path", + schema=coreschema.String() + ), + ])) + def extra_action(self, pk, **kwargs): + pass + + router = SimpleRouter() + router.register(r'detail', CustomViewSet, base_name='detail') + + generator = SchemaGenerator() + view = generator.create_view(router.urls[0].callback, 'GET') + link = view.schema.get_link('/a/url/{id}/', 'GET', '') + fields = link.fields + + assert len(fields) == 2 + assert "my_extra_field" in [f.name for f in fields] + @pytest.mark.skipif(not coreapi, reason='coreapi is not installed') def test_view_with_manual_schema(self):