from django.forms import TextInput from django.utils.safestring import mark_safe from .base import WidgetTest class TextInputTest(WidgetTest): widget = TextInput() def test_render(self): self.check_html(self.widget, 'email', '', html='') def test_render_none(self): self.check_html(self.widget, 'email', None, html='') def test_render_value(self): self.check_html(self.widget, 'email', 'test@example.com', html=( '' )) def test_render_boolean(self): """ Boolean values are rendered to their string forms ("True" and "False"). """ self.check_html(self.widget, 'get_spam', False, html=( '' )) self.check_html(self.widget, 'get_spam', True, html=( '' )) def test_render_quoted(self): self.check_html( self.widget, 'email', 'some "quoted" & ampersanded value', html='', ) def test_render_custom_attrs(self): self.check_html( self.widget, 'email', 'test@example.com', attrs={'class': 'fun'}, html='', ) def test_render_unicode(self): self.check_html( self.widget, 'email', 'ŠĐĆŽćžšđ', attrs={'class': 'fun'}, html=( '' ), ) def test_constructor_attrs(self): widget = TextInput(attrs={'class': 'fun', 'type': 'email'}) self.check_html(widget, 'email', '', html='') self.check_html( widget, 'email', 'foo@example.com', html='', ) def test_attrs_precedence(self): """ `attrs` passed to render() get precedence over those passed to the constructor """ widget = TextInput(attrs={'class': 'pretty'}) self.check_html( widget, 'email', '', attrs={'class': 'special'}, html='', ) def test_attrs_safestring(self): widget = TextInput(attrs={'onBlur': mark_safe("function('foo')")}) self.check_html(widget, 'email', '', html='') def test_use_required_attribute(self): # Text inputs can safely trigger the browser validation. self.assertIs(self.widget.use_required_attribute(None), True) self.assertIs(self.widget.use_required_attribute(''), True) self.assertIs(self.widget.use_required_attribute('resume.txt'), True)