Ejemplo n.º 1
0
    def test_submit_cancel_form_actions(self):
        """Test custom SubmitCancelFormActions bootstrap layout object"""
        template = loader.get_template_from_string(u"""
            {% load crispy_forms_tags %}
            {% crispy form %}
        """)

        test_form = TestForm()
        test_form.helper = FormHelper()
        test_form.helper.layout = Layout(
            SubmitCancelFormActions()
        )

        c = Context({'form': test_form})

        html = template.render(c)
        self.assertEqual(html.count('class="form-actions'), 1)
        self.assertEqual(html.count('role="button"'), 1)
        self.assertEqual(html.count('href="#"'), 1)
        self.assertEqual(html.count('Cancel'), 1)
        self.assertEqual(html.count('Submit'), 1)

        test_form.helper.layout = Layout(
            SubmitCancelFormActions(cancel_href="/some/url/")
        )
        c = Context({'form': test_form})

        html = template.render(c)
        self.assertEqual(html.count('href="/some/url/'), 1)
Ejemplo n.º 2
0
 def test_filter_by_widget_without_form(self):
     form = TestForm()
     form.helper = FormHelper()
     form.helper.layout = self.advanced_layout
     self.assertRaises(
         FormHelpersException,
         lambda: form.helper.filter_by_widget(forms.PasswordInput))
Ejemplo n.º 3
0
    def test_submit_cancel_form_actions(self):
        """Test custom SubmitCancelFormActions bootstrap layout object"""
        template = loader.get_template_from_string(u"""
            {% load crispy_forms_tags %}
            {% crispy form %}
        """)

        test_form = TestForm()
        test_form.helper = FormHelper()
        test_form.helper.layout = Layout(SubmitCancelFormActions())

        c = Context({'form': test_form})

        html = template.render(c)
        self.assertEqual(html.count('class="form-actions'), 1)
        self.assertEqual(html.count('role="button"'), 1)
        self.assertEqual(html.count('href="#"'), 1)
        self.assertEqual(html.count('Cancel'), 1)
        self.assertEqual(html.count('Submit'), 1)

        test_form.helper.layout = Layout(
            SubmitCancelFormActions(cancel_href="/some/url/"))
        c = Context({'form': test_form})

        html = template.render(c)
        self.assertEqual(html.count('href="/some/url/'), 1)
Ejemplo n.º 4
0
def test_filter_by_widget(advanced_layout):
    form = TestForm()
    form.helper = FormHelper(form)
    form.helper.layout = advanced_layout
    assert form.helper.filter_by_widget(forms.PasswordInput).slice == [
        [[0, 1, 0, 0], 'password1'],
        [[0, 4, 0], 'password2'],
    ]
Ejemplo n.º 5
0
 def test_filter_by_widget(self):
     form = TestForm()
     form.helper = FormHelper(form)
     form.helper.layout = self.advanced_layout
     self.assertEqual(form.helper.filter_by_widget(forms.PasswordInput).slice, [
         [[0, 1, 0, 0], 'password1'],
         [[0, 4, 0], 'password2'],
     ])
Ejemplo n.º 6
0
def test_exclude_by_widget(advanced_layout):
    form = TestForm()
    form.helper = FormHelper(form)
    form.helper.layout = advanced_layout
    assert form.helper.exclude_by_widget(forms.PasswordInput).slice == [
        [[0, 0, 0, 0], 'email'],
        [[0, 3, 0], 'first_name'],
        [[1], 'last_name'],
    ]
Ejemplo n.º 7
0
 def test_filter_by_widget(self):
     form = TestForm()
     form.helper = FormHelper(form)
     form.helper.layout = self.advanced_layout
     self.assertEqual(
         form.helper.filter_by_widget(forms.PasswordInput).slice, [
             [[0, 1, 0, 0], 'password1'],
             [[0, 4, 0], 'password2'],
         ])
Ejemplo n.º 8
0
 def test_exclude_by_widget(self):
     form = TestForm()
     form.helper = FormHelper(form)
     form.helper.layout = self.advanced_layout
     self.assertEqual(form.helper.exclude_by_widget(forms.PasswordInput).slice, [
         [[0, 0, 0, 0], 'email'],
         [[0, 3, 0], 'first_name'],
         [[1], 'last_name'],
     ])
Ejemplo n.º 9
0
 def test_exclude_by_widget(self):
     form = TestForm()
     form.helper = FormHelper(form)
     form.helper.layout = self.advanced_layout
     self.assertEqual(
         form.helper.exclude_by_widget(forms.PasswordInput).slice, [
             [[0, 0, 0, 0], 'email'],
             [[0, 3, 0], 'first_name'],
             [[1], 'last_name'],
         ])
Ejemplo n.º 10
0
def test_exclude_by_widget_and_wrap(advanced_layout):
    form = TestForm()
    form.helper = FormHelper(form)
    form.helper.layout = advanced_layout
    form.helper.exclude_by_widget(forms.PasswordInput).wrap(Field, css_class='hero')
    # Check wrapped fields
    assert isinstance(form.helper.layout[0][0][0][0], Field)
    assert isinstance(form.helper.layout[0][3][0], Field)
    assert isinstance(form.helper.layout[1], Field)
    # Check others stay the same
    assert isinstance(form.helper.layout[0][3][1], HTML)
    assert isinstance(form.helper.layout[0][1][0][0], string_types)
    assert isinstance(form.helper.layout[0][4][0], string_types)
Ejemplo n.º 11
0
    def test_submit_cancel_form_helper(self):
        """Test custom crispy forms layout helper"""
        template = loader.get_template_from_string("""
            {% load crispy_forms_tags %}
            {% crispy form %}
        """)

        test_form = TestForm()
        test_form.helper = SubmitCancelFormHelper(test_form)

        c = Context({'form': test_form})

        html = template.render(c)
        self.assertEqual(html.count('class="form-actions'), 1)
        self.assertEqual(html.count('role="button"'), 1)
        self.assertEqual(html.count('href="#"'), 1)
        self.assertEqual(html.count('Cancel'), 1)
        self.assertEqual(html.count('Submit'), 1)

        test_form = TestForm()
        test_form.helper = SubmitCancelFormHelper(test_form,
                                                  cancel_href="/some/url/")

        c = Context({'form': test_form})

        html = template.render(c)
        self.assertEqual(html.count('href="/some/url/'), 1)
Ejemplo n.º 12
0
def test_filter_by_widget_without_form(advanced_layout):
    form = TestForm()
    form.helper = FormHelper()
    form.helper.layout = advanced_layout
    with pytest.raises(FormHelpersException):
        form.helper.filter_by_widget(forms.PasswordInput)
Ejemplo n.º 13
0
def test_all_without_layout():
    form = TestForm()
    form.helper = FormHelper()
    with pytest.raises(FormHelpersException):
        form.helper.all().wrap(Div)
Ejemplo n.º 14
0
 def test_all_without_layout(self):
     form = TestForm()
     form.helper = FormHelper()
     self.assertRaises(FormHelpersException,
                       lambda: form.helper.all().wrap(Div))
Ejemplo n.º 15
0
 def test_filter_by_widget_without_form(self):
     form = TestForm()
     form.helper = FormHelper()
     form.helper.layout = self.advanced_layout
     self.assertRaises(FormHelpersException, lambda: form.helper.filter_by_widget(forms.PasswordInput))
Ejemplo n.º 16
0
 def test_all_without_layout(self):
     form = TestForm()
     form.helper = FormHelper()
     self.assertRaises(FormHelpersException, lambda: form.helper.all().wrap(Div))