Add test for nullable ChoiceField and blank HTML input. Closes #2623.

This commit is contained in:
Tom Christie 2015-07-27 13:51:03 +01:00
parent 75beb6ab2d
commit c5a04a8516

View File

@ -1070,6 +1070,22 @@ class TestChoiceField(FieldValues):
output = field.run_validation('') output = field.run_validation('')
assert output == '' assert output == ''
def test_allow_null(self):
"""
If `allow_null=True` then '' on HTML forms is treated as None.
"""
field = serializers.ChoiceField(
allow_null=True,
choices=[
1, 2, 3
]
)
field.field_name = 'example'
value = field.get_value(QueryDict('example='))
assert value is None
output = field.run_validation(None)
assert output is None
class TestChoiceFieldWithType(FieldValues): class TestChoiceFieldWithType(FieldValues):
""" """