Commit c5a04a85 by Tom Christie

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

parent 75beb6ab
......@@ -1070,6 +1070,22 @@ class TestChoiceField(FieldValues):
output = field.run_validation('')
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):
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment