Пример #1
0
 def assertExpectWidget(self, instance, new_class_,
     equal_attributes=None, new_attributes=None):
     new_instance = floppify_widget(instance)
     self.assertEqual(new_instance.__class__, new_class_)
     if equal_attributes:
         for attribute in equal_attributes:
             self.assertTrue(
                 hasattr(instance, attribute),
                 'Cannot check attribute %r, not available on original '
                 'widget %r' % (attribute, instance))
             self.assertTrue(
                 hasattr(new_instance, attribute),
                 'Cannot check attribute %r, not available on generated '
                 'widget %r' % (attribute, new_instance))
             old_attr = getattr(instance, attribute)
             new_attr = getattr(new_instance, attribute)
             self.assertEqual(old_attr, new_attr,
                 'Original widget\'s attribute was not copied: %r != %r' %
                 (old_attr, new_attr))
     if new_attributes:
         for attribute, value in new_attributes.items():
             self.assertTrue(
                 hasattr(new_instance, attribute),
                 'Cannot check new attribute %r, not available on '
                 'generated widget %r' % (attribute, new_instance))
             new_attr = getattr(new_instance, attribute)
             self.assertEqual(new_attr, value,
                 'Generated widget\'s attribute is not as expected: '
                 '%r != %r' % (new_attr, value))
Пример #2
0
 def assertExpectWidget(self,
                        instance,
                        new_class_,
                        equal_attributes=None,
                        new_attributes=None):
     new_instance = floppify_widget(instance)
     self.assertEqual(new_instance.__class__, new_class_)
     if equal_attributes:
         for attribute in equal_attributes:
             self.assertTrue(
                 hasattr(instance, attribute),
                 'Cannot check attribute %r, not available on original '
                 'widget %r' % (attribute, instance))
             self.assertTrue(
                 hasattr(new_instance, attribute),
                 'Cannot check attribute %r, not available on generated '
                 'widget %r' % (attribute, new_instance))
             old_attr = getattr(instance, attribute)
             new_attr = getattr(new_instance, attribute)
             self.assertEqual(
                 old_attr, new_attr,
                 'Original widget\'s attribute was not copied: %r != %r' %
                 (old_attr, new_attr))
     if new_attributes:
         for attribute, value in new_attributes.items():
             self.assertTrue(
                 hasattr(new_instance, attribute),
                 'Cannot check new attribute %r, not available on '
                 'generated widget %r' % (attribute, new_instance))
             new_attr = getattr(new_instance, attribute)
             self.assertEqual(
                 new_attr, value,
                 'Generated widget\'s attribute is not as expected: '
                 '%r != %r' % (new_attr, value))
Пример #3
0
    def test_multi_widget(self):
        self.assertExpectWidget(forms.widgets.MultiWidget([]), floppyforms.widgets.MultiWidget)

        text_input = forms.widgets.TextInput()
        widget = forms.widgets.MultiWidget([text_input])
        new_widget = floppify_widget(widget)
        self.assertEqual(widget.widgets, new_widget.widgets)
        self.assertTrue(new_widget.widgets[0] is text_input)
Пример #4
0
    def test_checkboxinput_widget(self):
        self.assertExpectWidget(forms.widgets.CheckboxInput(), floppyforms.widgets.CheckboxInput)

        check_test = lambda v: False
        widget = forms.widgets.CheckboxInput(check_test=check_test)
        new_widget = floppify_widget(widget)
        self.assertEqual(widget.check_test, new_widget.check_test)
        self.assertTrue(new_widget.check_test is check_test)
Пример #5
0
    def test_multi_widget(self):
        self.assertExpectWidget(forms.widgets.MultiWidget([]),
                                floppyforms.widgets.MultiWidget)

        text_input = forms.widgets.TextInput()
        widget = forms.widgets.MultiWidget([text_input])
        new_widget = floppify_widget(widget)
        self.assertEqual(widget.widgets, new_widget.widgets)
        self.assertTrue(new_widget.widgets[0] is text_input)
Пример #6
0
    def test_checkboxinput_widget(self):
        self.assertExpectWidget(forms.widgets.CheckboxInput(),
                                floppyforms.widgets.CheckboxInput)

        check_test = lambda v: False
        widget = forms.widgets.CheckboxInput(check_test=check_test)
        new_widget = floppify_widget(widget)
        self.assertEqual(widget.check_test, new_widget.check_test)
        self.assertTrue(new_widget.check_test is check_test)
