Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 14 additions & 28 deletions tests/test_form_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ def test_inputs():
form_helper.add_input(Hidden("my-hidden", "Hidden"))
form_helper.add_input(Button("my-button", "Button"))

template = Template(
"""
template = Template("""
{% load crispy_forms_tags %}
{% crispy form form_helper %}
"""
)
""")
c = Context({"form": SampleForm(), "form_helper": form_helper})
html = template.render(c)

Expand Down Expand Up @@ -72,12 +70,10 @@ def test_form_with_helper_without_layout():
form_helper.form_action = "simpleAction"
form_helper.form_error_title = "ERRORS"

template = Template(
"""
template = Template("""
{% load crispy_forms_tags %}
{% crispy testForm form_helper %}
"""
)
""")

# now we render it, with errors
form = SampleForm({"password1": "wargame", "password2": "god"})
Expand Down Expand Up @@ -112,12 +108,10 @@ def test_form_show_errors_non_field_errors(settings):
form.helper.form_show_errors = True
form.is_valid()

template = Template(
"""
template = Template("""
{% load crispy_forms_tags %}
{% crispy testForm %}
"""
)
""")

# First we render with errors
c = Context({"testForm": form})
Expand Down Expand Up @@ -234,12 +228,10 @@ def test_template_helper_access():


def test_without_helper():
template = Template(
"""
template = Template("""
{% load crispy_forms_tags %}
{% crispy form %}
"""
)
""")
c = Context({"form": SampleForm()})
html = template.render(c)

Expand All @@ -250,12 +242,10 @@ def test_without_helper():


def test_formset_with_helper_without_layout():
template = Template(
"""
template = Template("""
{% load crispy_forms_tags %}
{% crispy testFormSet formset_helper %}
"""
)
""")

form_helper = FormHelper()
form_helper.form_id = "thisFormsetRocks"
Expand Down Expand Up @@ -291,12 +281,10 @@ def test_formset_with_helper_without_layout():

def test_CSRF_token_POST_form():
form_helper = FormHelper()
template = Template(
"""
template = Template("""
{% load crispy_forms_tags %}
{% crispy form form_helper %}
"""
)
""")

# The middleware only initializes the CSRF token when processing a real request
# So using RequestContext or csrf(request) here does not work.
Expand All @@ -317,12 +305,10 @@ def test_CSRF_token_POST_form():
def test_CSRF_token_GET_form():
form_helper = FormHelper()
form_helper.form_method = "GET"
template = Template(
"""
template = Template("""
{% load crispy_forms_tags %}
{% crispy form form_helper %}
"""
)
""")

c = Context(
{
Expand Down
66 changes: 22 additions & 44 deletions tests/test_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ def test_invalid_unicode_characters(settings):
form_helper = FormHelper()
form_helper.add_layout(Layout("españa"))

template = Template(
"""
template = Template("""
{% load crispy_forms_tags %}
{% crispy form form_helper %}
"""
)
""")
c = Context({"form": SampleForm(), "form_helper": form_helper})
settings.CRISPY_FAIL_SILENTLY = False
with pytest.raises(Exception):
Expand Down Expand Up @@ -81,12 +79,10 @@ class Meta:
form_helper = FormHelper()
form_helper.layout = Layout("first_name")

template = Template(
"""
template = Template("""
{% load crispy_forms_tags %}
{% crispy form form_helper %}
"""
)
""")
c = Context({"form": form, "form_helper": form_helper})
html = template.render(c)
assert "email" not in html
Expand All @@ -96,12 +92,10 @@ def test_layout_unresolved_field(settings):
form_helper = FormHelper()
form_helper.add_layout(Layout("typo"))

template = Template(
"""
template = Template("""
{% load crispy_forms_tags %}
{% crispy form form_helper %}
"""
)
""")
c = Context({"form": SampleForm(), "form_helper": form_helper})
settings.CRISPY_FAIL_SILENTLY = False
with pytest.raises(Exception):
Expand All @@ -112,12 +106,10 @@ def test_double_rendered_field(settings):
form_helper = FormHelper()
form_helper.add_layout(Layout("is_company", "is_company"))

template = Template(
"""
template = Template("""
{% load crispy_forms_tags %}
{% crispy form form_helper %}
"""
)
""")
c = Context({"form": SampleForm(), "form_helper": form_helper})
settings.CRISPY_FAIL_SILENTLY = False
with pytest.raises(Exception):
Expand All @@ -131,14 +123,12 @@ class ExampleForm(forms.Form):
form = ExampleForm()
form2 = SampleForm()

template = Template(
"""
template = Template("""
{% load crispy_forms_tags %}
{{ form.as_ul }}
{% crispy form2 %}
{{ form.as_ul }}
"""
)
""")
c = Context({"form": form, "form2": form2})
html = template.render(c)

Expand Down Expand Up @@ -168,23 +158,19 @@ def test_layout_fieldset_row_html_with_unicode_fieldnames():
css_class="rows",
),
HTML('<a href="#" id="testLink">test link</a>'),
HTML(
"""
HTML("""
{% if flag %}{{ message }}{% endif %}
"""
),
"""),
"first_name",
"last_name",
),
)
)

template = Template(
"""
template = Template("""
{% load crispy_forms_tags %}
{% crispy form form_helper %}
"""
)
""")
c = Context(
{
"form": SampleForm(),
Expand All @@ -208,12 +194,10 @@ def test_layout_fieldset_row_html_with_unicode_fieldnames():


def test_change_layout_dynamically_delete_field():
template = Template(
"""
template = Template("""
{% load crispy_forms_tags %}
{% crispy form form_helper %}
"""
)
""")

form = SampleForm()
form_helper = FormHelper()
Expand Down Expand Up @@ -246,12 +230,10 @@ def test_change_layout_dynamically_delete_field():


def test_column_has_css_classes():
template = Template(
"""
template = Template("""
{% load crispy_forms_tags %}
{% crispy form form_helper %}
"""
)
""")

form = SampleForm()
form_helper = FormHelper()
Expand All @@ -275,12 +257,10 @@ def test_column_has_css_classes():


def test_bs4_column_css_classes():
template = Template(
"""
template = Template("""
{% load crispy_forms_tags %}
{% crispy form form_helper %}
"""
)
""")

form = SampleForm()
form_helper = FormHelper()
Expand Down Expand Up @@ -401,12 +381,10 @@ def test_modelformset_layout():


def test_i18n():
template = Template(
"""
template = Template("""
{% load crispy_forms_tags %}
{% crispy form form.helper %}
"""
)
""")
form = SampleForm()
form_helper = FormHelper()
form_helper.layout = Layout(
Expand Down
12 changes: 4 additions & 8 deletions tests/test_layout_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@


def test_multiwidget_field():
template = Template(
"""
template = Template("""
{% load crispy_forms_tags %}
{% crispy form %}
"""
)
""")

test_form = SampleForm()
test_form.helper = FormHelper()
Expand All @@ -76,12 +74,10 @@ def test_multiwidget_field():


def test_field_type_hidden():
template = Template(
"""
template = Template("""
{% load crispy_forms_tags %}
{% crispy test_form %}
"""
)
""")

test_form = SampleForm()
test_form.helper = FormHelper()
Expand Down
Loading
Loading