summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/internals/deprecation.txt4
-rw-r--r--docs/releases/4.1.txt16
-rw-r--r--docs/topics/testing/tools.txt72
3 files changed, 65 insertions, 27 deletions
diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt
index ab147725c1..eb6d7f7b2f 100644
--- a/docs/internals/deprecation.txt
+++ b/docs/internals/deprecation.txt
@@ -97,6 +97,10 @@ details on these changes.
* The ``django.utils.timezone.utc`` alias to ``datetime.timezone.utc`` will be
removed.
+* Passing a response object and a form/formset name to
+ ``SimpleTestCase.assertFormError()`` and ``assertFormsetError()`` will no
+ longer be allowed.
+
.. _deprecation-removed-in-4.1:
4.1
diff --git a/docs/releases/4.1.txt b/docs/releases/4.1.txt
index 7660780ae5..4413fdfc9a 100644
--- a/docs/releases/4.1.txt
+++ b/docs/releases/4.1.txt
@@ -327,6 +327,10 @@ Tests
* A nested atomic block marked as durable in :class:`django.test.TestCase` now
raises a ``RuntimeError``, the same as outside of tests.
+* :meth:`.SimpleTestCase.assertFormError` and
+ :meth:`~.SimpleTestCase.assertFormsetError` now support passing a
+ form/formset object directly.
+
URLs
~~~~
@@ -449,6 +453,9 @@ Miscellaneous
* The admin log out UI now uses ``POST`` requests.
+* The undocumented ``InlineAdminFormSet.non_form_errors`` property is replaced
+ by the ``non_form_errors()`` method. This is consistent with ``BaseFormSet``.
+
.. _deprecated-features-4.1:
Features deprecated in 4.1
@@ -552,6 +559,15 @@ Miscellaneous
* The :data:`django.utils.timezone.utc` alias to :attr:`datetime.timezone.utc`
is deprecated. Use :attr:`datetime.timezone.utc` directly.
+* Passing a response object and a form/formset name to
+ ``SimpleTestCase.assertFormError()`` and ``assertFormsetError()`` is
+ deprecated. Use::
+
+ assertFormError(response.context['form_name'], …)
+ assertFormsetError(response.context['formset_name'], …)
+
+ or pass the form/formset object directly instead.
+
Features removed in 4.1
=======================
diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt
index c6923c6c87..836dab54e4 100644
--- a/docs/topics/testing/tools.txt
+++ b/docs/topics/testing/tools.txt
@@ -1473,47 +1473,65 @@ your test suite.
self.assertFieldOutput(EmailField, {'a@a.com': 'a@a.com'}, {'aaa': ['Enter a valid email address.']})
-.. method:: SimpleTestCase.assertFormError(response, form, field, errors, msg_prefix='')
+.. method:: SimpleTestCase.assertFormError(form, field, errors, msg_prefix='')
- Asserts that a field on a form raises the provided list of errors when
- rendered on the form.
+ Asserts that a field on a form raises the provided list of errors.
- ``response`` must be a response instance returned by the
- :class:`test client <django.test.Response>`.
+ ``form`` is a ``Form`` instance. The form must be
+ :ref:`bound <ref-forms-api-bound-unbound>` but not necessarily
+ validated (``assertFormError()`` will automatically call ``full_clean()``
+ on the form).
+
+ ``field`` is the name of the field on the form to check. To check the form's
+ :meth:`non-field errors <django.forms.Form.non_field_errors>`, use
+ ``field=None``.
+
+ ``errors`` is a list of all the error strings that the field is expected to
+ have. You can also pass a single error string if you only expect one error
+ which means that ``errors='error message'`` is the same as
+ ``errors=['error message']``.
- ``form`` is the name the ``Form`` instance was given in the template
- context of the response.
+ .. versionchanged:: 4.1
- ``field`` is the name of the field on the form to check. If ``field``
- has a value of ``None``, non-field errors (errors you can access via
- :meth:`form.non_field_errors() <django.forms.Form.non_field_errors>`) will
- be checked.
+ In older versions, using an empty error list with ``assertFormError()``
+ would always pass, regardless of whether the field had any errors or
+ not. Starting from Django 4.1, using ``errors=[]`` will only pass if
+ the field actually has no errors.
- ``errors`` is an error string, or a list of error strings, that are
- expected as a result of form validation.
+ Django 4.1 also changed the behavior of ``assertFormError()`` when a
+ field has multiple errors. In older versions, if a field had multiple
+ errors and you checked for only some of them, the test would pass.
+ Starting from Django 4.1, the error list must be an exact match to the
+ field's actual errors.
-.. method:: SimpleTestCase.assertFormsetError(response, formset, form_index, field, errors, msg_prefix='')
+ .. deprecated:: 4.1
+
+ Support for passing a response object and a form name to
+ ``assertFormError()`` is deprecated and will be removed in Django 5.0.
+ Use the form instance directly instead.
+
+.. method:: SimpleTestCase.assertFormsetError(formset, form_index, field, errors, msg_prefix='')
Asserts that the ``formset`` raises the provided list of errors when
rendered.
- ``response`` must be a response instance returned by the
- :class:`test client <django.test.Response>`.
+ ``formset`` is a ``Formset`` instance. The formset must be bound but not
+ necessarily validated (``assertFormsetError()`` will automatically call the
+ ``full_clean()`` on the formset).
- ``formset`` is the name the ``Formset`` instance was given in the template
- context of the response.
+ ``form_index`` is the number of the form within the ``Formset`` (starting
+ from 0). Use ``form_index=None`` to check the formset's non-form errors,
+ i.e. the errors you get when calling ``formset.non_form_errors()``. In that
+ case you must also use ``field=None``.
- ``form_index`` is the number of the form within the ``Formset``. If
- ``form_index`` has a value of ``None``, non-form errors (errors you can
- access via ``formset.non_form_errors()``) will be checked.
+ ``field`` and ``errors`` have the same meaning as the parameters to
+ ``assertFormError()``.
- ``field`` is the name of the field on the form to check. If ``field``
- has a value of ``None``, non-field errors (errors you can access via
- :meth:`form.non_field_errors() <django.forms.Form.non_field_errors>`) will
- be checked.
+ .. deprecated:: 4.1
- ``errors`` is an error string, or a list of error strings, that are
- expected as a result of form validation.
+ Support for passing a response object and a formset name to
+ ``assertFormsetError()`` is deprecated and will be removed in Django
+ 5.0. Use the formset instance directly instead.
.. method:: SimpleTestCase.assertContains(response, text, count=None, status_code=200, msg_prefix='', html=False)