diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2011-08-23 02:32:37 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2011-08-23 02:32:37 +0000 |
| commit | 2664fa189614a4dbbfed5cb683148707ab568f47 (patch) | |
| tree | 31a4924654e21d30b6b9f8cbc026c6771f1a79e6 /docs | |
| parent | 46ef2983ba0434ee9c71385bc709b70a64b35060 (diff) | |
Fixed #15838 -- Promoted assertFieldOutput to a general test utility. Thanks to Ramiro Morales for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16653 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/topics/testing.txt | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/docs/topics/testing.txt b/docs/topics/testing.txt index 7bef4cb52f..eef5b138b1 100644 --- a/docs/topics/testing.txt +++ b/docs/topics/testing.txt @@ -1178,6 +1178,7 @@ basic functionality like: * Saving and restoring the Python warning machinery state. * Checking that a callable :meth:`raises a certain exeception <TestCase.assertRaisesMessage>`. + * :meth:`Testing form field rendering <assertFieldOutput>`. If you need any of the other more complex and heavyweight Django-specific features like: @@ -1523,6 +1524,26 @@ your test suite. failure. Similar to unittest's ``assertRaisesRegexp`` with the difference that ``expected_message`` isn't a regular expression. +.. method:: assertFieldOutput(self, fieldclass, valid, invalid, field_args=None, field_kwargs=None, empty_value=u'') + + Asserts that a form field behaves correctly with various inputs. + + :param fieldclass: the class of the field to be tested. + :param valid: a dictionary mapping valid inputs to their expected cleaned + values. + :param invalid: a dictionary mapping invalid inputs to one or more raised + error messages. + :param field_args: the args passed to instantiate the field. + :param field_kwargs: the kwargs passed to instantiate the field. + :param empty_value: the expected clean output for inputs in ``EMPTY_VALUES``. + + For example, the following code tests that an ``EmailField`` accepts + "a@a.com" as a valid email address, but rejects "aaa" with a reasonable + error message:: + + self.assertFieldOutput(EmailField, {'a@a.com': 'a@a.com'}, {'aaa': [u'Enter a valid e-mail address.']}) + + .. method:: TestCase.assertContains(response, text, count=None, status_code=200, msg_prefix='') Asserts that a ``Response`` instance produced the given ``status_code`` and |
