1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Rewrote form widget tests as proper unittests.

This is preparation for landing the template-based widget rendering
patch and goes a long way to making these tests more useful for future
development. The old doctest heritage is strong here.
This commit is contained in:
Preston Timmons
2015-08-30 21:13:42 -05:00
parent 5153a3bfdc
commit 4c30fa905d
26 changed files with 2270 additions and 1825 deletions

View File

@@ -0,0 +1,34 @@
from django.forms import Textarea
from django.utils.safestring import mark_safe
from .base import WidgetTest
class TextareaTest(WidgetTest):
widget = Textarea()
def test_render(self):
self.check_html(self.widget, 'msg', 'value', html=(
'<textarea rows="10" cols="40" name="msg">value</textarea>'
))
def test_render_required(self):
widget = Textarea()
widget.is_required = True
self.check_html(widget, 'msg', 'value', html='<textarea rows="10" cols="40" name="msg">value</textarea>')
def test_render_empty(self):
self.check_html(self.widget, 'msg', '', html='<textarea rows="10" cols="40" name="msg"></textarea>')
def test_render_none(self):
self.check_html(self.widget, 'msg', None, html='<textarea rows="10" cols="40" name="msg"></textarea>')
def test_escaping(self):
self.check_html(self.widget, 'msg', 'some "quoted" & ampersanded value', html=(
'<textarea rows="10" cols="40" name="msg">some &quot;quoted&quot; &amp; ampersanded value</textarea>'
))
def test_mark_safe(self):
self.check_html(self.widget, 'msg', mark_safe('pre &quot;quoted&quot; value'), html=(
'<textarea rows="10" cols="40" name="msg">pre &quot;quoted&quot; value</textarea>'
))