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]
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(

View File

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

View File

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