From 482ba9246e1838378a7e320c247fa7338ca49b40 Mon Sep 17 00:00:00 2001 From: CHI Cheng Date: Wed, 2 May 2018 23:20:04 +1000 Subject: [2.0.x] Fixed #29375 -- Removed empty action attribute on HTML forms. Backport of 4660ce5a6930e07899ed083801845ee4c44c09df from master --- .../templates/forms_tests/article_form.html | 2 +- tests/forms_tests/tests/test_forms.py | 34 +++++++++++----------- tests/templates/form_view.html | 2 +- tests/templates/login.html | 2 +- tests/test_utils/tests.py | 6 ++-- 5 files changed, 23 insertions(+), 23 deletions(-) (limited to 'tests') diff --git a/tests/forms_tests/templates/forms_tests/article_form.html b/tests/forms_tests/templates/forms_tests/article_form.html index 8ab7a85bb9..3edd8713de 100644 --- a/tests/forms_tests/templates/forms_tests/article_form.html +++ b/tests/forms_tests/templates/forms_tests/article_form.html @@ -1,6 +1,6 @@ -
{% csrf_token %} + {% csrf_token %} {{ form.as_p }}
diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index 3f4fb4e10b..2e7e3df747 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -2482,13 +2482,13 @@ Password: return 'VALID: %r' % sorted(form.cleaned_data.items()) t = Template( - '
\n' + '\n' '\n{{ form }}\n
\n\n
' ) return t.render(Context({'form': form})) # Case 1: GET (an empty form, with no errors).) - self.assertHTMLEqual(my_function('GET', {}), """
+ self.assertHTMLEqual(my_function('GET', {}), """ @@ -2499,7 +2499,7 @@ Password: # Case 2: POST with erroneous data (a redisplayed form, with errors).) self.assertHTMLEqual( my_function('POST', {'username': 'this-is-a-long-username', 'password1': 'foo', 'password2': 'bar'}), - """ + """
Username:
Password1:
  • Please make sure your passwords match.
Username:
    @@ -2535,13 +2535,13 @@ Password: # fields. Note, however, that this flexibility comes with the responsibility of # displaying all the errors, including any that might not be associated with a # particular field. - t = Template(''' + t = Template(''' {{ form.username.errors.as_ul }}

    {{ form.password1.errors.as_ul }}

    {{ form.password2.errors.as_ul }}

    ''') - self.assertHTMLEqual(t.render(Context({'form': UserRegistration(auto_id=False)})), """
    + self.assertHTMLEqual(t.render(Context({'form': UserRegistration(auto_id=False)})), """

    @@ -2549,7 +2549,7 @@ Password:
    """) self.assertHTMLEqual( t.render(Context({'form': UserRegistration({'username': 'django'}, auto_id=False)})), - """
    + """

    • This field is required.

    @@ -2563,13 +2563,13 @@ Password: # a field by using the 'label' argument to a Field class. If you don't specify # 'label', Django will use the field name with underscores converted to spaces, # and the initial letter capitalized. - t = Template(''' + t = Template('''

    ''') - self.assertHTMLEqual(t.render(Context({'form': UserRegistration(auto_id=False)})), """
    + self.assertHTMLEqual(t.render(Context({'form': UserRegistration(auto_id=False)})), """

    @@ -2580,19 +2580,19 @@ Password: # wrapped around it, but *only* if the given field has an "id" attribute. # Recall from above that passing the "auto_id" argument to a Form gives each # field an "id" attribute. - t = Template(''' + t = Template('''

    {{ form.username.label_tag }} {{ form.username }}

    {{ form.password1.label_tag }} {{ form.password1 }}

    {{ form.password2.label_tag }} {{ form.password2 }}

    ''') - self.assertHTMLEqual(t.render(Context({'form': UserRegistration(auto_id=False)})), """
    + self.assertHTMLEqual(t.render(Context({'form': UserRegistration(auto_id=False)})), """

    Username:

    Password1:

    Password2:

    """) - self.assertHTMLEqual(t.render(Context({'form': UserRegistration(auto_id='id_%s')})), """
    + self.assertHTMLEqual(t.render(Context({'form': UserRegistration(auto_id='id_%s')})), """

    @@ -2604,7 +2604,7 @@ Password: # User form.[field].help_text to output a field's help text. If the given field # does not have help text, nothing will be output. - t = Template(''' + t = Template('''

    {{ form.username.label_tag }} {{ form.username }}
    {{ form.username.help_text }}

    {{ form.password1.label_tag }} {{ form.password1 }}

    {{ form.password2.label_tag }} {{ form.password2 }}

    @@ -2612,7 +2612,7 @@ Password:
    ''') self.assertHTMLEqual( t.render(Context({'form': UserRegistration(auto_id=False)})), - """
    + """

    Username:
    Good luck picking a username that doesn't already exist.

    Password1:

    @@ -2629,7 +2629,7 @@ Good luck picking a username that doesn't already exist.

    # the errors caused by Form.clean() -- use {{ form.non_field_errors }} in the # template. If used on its own, it is displayed as a
      (or an empty string, if # the list of errors is empty). You can also use it in {% if %} statements. - t = Template(''' + t = Template(''' {{ form.username.errors.as_ul }}

      {{ form.password1.errors.as_ul }}

      {{ form.password2.errors.as_ul }}

      @@ -2639,14 +2639,14 @@ Good luck picking a username that doesn't already exist.

      t.render(Context({ 'form': UserRegistration({'username': 'django', 'password1': 'foo', 'password2': 'bar'}, auto_id=False) })), - """ + """

      """ ) - t = Template('''
      + t = Template(''' {{ form.non_field_errors }} {{ form.username.errors.as_ul }}

      {{ form.password1.errors.as_ul }}

      @@ -2657,7 +2657,7 @@ Good luck picking a username that doesn't already exist.

      t.render(Context({ 'form': UserRegistration({'username': 'django', 'password1': 'foo', 'password2': 'bar'}, auto_id=False) })), - """ + """
      • Please make sure your passwords match.

      diff --git a/tests/templates/form_view.html b/tests/templates/form_view.html index 1ef410fb71..16945a018c 100644 --- a/tests/templates/form_view.html +++ b/tests/templates/form_view.html @@ -2,7 +2,7 @@ {% block title %}Submit data{% endblock %} {% block content %}

      {{ message }}

      - + {% if form.errors %}

      Please correct the errors below:

      {% endif %} diff --git a/tests/templates/login.html b/tests/templates/login.html index d1aa5f6b7c..3b38fc7ad6 100644 --- a/tests/templates/login.html +++ b/tests/templates/login.html @@ -5,7 +5,7 @@

      Your username and password didn't match. Please try again.

      {% endif %} - + diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py index 80ee5a27b5..e2512920c1 100644 --- a/tests/test_utils/tests.py +++ b/tests/test_utils/tests.py @@ -695,15 +695,15 @@ class HTMLEqualTests(SimpleTestCase): def test_contains_html(self): response = HttpResponse(''' - This is a form: + This is a form: ''') self.assertNotContains(response, "") - self.assertContains(response, '') + self.assertContains(response, '') self.assertContains(response, "", html=True) - self.assertNotContains(response, '', html=True) + self.assertNotContains(response, '', html=True) invalid_response = HttpResponse('''>''') -- cgit v1.3
      {{ form.username }}
      {{ form.password }}