added tests to check password fields get the correct schema format

This commit is contained in:
Dan Bate 2018-06-26 12:05:50 +01:00
parent 2dab29ca1b
commit 8207dfaa5a

View File

@ -48,6 +48,7 @@ class ExampleSerializer(serializers.Serializer):
b = serializers.CharField(required=False) b = serializers.CharField(required=False)
read_only = serializers.CharField(read_only=True) read_only = serializers.CharField(read_only=True)
hidden = serializers.HiddenField(default='hello') hidden = serializers.HiddenField(default='hello')
password = serializers.CharField(write_only=True, style={'input_type': 'password'})
class AnotherSerializerWithDictField(serializers.Serializer): class AnotherSerializerWithDictField(serializers.Serializer):
@ -188,7 +189,8 @@ class TestRouterGeneratedSchema(TestCase):
encoding='application/json', encoding='application/json',
fields=[ fields=[
coreapi.Field('a', required=True, location='form', schema=coreschema.String(title='A', description='A field description')), coreapi.Field('a', required=True, location='form', schema=coreschema.String(title='A', description='A field description')),
coreapi.Field('b', required=False, location='form', schema=coreschema.String(title='B')) coreapi.Field('b', required=False, location='form', schema=coreschema.String(title='B')),
coreapi.Field('password', required=True, location='form', schema=coreschema.String(title='Password', format='password'))
] ]
), ),
'read': coreapi.Link( 'read': coreapi.Link(
@ -253,7 +255,8 @@ class TestRouterGeneratedSchema(TestCase):
coreapi.Field('id', required=True, location='path', schema=coreschema.String()), coreapi.Field('id', required=True, location='path', schema=coreschema.String()),
coreapi.Field('a', required=True, location='form', schema=coreschema.String(title='A', description=('A field description'))), coreapi.Field('a', required=True, location='form', schema=coreschema.String(title='A', description=('A field description'))),
coreapi.Field('b', required=False, location='form', schema=coreschema.String(title='B')), coreapi.Field('b', required=False, location='form', schema=coreschema.String(title='B')),
coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.')) coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.')),
coreapi.Field('password', required=True, location='form', schema=coreschema.String(title='Password', format='password')),
] ]
), ),
'partial_update': coreapi.Link( 'partial_update': coreapi.Link(
@ -264,7 +267,8 @@ class TestRouterGeneratedSchema(TestCase):
coreapi.Field('id', required=True, location='path', schema=coreschema.String()), coreapi.Field('id', required=True, location='path', schema=coreschema.String()),
coreapi.Field('a', required=False, location='form', schema=coreschema.String(title='A', description='A field description')), coreapi.Field('a', required=False, location='form', schema=coreschema.String(title='A', description='A field description')),
coreapi.Field('b', required=False, location='form', schema=coreschema.String(title='B')), coreapi.Field('b', required=False, location='form', schema=coreschema.String(title='B')),
coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.')) coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.')),
coreapi.Field('password', required=False, location='form', schema=coreschema.String(title='Password', format='password')),
] ]
), ),
'delete': coreapi.Link( 'delete': coreapi.Link(