From cafe7266ee69f7e017ddbc0d440084ace559b04b Mon Sep 17 00:00:00 2001 From: François Freitag Date: Thu, 15 Jun 2023 17:16:46 +0200 Subject: Fixed #34730 -- Added django.contrib.messages.test.MessagesTestMixin.assertMessages(). --- docs/ref/contrib/messages.txt | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'docs/ref') 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 + ` 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``. -- cgit v1.3