diff options
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/contrib/messages.txt | 33 |
1 files changed, 33 insertions, 0 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``. |
