summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorFrançois Freitag <mail@franek.fr>2023-06-15 17:16:46 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-09-05 11:55:37 +0200
commitcafe7266ee69f7e017ddbc0d440084ace559b04b (patch)
treeed48113e9c2002d37c1249ad17931e4ca486448f /docs
parent4f0c0e6fa1ce2e4da9407f122d0c1c27c7f8ad83 (diff)
Fixed #34730 -- Added django.contrib.messages.test.MessagesTestMixin.assertMessages().
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/contrib/messages.txt33
-rw-r--r--docs/releases/5.0.txt4
2 files changed, 36 insertions, 1 deletions
diff --git a/docs/ref/contrib/messages.txt b/docs/ref/contrib/messages.txt
index f5c5621c71..b85f425277 100644
--- a/docs/ref/contrib/messages.txt
+++ b/docs/ref/contrib/messages.txt
@@ -452,3 +452,36 @@ the session cookie settings:
* :setting:`SESSION_COOKIE_DOMAIN`
* :setting:`SESSION_COOKIE_SECURE`
* :setting:`SESSION_COOKIE_HTTPONLY`
+
+Testing
+=======
+
+.. versionadded:: 5.0
+
+This module offers a tailored test assertion method, for testing messages
+attached to an :class:`~.HttpResponse`.
+
+To benefit from this assertion, add ``MessagesTestMixin`` to the class
+hierarchy::
+
+ from django.contrib.messages.test import MessagesTestMixin
+ from django.test import TestCase
+
+
+ class MsgTestCase(MessagesTestMixin, TestCase):
+ pass
+
+Then, inherit from the ``MsgTestCase`` in your tests.
+
+.. module:: django.contrib.messages.test
+
+.. method:: MessagesTestMixin.assertMessages(response, expected_messages, ordered=True)
+
+ Asserts that :mod:`~django.contrib.messages` added to the :class:`response
+ <django.http.HttpResponse>` matches ``expected_messages``.
+
+ ``expected_messages`` is a list of
+ :class:`~django.contrib.messages.Message` objects.
+
+ By default, the comparison is ordering dependent. You can disable this by
+ setting the ``ordered`` argument to ``False``.
diff --git a/docs/releases/5.0.txt b/docs/releases/5.0.txt
index 5a8e44f1fb..5b8abc8498 100644
--- a/docs/releases/5.0.txt
+++ b/docs/releases/5.0.txt
@@ -247,7 +247,9 @@ Minor features
:mod:`django.contrib.messages`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-* ...
+* The new :meth:`.MessagesTestMixin.assertMessages` assertion method allows
+ testing :mod:`~django.contrib.messages` added to a
+ :class:`response <django.http.HttpResponse>`.
:mod:`django.contrib.postgres`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~