mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
Add test for nullable ChoiceField and blank HTML input. Closes #2623.
This commit is contained in:
parent
75beb6ab2d
commit
c5a04a8516
|
@ -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):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user