summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/topics/testing.txt21
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