Fix schema generation problem, and fix test_schemas.TestURLNamingCollisions.test_from_router() behavior. (#6007)

This commit is contained in:
fakepoet 2019-05-05 14:13:14 +08:00
parent 6b6bb80ab8
commit c432f1ff84
3 changed files with 21 additions and 14 deletions

View File

@ -97,6 +97,9 @@ def insert_into(target, keys, value):
target = target[key] target = target[key]
try: try:
if len(keys) == 1:
target[keys[-1]] = LinkNode()
target = target[keys[-1]]
target.links.append((keys[-1], value)) target.links.append((keys[-1], value))
except TypeError: except TypeError:
msg = INSERT_INTO_COLLISION_FMT.format( msg = INSERT_INTO_COLLISION_FMT.format(

View File

@ -65,11 +65,13 @@ class AnotherTestRouterGeneratedSchema(TestCase):
url='http://testserver/', url='http://testserver/',
title='Example API', title='Example API',
content={ content={
'example': { 'test1': {
'test1': coreapi.Link( 'test1': coreapi.Link(
url='/example/example/test1/', url='/example/example/test1/',
action='get' action='get'
), )
},
'test2': {
'test2': coreapi.Link( 'test2': coreapi.Link(
url='/example/example/test2/', url='/example/example/test2/',
action='get' action='get'
@ -77,7 +79,6 @@ class AnotherTestRouterGeneratedSchema(TestCase):
} }
} }
) )
print(response.data)
assert response.data == expected assert response.data == expected
def test_authenticated_request(self): def test_authenticated_request(self):
@ -90,11 +91,13 @@ class AnotherTestRouterGeneratedSchema(TestCase):
url='http://testserver/', url='http://testserver/',
title='Example API', title='Example API',
content={ content={
'example': { 'test1': {
'test1': coreapi.Link( 'test1': coreapi.Link(
url='/example/example/test1/', url='/example/example/test1/',
action='get' action='get'
), )
},
'test2': {
'test2': coreapi.Link( 'test2': coreapi.Link(
url='/example/example/test2/', url='/example/example/test2/',
action='get' action='get'

View File

@ -1191,24 +1191,25 @@ class TestURLNamingCollisions(TestCase):
schema = generator.get_schema() schema = generator.get_schema()
# not important here # not important here
desc_0 = schema['detail']['detail_export'].description desc_0 = schema['detail']['detail'].description
desc_1 = schema['detail_0'].description desc_1 = schema['detail']['detail_export'].description
expected = coreapi.Document( expected = coreapi.Document(
url='', url='',
title='Naming Colisions', title='Naming Colisions',
content={ content={
'detail': { 'detail': {
'detail': coreapi.Link(
url='/from-routercollision/detail/',
action='get',
description=desc_0
),
'detail_export': coreapi.Link( 'detail_export': coreapi.Link(
url='/from-routercollision/detail/export/', url='/from-routercollision/detail/export/',
action='get', action='get',
description=desc_0) description=desc_1
}, )
'detail_0': coreapi.Link( }
url='/from-routercollision/detail/',
action='get',
description=desc_1
)
} }
) )