Skip to content

Add test for AutoSchema on detail_route (#5630) #5631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.test import TestCase, override_settings

from rest_framework import (
filters, generics, pagination, permissions, serializers
filters, generics, pagination, permissions, serializers, routers
)
from rest_framework.compat import coreapi, coreschema, get_regex_pattern
from rest_framework.decorators import (
Expand Down Expand Up @@ -547,6 +547,33 @@ class CustomView(APIView):
assert len(fields) == 2
assert "my_extra_field" in [f.name for f in fields]

def test_detail_route(self):

class AViewSet(GenericViewSet):
@detail_route(schema=AutoSchema(manual_fields=[
coreapi.Field(
"my_extra_field",
required=True,
location="path",
schema=coreschema.String()
),
]))
def a_detail_route(self, request, my_normal_field):
pass

router = routers.SimpleRouter()
router.register(r'detail', AViewSet, base_name='detail')
routes = router.urls

callback = routes[0].callback
generator = SchemaGenerator()
view = generator.create_view(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]

def test_view_with_manual_schema(self):

path = '/example'
Expand Down