mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-29 04:54:00 +03:00
parent
a3e64fbe0d
commit
18af181191
|
@ -280,9 +280,7 @@ class Field(object):
|
||||||
self.allow_null = allow_null
|
self.allow_null = allow_null
|
||||||
|
|
||||||
if self.default_empty_html is not empty:
|
if self.default_empty_html is not empty:
|
||||||
if not required:
|
if default is not empty:
|
||||||
self.default_empty_html = empty
|
|
||||||
elif default is not empty:
|
|
||||||
self.default_empty_html = default
|
self.default_empty_html = default
|
||||||
|
|
||||||
if validators is not None:
|
if validators is not None:
|
||||||
|
|
|
@ -227,19 +227,27 @@ class TestInvalidErrorKey:
|
||||||
|
|
||||||
|
|
||||||
class TestBooleanHTMLInput:
|
class TestBooleanHTMLInput:
|
||||||
def setup(self):
|
|
||||||
class TestSerializer(serializers.Serializer):
|
|
||||||
archived = serializers.BooleanField()
|
|
||||||
self.Serializer = TestSerializer
|
|
||||||
|
|
||||||
def test_empty_html_checkbox(self):
|
def test_empty_html_checkbox(self):
|
||||||
"""
|
"""
|
||||||
HTML checkboxes do not send any value, but should be treated
|
HTML checkboxes do not send any value, but should be treated
|
||||||
as `False` by BooleanField.
|
as `False` by BooleanField.
|
||||||
"""
|
"""
|
||||||
# This class mocks up a dictionary like object, that behaves
|
class TestSerializer(serializers.Serializer):
|
||||||
# as if it was returned for multipart or urlencoded data.
|
archived = serializers.BooleanField()
|
||||||
serializer = self.Serializer(data=QueryDict(''))
|
|
||||||
|
serializer = TestSerializer(data=QueryDict(''))
|
||||||
|
assert serializer.is_valid()
|
||||||
|
assert serializer.validated_data == {'archived': False}
|
||||||
|
|
||||||
|
def test_empty_html_checkbox_not_required(self):
|
||||||
|
"""
|
||||||
|
HTML checkboxes do not send any value, but should be treated
|
||||||
|
as `False` by BooleanField, even if the field is required=False.
|
||||||
|
"""
|
||||||
|
class TestSerializer(serializers.Serializer):
|
||||||
|
archived = serializers.BooleanField(required=False)
|
||||||
|
|
||||||
|
serializer = TestSerializer(data=QueryDict(''))
|
||||||
assert serializer.is_valid()
|
assert serializer.is_valid()
|
||||||
assert serializer.validated_data == {'archived': False}
|
assert serializer.validated_data == {'archived': False}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user