Author: aaugustin
Date: 2012-01-07 02:26:29 -0800 (Sat, 07 Jan 2012)
New Revision: 17345
Modified:
django/trunk/django/test/testcases.py
django/trunk/tests/regressiontests/test_utils/tests.py
Log:
Fixed #17499 -- Ensured assertFieldOutput works for fields that customize the
"required" error message. Thanks dpifke for the report and patch, and claudep
for the tests.
Modified: django/trunk/django/test/testcases.py
===================================================================
--- django/trunk/django/test/testcases.py 2012-01-07 09:05:36 UTC (rev
17344)
+++ django/trunk/django/test/testcases.py 2012-01-07 10:26:29 UTC (rev
17345)
@@ -31,7 +31,7 @@
from django.test.utils import (get_warnings_state, restore_warnings_state,
override_settings)
from django.utils import simplejson, unittest as ut2
-from django.utils.encoding import smart_str
+from django.utils.encoding import smart_str, force_unicode
from django.views.static import serve
__all__ = ('DocTestRunner', 'OutputChecker', 'TestCase', 'TransactionTestCase',
@@ -335,7 +335,7 @@
optional.clean(input)
self.assertEqual(context_manager.exception.messages, errors)
# test required inputs
- error_required = [u'This field is required.']
+ error_required = [force_unicode(required.error_messages['required'])]
for e in EMPTY_VALUES:
with self.assertRaises(ValidationError) as context_manager:
required.clean(e)
Modified: django/trunk/tests/regressiontests/test_utils/tests.py
===================================================================
--- django/trunk/tests/regressiontests/test_utils/tests.py 2012-01-07
09:05:36 UTC (rev 17344)
+++ django/trunk/tests/regressiontests/test_utils/tests.py 2012-01-07
10:26:29 UTC (rev 17345)
@@ -1,6 +1,6 @@
from __future__ import with_statement, absolute_import
-from django.forms import EmailField
+from django.forms import EmailField, IntegerField
from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature
from django.utils.unittest import skip
@@ -149,6 +149,12 @@
self.assertRaises(AssertionError, self.assertFieldOutput, EmailField,
{'[email protected]': 'Wrong output'}, {'aaa': error_invalid})
self.assertRaises(AssertionError, self.assertFieldOutput, EmailField,
{'[email protected]': '[email protected]'}, {'aaa': [u'Come on, gimme some well formatted
data, dude.']})
+ def test_custom_required_message(self):
+ class MyCustomField(IntegerField):
+ default_error_messages = {
+ 'required': u'This is really required.',
+ }
+ self.assertFieldOutput(MyCustomField, {}, {}, empty_value=None)
__test__ = {"API_TEST": r"""
# Some checks of the doctest output normalizer.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.