Refs #9230 -- Added complementary tests for widget iterations
This commit is contained in:
parent
21efb5eb74
commit
97e1160be5
|
@ -446,6 +446,13 @@ class FormsTestCase(SimpleTestCase):
|
|||
<li><label for="id_language_1"><input type="radio" id="id_language_1" value="J" name="language" /> Java</label></li>
|
||||
</ul></p>""")
|
||||
|
||||
# Test iterating on individual radios in a template
|
||||
t = Template('{% for radio in form.language %}<div class="myradio">{{ radio }}</div>{% endfor %}')
|
||||
self.assertHTMLEqual(t.render(Context({'form': f})), """<div class="myradio"><label for="id_language_0">
|
||||
<input id="id_language_0" name="language" type="radio" value="P" /> Python</label></div>
|
||||
<div class="myradio"><label for="id_language_1">
|
||||
<input id="id_language_1" name="language" type="radio" value="J" /> Java</label></div>""")
|
||||
|
||||
def test_form_with_iterable_boundfield(self):
|
||||
class BeatleForm(Form):
|
||||
name = ChoiceField(choices=[('john', 'John'), ('paul', 'Paul'), ('george', 'George'), ('ringo', 'Ringo')], widget=RadioSelect)
|
||||
|
@ -538,6 +545,12 @@ class FormsTestCase(SimpleTestCase):
|
|||
<li><label><input checked="checked" type="checkbox" name="composers" value="J" /> John Lennon</label></li>
|
||||
<li><label><input checked="checked" type="checkbox" name="composers" value="P" /> Paul McCartney</label></li>
|
||||
</ul>""")
|
||||
# Test iterating on individual checkboxes in a template
|
||||
t = Template('{% for checkbox in form.composers %}<div class="mycheckbox">{{ checkbox }}</div>{% endfor %}')
|
||||
self.assertHTMLEqual(t.render(Context({'form': f})), """<div class="mycheckbox"><label>
|
||||
<input checked="checked" name="composers" type="checkbox" value="J" /> John Lennon</label></div>
|
||||
<div class="mycheckbox"><label>
|
||||
<input checked="checked" name="composers" type="checkbox" value="P" /> Paul McCartney</label></div>""")
|
||||
|
||||
def test_checkbox_auto_id(self):
|
||||
# Regarding auto_id, CheckboxSelectMultiple is a special case. Each checkbox
|
||||
|
|
Loading…
Reference in New Issue