From eb8032835699cdd289fb789d1156e16420574b34 Mon Sep 17 00:00:00 2001 From: sol HYUN Date: Fri, 24 Mar 2017 15:27:44 +0900 Subject: [PATCH] Modify test code --- tests/test_schemas.py | 113 +++++++++++++++++++++--------------------- 1 file changed, 57 insertions(+), 56 deletions(-) diff --git a/tests/test_schemas.py b/tests/test_schemas.py index f75370170..1d7249ddb 100644 --- a/tests/test_schemas.py +++ b/tests/test_schemas.py @@ -109,12 +109,6 @@ class TestRouterGeneratedSchema(TestCase): url='/example/custom_list_action/', action='get' ), - 'custom_list_action_multiple_methods': { - 'read': coreapi.Link( - url='/example/custom_list_action_multiple_methods/', - action='get' - ) - }, 'read': coreapi.Link( url='/example/{id}/', action='get', @@ -122,6 +116,12 @@ class TestRouterGeneratedSchema(TestCase): coreapi.Field('id', required=True, location='path', schema=coreschema.String()) ] ) + }, + 'example-custom_list_action_multiple_methods': { + 'read': coreapi.Link( + url='/example/custom_list_action_multiple_methods/', + action='get' + ) } } ) @@ -162,31 +162,6 @@ class TestRouterGeneratedSchema(TestCase): coreapi.Field('id', required=True, location='path', schema=coreschema.String()) ] ), - 'custom_action': coreapi.Link( - url='/example/{id}/custom_action/', - action='post', - encoding='application/json', - description='A description of custom action.', - fields=[ - coreapi.Field('id', required=True, location='path', schema=coreschema.String()), - coreapi.Field('c', required=True, location='form', schema=coreschema.String(title='C')), - coreapi.Field('d', required=False, location='form', schema=coreschema.String(title='D')), - ] - ), - 'custom_list_action': coreapi.Link( - url='/example/custom_list_action/', - action='get' - ), - 'custom_list_action_multiple_methods': { - 'read': coreapi.Link( - url='/example/custom_list_action_multiple_methods/', - action='get' - ), - 'create': coreapi.Link( - url='/example/custom_list_action_multiple_methods/', - action='post' - ) - }, 'update': coreapi.Link( url='/example/{id}/', action='put', @@ -213,8 +188,33 @@ class TestRouterGeneratedSchema(TestCase): fields=[ coreapi.Field('id', required=True, location='path', schema=coreschema.String()) ] + ), + 'custom_list_action': coreapi.Link( + url='/example/custom_list_action/', + action='get' + ), + 'custom_action': coreapi.Link( + url='/example/{id}/custom_action/', + action='post', + encoding='application/json', + description='A description of custom action.', + fields=[ + coreapi.Field('id', required=True, location='path', schema=coreschema.String()), + coreapi.Field('c', required=True, location='form', schema=coreschema.String(title='C')), + coreapi.Field('d', required=False, location='form', schema=coreschema.String(title='D')), + ] ) - } + }, + 'example-custom_list_action_multiple_methods': { + 'read': coreapi.Link( + url='/example/custom_list_action_multiple_methods/', + action='get' + ), + 'create': coreapi.Link( + url='/example/custom_list_action_multiple_methods/', + action='post' + ) + }, } ) assert response.data == expected @@ -299,16 +299,15 @@ class TestSchemaGenerator(TestCase): fields=[ coreapi.Field('id', required=True, location='path', schema=coreschema.String()) ] - ), - 'sub': { - 'list': coreapi.Link( - url='/example/{id}/sub/', - action='get', - fields=[ - coreapi.Field('id', required=True, location='path', schema=coreschema.String()) - ] - ) - } + )}, + 'example-sub': { + 'list': coreapi.Link( + url='/example/{id}/sub/', + action='get', + fields=[ + coreapi.Field('id', required=True, location='path', schema=coreschema.String()) + ] + ) } } ) @@ -335,7 +334,7 @@ class TestSchemaGeneratorNotAtRoot(TestCase): url='', title='Example API', content={ - 'example': { + 'api-v1-example': { 'create': coreapi.Link( url='/api/v1/example/', action='post', @@ -352,16 +351,15 @@ class TestSchemaGeneratorNotAtRoot(TestCase): fields=[ coreapi.Field('id', required=True, location='path', schema=coreschema.String()) ] - ), - 'sub': { - 'list': coreapi.Link( - url='/api/v1/example/{id}/sub/', - action='get', - fields=[ - coreapi.Field('id', required=True, location='path', schema=coreschema.String()) - ] - ) - } + )}, + 'api-v1-example-sub': { + 'list': coreapi.Link( + url='/api/v1/example/{id}/sub/', + action='get', + fields=[ + coreapi.Field('id', required=True, location='path', schema=coreschema.String()) + ] + ) } } ) @@ -407,8 +405,11 @@ class TestSchemaGeneratorWithRestrictedViewSets(TestCase): class Test4605Regression(TestCase): def test_4605_regression(self): generator = SchemaGenerator() - prefix = generator.determine_path_prefix([ + typical_path1 = generator.make_typical_path( '/api/v1/items/', + ) + assert typical_path1 == 'api-v1-items' + typical_path2 = generator.make_typical_path( '/auth/convert-token/' - ]) - assert prefix == '/' + ) + assert typical_path2 == 'auth-convert-token'