Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Fixed #17499 -- Ensured assertFieldOutput works for fields that custo…

…mize the "required" error message. Thanks dpifke for the report and patch, and claudep for the tests.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 4629668 commit 56b37bf1cfcff2ca077cc73e6bf88ba66d0cf642 @aaugustin aaugustin committed
4 django/test/
@@ -31,7 +31,7 @@
from django.test.utils import (get_warnings_state, restore_warnings_state,
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 @@ def assertFieldOutput(self, fieldclass, valid, invalid, field_args=None,
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:
8 tests/regressiontests/test_utils/
@@ -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 @@ def test_assert_field_output(self):
self.assertRaises(AssertionError, self.assertFieldOutput, EmailField, {'': 'Wrong output'}, {'aaa': error_invalid})
self.assertRaises(AssertionError, self.assertFieldOutput, EmailField, {'': ''}, {'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.

0 comments on commit 56b37bf

Please sign in to comment.
Something went wrong with that request. Please try again.