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
This commit is contained in:
Russell Keith-Magee 2011-08-23 02:32:37 +00:00
parent 46ef2983ba
commit 2664fa1896
47 changed files with 167 additions and 161 deletions

View file

@ -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