def test_needs_multipart_false(self): """ needs_multipart_form should be False if no widgets need it. """ widget = forms.NestedFormWidget(('text', 'text2'), (TextInput(), TextInput())) self.assertFalse(widget.needs_multipart_form)
def test_needs_multipart_true(self): """ needs_multipart_form should be True if any widgets need it. """ widget = forms.NestedFormWidget(('text', 'file'), (TextInput(), FileInput())) self.assertTrue(widget.needs_multipart_form)
def test_text_inputs(self): widget = forms.NestedFormWidget( ('A', 'B', 'C'), ((TextInput()), (TextInput()), (TextInput()))) self.check_html(widget, 'name', ['john', 'winston', 'lennon'], html="""<ul> <li><label>A:</label><input name="name_a" type="text" value="john" /></li> <li><label>B:</label><input name="name_b" type="text" value="winston" /></li> <li><label>C:</label><input name="name_c" type="text" value="lennon" /></li> </ul>""")
def test_deepcopy(self): """ MultiWidget should define __deepcopy__() (#12048). """ w1 = forms.NestedFormWidget(['A', 'B', 'C'], (TextInput(), TextInput(), TextInput())) w2 = copy.deepcopy(w1) w2.labels.append('d') # w2 ought to be independent of w1, since MultiWidget ought # to make a copy of its sub-widgets when it is copied. self.assertEqual(w1.labels, ['A', 'B', 'C'])
def test_nested_multiwidget(self): """ NestedFormWidget can be composed of other NestedFormWidgets. """ widget = forms.NestedFormWidget( ('A', 'B'), (TextInput(), forms.NestedFormWidget(('C', 'D'), (TextInput(), TextInput())))) self.check_html(widget, 'name', ['Singer', ['John', 'Lennon']], html=(""" <ul> <li><label>A:</label><input name="name_a" type="text" value="Singer" /></li> <li><label>B:</label><ul> <li><label>C:</label><input name="name_b_c" type="text" value="John" /></li> <li><label>D:</label><input name="name_b_d" type="text" value="Lennon" /></li> </ul> </li> </ul> """))
def test_constructor_attrs(self): widget = forms.NestedFormWidget( ('A', 'B', 'C'), ((TextInput()), (TextInput()), (TextInput())), attrs={'id': 'bar'}, ) self.check_html(widget, 'name', ['john', 'winston', 'lennon'], html="""<ul> <li><label for="bar_a">A:</label><input id="bar_a" name="name_a" type="text" value="john" /></li> <li><label for="bar_b">B:</label><input id="bar_b" name="name_b" type="text" value="winston" /></li> <li><label for="bar_c">C:</label><input id="bar_c" name="name_c" type="text" value="lennon" /></li> </ul> """)