Add regression test for overlapping keys

This commit is contained in:
Kaleb Elwert 2017-03-27 16:39:24 -07:00
parent bf1233b62b
commit 4cd9e8a263

View File

@ -376,6 +376,47 @@ class TestSchemaGeneratorNotAtRoot(TestCase):
assert schema == expected
@unittest.skipUnless(coreapi, 'coreapi is not installed')
class TestSchemaGeneratorWithOverlappingKeys(TestCase):
def setUp(self):
self.patterns = [
url('^api/v1/example/(?P<pk>\d+)/?$', ExampleDetailView.as_view()),
url('^api/v1/example/(?P<pk>\d+)/(?P<id2>\d+)/?$', ExampleDetailView.as_view()),
]
def test_schema_for_regular_views(self):
generator = SchemaGenerator(title='Example API', patterns=self.patterns)
schema = generator.get_schema()
expected = coreapi.Document(
url='',
title='Example API',
content={
'example': {
'id': {
'read': coreapi.Link(
url='/api/v1/example/{id}/',
action='get',
fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String())
]
),
'id2': {
'read': coreapi.Link(
url='/api/v1/example/{id}/{id2}/',
action='get',
fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()),
coreapi.Field('id2', required=True, location='path', schema=coreschema.String())
]
)
}
}
}
}
)
assert schema == expected
@unittest.skipUnless(coreapi, 'coreapi is not installed')
class TestSchemaGeneratorWithRestrictedViewSets(TestCase):
def setUp(self):