From d988826e00cadc60d7d150af1554f342b98cf13e Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Fri, 29 Sep 2017 11:24:36 +0200 Subject: [PATCH] Add failing tests for #4704 --- tests/test_schemas.py | 51 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/tests/test_schemas.py b/tests/test_schemas.py index 07c49b71d..cefac6750 100644 --- a/tests/test_schemas.py +++ b/tests/test_schemas.py @@ -12,7 +12,7 @@ from rest_framework.decorators import ( api_view, detail_route, list_route, schema ) from rest_framework.request import Request -from rest_framework.routers import DefaultRouter +from rest_framework.routers import DefaultRouter, SimpleRouter from rest_framework.schemas import ( AutoSchema, ManualSchema, SchemaGenerator, get_schema_view ) @@ -20,7 +20,7 @@ from rest_framework.schemas.generators import EndpointEnumerator from rest_framework.test import APIClient, APIRequestFactory from rest_framework.utils import formatting from rest_framework.views import APIView -from rest_framework.viewsets import ModelViewSet +from rest_framework.viewsets import GenericViewSet, ModelViewSet factory = APIRequestFactory() @@ -726,3 +726,50 @@ class SchemaGenerationExclusionTests(TestCase): "The `OldFashionedExcludedView.exclude_from_schema` attribute is " "pending deprecation. Set `schema = None` instead." ) + + + +@api_view(["GET"]) +def simple_fbv(request): + pass + + +class NamingCollisionViewSet(GenericViewSet): + """ + Example via: https://stackoverflow.com/questions/43778668/django-rest-framwork-occured-typeerror-link-object-does-not-support-item-ass/ + """ + permision_class = () + + @list_route() + def detail(self, request): + return {} + + @list_route(url_path='detail/export') + def detail_export(self, request): + return {} + + +naming_collisions_router = SimpleRouter() +naming_collisions_router.register(r'collision', NamingCollisionViewSet, base_name="collision") + + +class TestURLNamingCollisions(TestCase): + """ + Ref: https://github.com/encode/django-rest-framework/issues/4704 + """ + def test_manually_routing_nested_routes(self): + patterns = [ + url(r'^test', simple_fbv), + url(r'^test/list/', simple_fbv), + ] + + generator = SchemaGenerator(title='Naming Colisions', patterns=patterns) + schema = generator.get_schema() + + def test_from_router(self): + patterns = [ + url(r'from-router', include(naming_collisions_router.urls)), + ] + + generator = SchemaGenerator(title='Naming Colisions', patterns=patterns) + schema = generator.get_schema()