mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 11:30:12 +03:00
added tests to cover docs sections in custom actions
This commit is contained in:
parent
65a0d59c70
commit
a138cfc627
|
@ -104,6 +104,17 @@ class ExampleViewSet(ModelViewSet):
|
|||
assert self.action
|
||||
return super(ExampleViewSet, self).get_serializer(*args, **kwargs)
|
||||
|
||||
@action(methods=['get', 'post'], detail=False)
|
||||
def documented_custom_action(self, request):
|
||||
"""
|
||||
get:
|
||||
A description of the get method on the custom action.
|
||||
|
||||
post:
|
||||
A description of the post method on the custom action.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
if coreapi:
|
||||
schema_view = get_schema_view(title='Example API')
|
||||
|
@ -150,6 +161,13 @@ class TestRouterGeneratedSchema(TestCase):
|
|||
action='get'
|
||||
)
|
||||
},
|
||||
'documented_custom_action': {
|
||||
'read': coreapi.Link(
|
||||
url='/example/documented_custom_action/',
|
||||
action='get',
|
||||
description='A description of the get method on the custom action.',
|
||||
)
|
||||
},
|
||||
'read': coreapi.Link(
|
||||
url='/example/{id}/',
|
||||
action='get',
|
||||
|
@ -245,6 +263,23 @@ class TestRouterGeneratedSchema(TestCase):
|
|||
action='post'
|
||||
)
|
||||
},
|
||||
'documented_custom_action': {
|
||||
'read': coreapi.Link(
|
||||
url='/example/documented_custom_action/',
|
||||
action='get',
|
||||
description='A description of the get method on the custom action.',
|
||||
),
|
||||
'create': coreapi.Link(
|
||||
url='/example/documented_custom_action/',
|
||||
action='post',
|
||||
description='A description of the post method on the custom action.',
|
||||
encoding='application/json',
|
||||
fields=[
|
||||
coreapi.Field('a', required=True, location='form', schema=coreschema.String(title='A', description='A field description')),
|
||||
coreapi.Field('b', required=False, location='form', schema=coreschema.String(title='B'))
|
||||
]
|
||||
)
|
||||
},
|
||||
'update': coreapi.Link(
|
||||
url='/example/{id}/',
|
||||
action='put',
|
||||
|
@ -529,6 +564,13 @@ class TestSchemaGeneratorWithMethodLimitedViewSets(TestCase):
|
|||
action='get'
|
||||
)
|
||||
},
|
||||
'documented_custom_action': {
|
||||
'read': coreapi.Link(
|
||||
url='/example1/documented_custom_action/',
|
||||
action='get',
|
||||
description='A description of the get method on the custom action.',
|
||||
),
|
||||
},
|
||||
'read': coreapi.Link(
|
||||
url='/example1/{id}/',
|
||||
action='get',
|
||||
|
|
Loading…
Reference in New Issue
Block a user