mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #10314 -- Added a message prefix argument to Django's test assertions. Thanks to Wes Winham for the original suggestion, and Chistian Oudard for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12273 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
1b3dc8ad9a
commit
7ca9d9306c
4 changed files with 200 additions and 58 deletions
|
@ -1104,23 +1104,32 @@ Assertions
|
|||
|
||||
.. versionadded:: 1.0
|
||||
|
||||
.. versionchanged:: 1.2
|
||||
Addded ``msg_prefix`` argument.
|
||||
|
||||
As Python's normal ``unittest.TestCase`` class implements assertion methods
|
||||
such as ``assertTrue`` and ``assertEquals``, Django's custom ``TestCase`` class
|
||||
provides a number of custom assertion methods that are useful for testing Web
|
||||
applications:
|
||||
|
||||
.. method:: TestCase.assertContains(response, text, count=None, status_code=200)
|
||||
The failure messages given by the assertion methods can be customized
|
||||
with the ``msg_prefix`` argument. This string will be prefixed to any
|
||||
failure message generated by the assertion. This allows you to provide
|
||||
additional details that may help you to identify the location and
|
||||
cause of an failure in your test suite.
|
||||
|
||||
.. method:: TestCase.assertContains(response, text, count=None, status_code=200, msg_prefix='')
|
||||
|
||||
Asserts that a ``Response`` instance produced the given ``status_code`` and
|
||||
that ``text`` appears in the content of the response. If ``count`` is
|
||||
provided, ``text`` must occur exactly ``count`` times in the response.
|
||||
|
||||
.. method:: TestCase.assertNotContains(response, text, status_code=200)
|
||||
.. method:: TestCase.assertNotContains(response, text, status_code=200, msg_prefix='')
|
||||
|
||||
Asserts that a ``Response`` instance produced the given ``status_code`` and
|
||||
that ``text`` does not appears in the content of the response.
|
||||
|
||||
.. method:: TestCase.assertFormError(response, form, field, errors)
|
||||
.. method:: TestCase.assertFormError(response, form, field, errors, msg_prefix='')
|
||||
|
||||
Asserts that a field on a form raises the provided list of errors when
|
||||
rendered on the form.
|
||||
|
@ -1135,19 +1144,19 @@ applications:
|
|||
``errors`` is an error string, or a list of error strings, that are
|
||||
expected as a result of form validation.
|
||||
|
||||
.. method:: TestCase.assertTemplateUsed(response, template_name)
|
||||
.. method:: TestCase.assertTemplateUsed(response, template_name, msg_prefix='')
|
||||
|
||||
Asserts that the template with the given name was used in rendering the
|
||||
response.
|
||||
|
||||
The name is a string such as ``'admin/index.html'``.
|
||||
|
||||
.. method:: TestCase.assertTemplateNotUsed(response, template_name)
|
||||
.. method:: TestCase.assertTemplateNotUsed(response, template_name, msg_prefix='')
|
||||
|
||||
Asserts that the template with the given name was *not* used in rendering
|
||||
the response.
|
||||
|
||||
.. method:: TestCase.assertRedirects(response, expected_url, status_code=302, target_status_code=200)
|
||||
.. method:: TestCase.assertRedirects(response, expected_url, status_code=302, target_status_code=200, msg_prefix='')
|
||||
|
||||
Asserts that the response return a ``status_code`` redirect status, it
|
||||
redirected to ``expected_url`` (including any GET data), and the final
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue