@@ -749,6 +749,10 @@ class NamingCollisionView(generics.RetrieveUpdateDestroyAPIView):
749749 serializer_class = BasicModelSerializer
750750
751751
752+ class BasicNamingCollisionView (generics .RetrieveAPIView ):
753+ queryset = BasicModel .objects .all ()
754+
755+
752756class NamingCollisionViewSet (GenericViewSet ):
753757 """
754758 Example via: https://stackoverflow.com/questions/43778668/django-rest-framwork-occured-typeerror-link-object-does-not-support-item-ass/
@@ -779,9 +783,35 @@ def test_manually_routing_nested_routes(self):
779783 ]
780784
781785 generator = SchemaGenerator (title = 'Naming Colisions' , patterns = patterns )
786+ schema = generator .get_schema ()
782787
783- with pytest .raises (ValueError ):
784- generator .get_schema ()
788+ expected = coreapi .Document (
789+ url = '' ,
790+ title = 'Naming Colisions' ,
791+ content = {
792+ 'test' : {
793+ 'list' : {
794+ 'list' : coreapi .Link (url = '/test/list/' , action = 'get' )
795+ },
796+ 'list_0' : coreapi .Link (url = '/test' , action = 'get' )
797+ }
798+ }
799+ )
800+
801+ assert expected == schema
802+
803+ def _verify_cbv_links (self , loc , url , methods = None , suffixes = None ):
804+ if methods is None :
805+ methods = ('read' , 'update' , 'partial_update' , 'delete' )
806+ if suffixes is None :
807+ suffixes = (None for m in methods )
808+
809+ for method , suffix in zip (methods , suffixes ):
810+ if suffix is not None :
811+ key = '{}_{}' .format (method , suffix )
812+ else :
813+ key = method
814+ assert loc [key ].url == url
785815
786816 def test_manually_routing_generic_view (self ):
787817 patterns = [
@@ -797,18 +827,68 @@ def test_manually_routing_generic_view(self):
797827
798828 generator = SchemaGenerator (title = 'Naming Colisions' , patterns = patterns )
799829
800- with pytest .raises (ValueError ):
801- generator .get_schema ()
830+ schema = generator .get_schema ()
831+
832+ self ._verify_cbv_links (schema ['test' ]['delete' ], '/test/delete/' )
833+ self ._verify_cbv_links (schema ['test' ]['put' ], '/test/put/' )
834+ self ._verify_cbv_links (schema ['test' ]['get' ], '/test/get/' )
835+ self ._verify_cbv_links (schema ['test' ]['update' ], '/test/update/' )
836+ self ._verify_cbv_links (schema ['test' ]['retrieve' ], '/test/retrieve/' )
837+ self ._verify_cbv_links (schema ['test' ], '/test' , suffixes = (None , '0' , None , '0' ))
802838
803839 def test_from_router (self ):
804840 patterns = [
805841 url (r'from-router' , include (naming_collisions_router .urls )),
806842 ]
807843
808844 generator = SchemaGenerator (title = 'Naming Colisions' , patterns = patterns )
845+ schema = generator .get_schema ()
846+ desc = schema ['detail_0' ].description # not important here
847+
848+ expected = coreapi .Document (
849+ url = '' ,
850+ title = 'Naming Colisions' ,
851+ content = {
852+ 'detail' : {
853+ 'detail_export' : coreapi .Link (
854+ url = '/from-routercollision/detail/export/' ,
855+ action = 'get' ,
856+ description = desc )
857+ },
858+ 'detail_0' : coreapi .Link (
859+ url = '/from-routercollision/detail/' ,
860+ action = 'get' ,
861+ description = desc
862+ )
863+ }
864+ )
865+
866+ assert schema == expected
867+
868+ def test_url_under_same_key_not_replaced (self ):
869+ patterns = [
870+ url (r'example/(?P<pk>\d+)/$' , BasicNamingCollisionView .as_view ()),
871+ url (r'example/(?P<slug>\w+)/$' , BasicNamingCollisionView .as_view ()),
872+ ]
873+
874+ generator = SchemaGenerator (title = 'Naming Colisions' , patterns = patterns )
875+ schema = generator .get_schema ()
876+
877+ assert schema ['example' ]['read' ].url == '/example/{id}/'
878+ assert schema ['example' ]['read_0' ].url == '/example/{slug}/'
879+
880+ def test_url_under_same_key_not_replaced_another (self ):
881+
882+ patterns = [
883+ url (r'^test/list/' , simple_fbv ),
884+ url (r'^test/(?P<pk>\d+)/list/' , simple_fbv ),
885+ ]
886+
887+ generator = SchemaGenerator (title = 'Naming Colisions' , patterns = patterns )
888+ schema = generator .get_schema ()
809889
810- with pytest . raises ( ValueError ):
811- generator . get_schema ()
890+ assert schema [ 'test' ][ 'list' ][ 'list' ]. url == '/test/list/'
891+ assert schema [ 'test' ][ 'list' ][ 'list_0' ]. url == '/test/{id}/list/'
812892
813893
814894def test_is_list_view_recognises_retrieve_view_subclasses ():
0 commit comments