From 6079fe7be53824af55eb75f04cc859d9dcba1d0f Mon Sep 17 00:00:00 2001 From: fakepoet Date: Mon, 20 May 2019 16:17:39 +0800 Subject: [PATCH] Fix #6007, and fix test_schemas.TestURLNamingCollisions.test_from_router() assertion --- rest_framework/schemas/coreapi.py | 3 +++ tests/schemas/test_coreapi.py | 16 ++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/rest_framework/schemas/coreapi.py b/rest_framework/schemas/coreapi.py index 5cf789f9f..4c1cec155 100644 --- a/rest_framework/schemas/coreapi.py +++ b/rest_framework/schemas/coreapi.py @@ -85,6 +85,9 @@ def insert_into(target, keys, value): target = target[key] try: + if len(keys) == 1: + target[keys[-1]] = LinkNode() + target = target[keys[-1]] target.links.append((keys[-1], value)) except TypeError: msg = INSERT_INTO_COLLISION_FMT.format( diff --git a/tests/schemas/test_coreapi.py b/tests/schemas/test_coreapi.py index 5534f4534..b3e8822d8 100644 --- a/tests/schemas/test_coreapi.py +++ b/tests/schemas/test_coreapi.py @@ -1204,7 +1204,7 @@ class TestURLNamingCollisions(TestCase): # not important here desc_0 = schema['detail']['detail_export'].description - desc_1 = schema['detail_0'].description + desc_1 = schema['detail']['detail'].description expected = coreapi.Document( url='', @@ -1214,13 +1214,13 @@ class TestURLNamingCollisions(TestCase): 'detail_export': coreapi.Link( url='/from-routercollision/detail/export/', action='get', - description=desc_0) - }, - 'detail_0': coreapi.Link( - url='/from-routercollision/detail/', - action='get', - description=desc_1 - ) + description=desc_0), + 'detail': coreapi.Link( + url='/from-routercollision/detail/', + action='get', + description=desc_1 + ) + } } )