From 4cd9e8a2636f9a24888495f00859dd3acf28e657 Mon Sep 17 00:00:00 2001 From: Kaleb Elwert Date: Mon, 27 Mar 2017 16:39:24 -0700 Subject: [PATCH] Add regression test for overlapping keys --- tests/test_schemas.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/test_schemas.py b/tests/test_schemas.py index 541f36f72..58852d52f 100644 --- a/tests/test_schemas.py +++ b/tests/test_schemas.py @@ -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\d+)/?$', ExampleDetailView.as_view()), + url('^api/v1/example/(?P\d+)/(?P\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):