Beispiel #1
0
    def test_DictCharWidget_renders_with_initial_when_no_value(self):
        """Widgets should use initial value if rendered without value."""
        names = [factory.make_name()]
        initials = [factory.make_name()]
        labels = [factory.make_name()]
        mock_widget = Mock()
        mock_widget.configure_mock(**{"render.return_value": ""})
        widget = DictCharWidget([mock_widget, widgets.TextInput],
                                names, initials, labels, skip_check=True)
        widget.render('foo', [])

        self.assertThat(
            mock_widget.render, MockCalledOnceWith(ANY, initials[0], ANY))
Beispiel #2
0
 def test_DictCharWidget_renders_fieldset_with_label_and_field_names(self):
     names = [factory.make_string(), factory.make_string()]
     initials = []
     labels = [factory.make_string(), factory.make_string()]
     values = [factory.make_string(), factory.make_string()]
     widget = DictCharWidget(
         [widgets.TextInput, widgets.TextInput, widgets.CheckboxInput],
         names,
         initials,
         labels,
         skip_check=True,
     )
     name = factory.make_string()
     html_widget = fromstring("<root>" + widget.render(name, values) +
                              "</root>")
     widget_names = XPath("fieldset/input/@name")(html_widget)
     widget_labels = XPath("fieldset/label/text()")(html_widget)
     widget_values = XPath("fieldset/input/@value")(html_widget)
     expected_names = [
         "%s_%s" % (name, widget_name) for widget_name in names
     ]
     self.assertEqual(
         [expected_names, labels, values],
         [widget_names, widget_labels, widget_values],
     )
Beispiel #3
0
 def test_DictCharWidget_renders_with_empty_string_as_input_data(self):
     names = [factory.make_string(), factory.make_string()]
     initials = []
     labels = [factory.make_string(), factory.make_string()]
     widget = DictCharWidget(
         [widgets.TextInput, widgets.TextInput, widgets.CheckboxInput],
         names, initials, labels, skip_check=True)
     name = factory.make_string()
     html_widget = fromstring(
         '<root>' + widget.render(name, '') + '</root>')
     widget_names = XPath('fieldset/input/@name')(html_widget)
     widget_labels = XPath('fieldset/label/text()')(html_widget)
     expected_names = [
         "%s_%s" % (name, widget_name) for widget_name in names]
     self.assertEqual(
         [expected_names, labels],
         [widget_names, widget_labels])
Beispiel #4
0
 def test_DictCharWidget_renders_with_empty_string_as_input_data(self):
     names = [factory.getRandomString(), factory.getRandomString()]
     labels = [factory.getRandomString(), factory.getRandomString()]
     widget = DictCharWidget(
         [widgets.TextInput, widgets.TextInput, widgets.CheckboxInput],
         names, labels, skip_check=True)
     name = factory.getRandomString()
     self.assertEqual(
         '<fieldset>'
         '<label>%s</label>'
         '<input type="text" name="%s" />'
         '<label>%s</label>'
         '<input type="text" name="%s" />'
         '</fieldset>' %
             (
                 labels[0], '%s_%s' % (name, names[0]),
                 labels[1], '%s_%s' % (name, names[1]),
             ),
         widget.render(name, ''))
Beispiel #5
0
 def test_DictCharWidget_renders_fieldset_with_label_and_field_names(self):
     names = [factory.getRandomString(), factory.getRandomString()]
     labels = [factory.getRandomString(), factory.getRandomString()]
     values = [factory.getRandomString(), factory.getRandomString()]
     widget = DictCharWidget(
         [widgets.TextInput, widgets.TextInput, widgets.CheckboxInput],
         names, labels, skip_check=True)
     name = factory.getRandomString()
     self.assertEqual(
         '<fieldset>'
         '<label>%s</label>'
         '<input type="text" name="%s" value="%s" />'
         '<label>%s</label>'
         '<input type="text" name="%s" value="%s" />'
         '</fieldset>' %
             (
                 labels[0], '%s_%s' % (name, names[0]), values[0],
                 labels[1], '%s_%s' % (name, names[1]), values[1],
             ),
         widget.render(name, values))
Beispiel #6
0
 def test_DictCharWidget_renders_fieldset_with_label_and_field_names(self):
     names = [factory.getRandomString(), factory.getRandomString()]
     labels = [factory.getRandomString(), factory.getRandomString()]
     values = [factory.getRandomString(), factory.getRandomString()]
     widget = DictCharWidget(
         [widgets.TextInput, widgets.TextInput, widgets.CheckboxInput],
         names,
         labels,
         skip_check=True)
     name = factory.getRandomString()
     html_widget = fromstring('<root>' + widget.render(name, values) +
                              '</root>')
     widget_names = XPath('fieldset/input/@name')(html_widget)
     widget_labels = XPath('fieldset/label/text()')(html_widget)
     widget_values = XPath('fieldset/input/@value')(html_widget)
     expected_names = [
         "%s_%s" % (name, widget_name) for widget_name in names
     ]
     self.assertEqual([expected_names, labels, values],
                      [widget_names, widget_labels, widget_values])
Beispiel #7
0
 def test_empty_DictCharWidget_renders_as_empty_string(self):
     widget = DictCharWidget(
         [widgets.CheckboxInput], [], [], skip_check=True)
     self.assertEqual('', widget.render(factory.getRandomString(), ''))
Beispiel #8
0
 def test_empty_DictCharWidget_renders_as_empty_string(self):
     widget = DictCharWidget([widgets.CheckboxInput], [], [], [],
                             skip_check=True)
     self.assertEqual("", widget.render(factory.make_string(), ""))
Beispiel #9
0
 def test_empty_DictCharWidget_renders_as_empty_string(self):
     widget = DictCharWidget([widgets.CheckboxInput], [], [],
                             skip_check=True)
     self.assertEqual('', widget.render(factory.getRandomString(), ''))