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