diff options
Diffstat (limited to 'docs/topics/testing.txt')
| -rw-r--r-- | docs/topics/testing.txt | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/docs/topics/testing.txt b/docs/topics/testing.txt index 0b205cee35..b515d2fac9 100644 --- a/docs/topics/testing.txt +++ b/docs/topics/testing.txt @@ -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 |
