def test_additional_form_fields(self):
        class MyForm(forms.ModelForm):
            subtitle = forms.CharField()

        form_class = modelform_factory(model=Post, form=MyForm)
        form = form_class()
        self.assertTrue(isinstance(form.fields["subtitle"].widget, floppyforms.widgets.TextInput))
    def test_custom_base_form(self):
        class MyForm(forms.ModelForm):
            pass

        form_class = modelform_factory(model=Post, form=MyForm)
        form = form_class()
        self.assertTrue(isinstance(form.fields["title"].widget, floppyforms.widgets.TextInput))
    def test_slug_field(self):
        class MyForm(forms.ModelForm):
            slug = forms.SlugField()

        form_class = modelform_factory(model=Post, form=MyForm)
        widget = form_class().fields['slug'].widget
        self.assertTrue(isinstance(widget, floppyforms.widgets.SlugInput))
        self.assertEqual(widget.input_type, 'text')
    def test_decimal_field(self):
        class MyForm(forms.ModelForm):
            decimal = forms.DecimalField()

        form_class = modelform_factory(model=Post, form=MyForm)
        widget = form_class().fields['decimal'].widget
        self.assertTrue(isinstance(widget, floppyforms.widgets.NumberInput))
        self.assertEqual(widget.input_type, 'number')
    def test_decimal_field(self):
        class MyForm(forms.ModelForm):
            decimal = forms.DecimalField()

        form_class = modelform_factory(model=Post, form=MyForm)
        widget = form_class().fields['decimal'].widget
        self.assertTrue(isinstance(widget, floppyforms.widgets.NumberInput))
        self.assertEqual(widget.input_type, 'number')
    def test_email_field(self):
        class MyForm(forms.ModelForm):
            email = forms.EmailField()

        form_class = modelform_factory(model=Post, form=MyForm, exclude=[])
        widget = form_class().fields['email'].widget
        self.assertTrue(isinstance(widget, floppyforms.widgets.EmailInput))
        self.assertEqual(widget.input_type, 'email')
    def test_ipaddress_field(self):
        class MyForm(forms.ModelForm):
            ipaddress = forms.IPAddressField()

        form_class = modelform_factory(model=Post, form=MyForm)
        widget = form_class().fields['ipaddress'].widget
        self.assertTrue(isinstance(widget, floppyforms.widgets.IPAddressInput))
        self.assertEqual(widget.input_type, 'text')
    def test_float_field(self):
        class MyForm(forms.ModelForm):
            float = forms.FloatField()

        form_class = modelform_factory(model=Post, form=MyForm, exclude=[])
        widget = form_class().fields['float'].widget
        self.assertTrue(isinstance(widget, floppyforms.widgets.NumberInput))
        self.assertEqual(widget.input_type, 'number')
Beispiel #9
0
    def test_email_field(self):
        class MyForm(forms.ModelForm):
            email = forms.EmailField()

        form_class = modelform_factory(model=Post, form=MyForm, exclude=[])
        widget = form_class().fields['email'].widget
        self.assertTrue(isinstance(widget, floppyforms.widgets.EmailInput))
        self.assertEqual(widget.input_type, 'email')
Beispiel #10
0
    def test_float_field(self):
        class MyForm(forms.ModelForm):
            float = forms.FloatField()

        form_class = modelform_factory(model=Post, form=MyForm, exclude=[])
        widget = form_class().fields['float'].widget
        self.assertTrue(isinstance(widget, floppyforms.widgets.NumberInput))
        self.assertEqual(widget.input_type, 'number')
    def test_url_field(self):
        class MyForm(forms.ModelForm):
            url = forms.URLField()

        form_class = modelform_factory(model=Post, form=MyForm)
        widget = form_class().fields['url'].widget
        self.assertTrue(isinstance(widget, floppyforms.widgets.URLInput))
        self.assertEqual(widget.input_type, 'url')
    def test_integer_field(self):
        class MyForm(forms.ModelForm):
            integer = forms.IntegerField()

        form_class = modelform_factory(model=Post, form=MyForm)
        widget = form_class().fields['integer'].widget
        self.assertTrue(isinstance(widget, floppyforms.widgets.NumberInput))
        self.assertEqual(widget.input_type, 'number')
    def test_integer_field(self):
        class MyForm(forms.ModelForm):
            integer = forms.IntegerField()

        form_class = modelform_factory(model=Post, form=MyForm)
        widget = form_class().fields['integer'].widget
        self.assertTrue(isinstance(widget, floppyforms.widgets.NumberInput))
        self.assertEqual(widget.input_type, 'number')
    def test_url_field(self):
        class MyForm(forms.ModelForm):
            url = forms.URLField()

        form_class = modelform_factory(model=Post, form=MyForm)
        widget = form_class().fields['url'].widget
        self.assertTrue(isinstance(widget, floppyforms.widgets.URLInput))
        self.assertEqual(widget.input_type, 'url')
    def test_ipaddress_field(self):
        class MyForm(forms.ModelForm):
            ipaddress = forms.IPAddressField()

        form_class = modelform_factory(model=Post, form=MyForm)
        widget = form_class().fields['ipaddress'].widget
        self.assertTrue(isinstance(widget, floppyforms.widgets.IPAddressInput))
        self.assertEqual(widget.input_type, 'text')
    def test_slug_field(self):
        class MyForm(forms.ModelForm):
            slug = forms.SlugField()

        form_class = modelform_factory(model=Post, form=MyForm)
        widget = form_class().fields['slug'].widget
        self.assertTrue(isinstance(widget, floppyforms.widgets.SlugInput))
        self.assertEqual(widget.input_type, 'text')
    def test_additional_form_fields(self):
        class MyForm(forms.ModelForm):
            subtitle = forms.CharField()

        form_class = modelform_factory(model=Post, form=MyForm)
        form = form_class()
        self.assertTrue(
            isinstance(form.fields['subtitle'].widget,
                       floppyforms.widgets.TextInput))
    def test_custom_base_form(self):
        class MyForm(forms.ModelForm):
            pass

        form_class = modelform_factory(model=Post, form=MyForm)
        form = form_class()
        self.assertTrue(
            isinstance(form.fields['title'].widget,
                       floppyforms.widgets.TextInput))
    def test_splitdatetime_field(self):
        class MyForm(forms.ModelForm):
            splitdatetime = forms.SplitDateTimeField()

        form_class = modelform_factory(model=Post, form=MyForm)
        widget = form_class().fields["splitdatetime"].widget
        self.assertTrue(isinstance(widget, floppyforms.widgets.SplitDateTimeWidget))
        self.assertTrue(isinstance(widget.widgets[0], floppyforms.widgets.DateInput))
        self.assertTrue(isinstance(widget.widgets[1], floppyforms.widgets.TimeInput))
    def test_declared_fields(self):
        class MyForm(forms.ModelForm):
            subtitle = forms.CharField()

        form_class = modelform_factory(model=Post, form=MyForm)
        self.assertTrue(isinstance(form_class.base_fields["subtitle"].widget, floppyforms.widgets.TextInput))
        self.assertTrue(isinstance(form_class.declared_fields["subtitle"].widget, floppyforms.widgets.TextInput))

        self.assertTrue(isinstance(form_class.base_fields["title"].widget, floppyforms.widgets.TextInput))
    def test_splitdatetime_field(self):
        class MyForm(forms.ModelForm):
            splitdatetime = forms.SplitDateTimeField()

        form_class = modelform_factory(model=Post, form=MyForm)
        widget = form_class().fields['splitdatetime'].widget
        self.assertTrue(
            isinstance(widget, floppyforms.widgets.SplitDateTimeWidget))
        self.assertTrue(
            isinstance(widget.widgets[0], floppyforms.widgets.DateInput))
        self.assertTrue(
            isinstance(widget.widgets[1], floppyforms.widgets.TimeInput))
    def test_subclassing_forms(self):
        class MyForm(forms.ModelForm):
            subtitle = forms.CharField()

            class Meta:
                model = Post

        class ChildForm(MyForm):
            created = forms.DateField()

        form_class = modelform_factory(model=Post, form=ChildForm)
        form = form_class()
        self.assertTrue(isinstance(form.fields["title"].widget, floppyforms.widgets.TextInput))
        self.assertTrue(isinstance(form.fields["subtitle"].widget, floppyforms.widgets.TextInput))
        self.assertTrue(isinstance(form.fields["created"].widget, floppyforms.widgets.DateInput))
    def test_declared_fields(self):
        class MyForm(forms.ModelForm):
            subtitle = forms.CharField()

        form_class = modelform_factory(model=Post, form=MyForm)
        self.assertTrue(
            isinstance(form_class.base_fields['subtitle'].widget,
                       floppyforms.widgets.TextInput))
        self.assertTrue(
            isinstance(form_class.declared_fields['subtitle'].widget,
                       floppyforms.widgets.TextInput))

        self.assertTrue(
            isinstance(form_class.base_fields['title'].widget,
                       floppyforms.widgets.TextInput))
    def test_subclassing_forms(self):
        class MyForm(forms.ModelForm):
            subtitle = forms.CharField()

            class Meta:
                model = Post

        class ChildForm(MyForm):
            created = forms.DateField()

        form_class = modelform_factory(model=Post, form=ChildForm)
        form = form_class()
        self.assertTrue(
            isinstance(form.fields['title'].widget,
                       floppyforms.widgets.TextInput))
        self.assertTrue(
            isinstance(form.fields['subtitle'].widget,
                       floppyforms.widgets.TextInput))
        self.assertTrue(
            isinstance(form.fields['created'].widget,
                       floppyforms.widgets.DateInput))
 def test_modelform_factory(self):
     form_class = modelform_factory(Post)
     self.assertTrue(form_class)
     field = form_class.base_fields['title']
     self.assertTrue(isinstance(field.widget, floppyforms.TextInput))
 def test_modelform_factory(self):
     form_class = modelform_factory(Post)
     self.assertTrue(form_class)
     field = form_class.base_fields['title']
     self.assertTrue(isinstance(field.widget, floppyforms.TextInput))