mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
parent
fa4ce50be7
commit
9857cd9889
|
@ -55,6 +55,30 @@ class TestSimpleBoundField:
|
|||
assert serializer['bool_field'].as_form_field().value == ''
|
||||
assert serializer['null_field'].as_form_field().value == ''
|
||||
|
||||
def test_rendering_boolean_field(self):
|
||||
from rest_framework.renderers import HTMLFormRenderer
|
||||
|
||||
class ExampleSerializer(serializers.Serializer):
|
||||
bool_field = serializers.BooleanField(
|
||||
style={'base_template': 'checkbox.html', 'template_pack': 'rest_framework/vertical'})
|
||||
|
||||
serializer = ExampleSerializer(data={'bool_field': True})
|
||||
assert serializer.is_valid()
|
||||
renderer = HTMLFormRenderer()
|
||||
rendered = renderer.render_field(serializer['bool_field'], {})
|
||||
expected_packed = (
|
||||
'<divclass="form-group">'
|
||||
'<divclass="checkbox">'
|
||||
'<label>'
|
||||
'<inputtype="checkbox"name="bool_field"value="true"checked>'
|
||||
'Boolfield'
|
||||
'</label>'
|
||||
'</div>'
|
||||
'</div>'
|
||||
)
|
||||
rendered_packed = ''.join(rendered.split())
|
||||
assert rendered_packed == expected_packed
|
||||
|
||||
|
||||
class TestNestedBoundField:
|
||||
def test_nested_empty_bound_field(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user