Пример #7
0
 def test_created_widget_doesnt_leak_attributes_into_original_widget(self):
     widget = forms.TextInput()
     widget.is_required = True
     widget.attrs = {'placeholder': 'Search ...'}
     new_widget = floppify_widget(widget)
     self.assertFalse(widget.__dict__ is new_widget.__dict__)
     new_widget.is_required = False
     self.assertEqual(widget.is_required, True)
     new_widget.attrs['placeholder'] = 'Enter name'
     self.assertEqual(widget.attrs['placeholder'], 'Search ...')
Пример #8
0
 def test_created_widget_doesnt_leak_attributes_into_original_widget(self):
     widget = forms.TextInput()
     widget.is_required = True
     widget.attrs = {'placeholder': 'Search ...'}
     new_widget = floppify_widget(widget)
     self.assertFalse(widget.__dict__ is new_widget.__dict__)
     new_widget.is_required = False
     self.assertEqual(widget.is_required, True)
     new_widget.attrs['placeholder'] = 'Enter name'
     self.assertEqual(widget.attrs['placeholder'], 'Search ...')
Пример #9
0
 def test_created_widget_doesnt_leak_attributes_into_original_widget(self):
     widget = forms.TextInput()
     widget.is_required = True
     widget.attrs = {"placeholder": "Search ..."}
     new_widget = floppify_widget(widget)
     self.assertFalse(widget.__dict__ is new_widget.__dict__)
     new_widget.is_required = False
     self.assertEqual(widget.is_required, True)
     new_widget.attrs["placeholder"] = "Enter name"
     self.assertEqual(widget.attrs["placeholder"], "Search ...")
Пример #10
0
    def test_splitdatetime_widget(self):
        widget = forms.widgets.SplitDateTimeWidget()
        self.assertExpectWidget(widget, floppyforms.widgets.SplitDateTimeWidget)

        widget = forms.widgets.SplitDateTimeWidget(date_format="DATE_FORMAT", time_format="TIME_FORMAT")
        new_widget = floppify_widget(widget)
        self.assertTrue(isinstance(new_widget.widgets[0], floppyforms.widgets.DateInput))
        self.assertTrue(isinstance(new_widget.widgets[1], floppyforms.widgets.TimeInput))
        self.assertEqual(new_widget.widgets[0].format, "DATE_FORMAT")
        self.assertEqual(new_widget.widgets[1].format, "TIME_FORMAT")
Пример #11
0
    def test_splitdatetime_widget(self):
        widget = forms.widgets.SplitDateTimeWidget()
        self.assertExpectWidget(widget,
                                floppyforms.widgets.SplitDateTimeWidget)

        widget = forms.widgets.SplitDateTimeWidget(date_format='DATE_FORMAT',
                                                   time_format='TIME_FORMAT')
        new_widget = floppify_widget(widget)
        self.assertTrue(
            isinstance(new_widget.widgets[0], floppyforms.widgets.DateInput))
        self.assertTrue(
            isinstance(new_widget.widgets[1], floppyforms.widgets.TimeInput))
        self.assertEqual(new_widget.widgets[0].format, 'DATE_FORMAT')
        self.assertEqual(new_widget.widgets[1].format, 'TIME_FORMAT')
Пример #12
0
    def test_splithiddendatetime_widget(self):
        widget = forms.widgets.SplitHiddenDateTimeWidget()
        self.assertExpectWidget(
            widget,
            floppyforms.widgets.SplitHiddenDateTimeWidget)

        widget = forms.widgets.SplitHiddenDateTimeWidget(
            date_format='DATE_FORMAT', time_format='TIME_FORMAT')
        new_widget = floppify_widget(widget)
        self.assertTrue(isinstance(
            new_widget.widgets[0], floppyforms.widgets.DateInput))
        self.assertTrue(isinstance(
            new_widget.widgets[1], floppyforms.widgets.TimeInput))
        self.assertEqual(new_widget.widgets[0].format, 'DATE_FORMAT')
        self.assertEqual(new_widget.widgets[0].is_hidden, True)
        self.assertEqual(new_widget.widgets[1].format, 'TIME_FORMAT')
        self.assertEqual(new_widget.widgets[1].is_hidden, True)