2016-09-07 05:41:54 +08:00
|
|
|
from django.forms import Widget
|
2017-01-07 08:11:32 +08:00
|
|
|
from django.forms.widgets import Input
|
2016-09-07 05:41:54 +08:00
|
|
|
|
2017-01-07 08:11:32 +08:00
|
|
|
from .base import WidgetTest
|
2016-09-07 05:41:54 +08:00
|
|
|
|
2017-01-07 08:11:32 +08:00
|
|
|
|
|
|
|
class WidgetTests(WidgetTest):
|
2016-09-07 05:41:54 +08:00
|
|
|
|
2017-03-09 22:42:47 +08:00
|
|
|
def test_format_value(self):
|
|
|
|
widget = Widget()
|
|
|
|
self.assertIsNone(widget.format_value(None))
|
|
|
|
self.assertIsNone(widget.format_value(''))
|
|
|
|
self.assertEqual(widget.format_value('español'), 'español')
|
|
|
|
self.assertEqual(widget.format_value(42.5), '42.5')
|
|
|
|
|
2016-09-07 05:41:54 +08:00
|
|
|
def test_value_omitted_from_data(self):
|
|
|
|
widget = Widget()
|
|
|
|
self.assertIs(widget.value_omitted_from_data({}, {}, 'field'), True)
|
|
|
|
self.assertIs(widget.value_omitted_from_data({'field': 'value'}, {}, 'field'), False)
|
2017-01-07 08:11:32 +08:00
|
|
|
|
|
|
|
def test_no_trailing_newline_in_attrs(self):
|
2018-01-21 15:09:10 +08:00
|
|
|
self.check_html(Input(), 'name', 'value', strict=True, html='<input type="None" name="name" value="value">')
|
2017-01-23 02:15:56 +08:00
|
|
|
|
|
|
|
def test_attr_false_not_rendered(self):
|
2018-01-21 15:09:10 +08:00
|
|
|
html = '<input type="None" name="name" value="value">'
|
2017-01-23 02:15:56 +08:00
|
|
|
self.check_html(Input(), 'name', 'value', html=html, attrs={'readonly': False})
|