diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2010-04-15 11:19:59 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2010-04-15 11:19:59 +0000 |
| commit | d9aaad4e36ba2ebba13fd1c36da9eced4f7688ad (patch) | |
| tree | 420c96fd91856dfcc8e6ca5c17bb9bdd2b139d29 | |
| parent | 1cec641669d8b4dc507190371e263be914cbcca8 (diff) | |
Fixed #13352 -- Added __repr__ method for Validation Error. Thanks to elpaso66 for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12976 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/core/exceptions.py | 5 | ||||
| -rw-r--r-- | tests/modeltests/validators/tests.py | 15 |
2 files changed, 19 insertions, 1 deletions
diff --git a/django/core/exceptions.py b/django/core/exceptions.py index 5ccd3e8c63..ee6d5fe37b 100644 --- a/django/core/exceptions.py +++ b/django/core/exceptions.py @@ -64,6 +64,11 @@ class ValidationError(Exception): return repr(self.message_dict) return repr(self.messages) + def __repr__(self): + if hasattr(self, 'message_dict'): + return 'ValidationError(%s)' % repr(self.message_dict) + return 'ValidationError(%s)' % repr(self.messages) + def update_error_dict(self, error_dict): if hasattr(self, 'message_dict'): if error_dict: diff --git a/tests/modeltests/validators/tests.py b/tests/modeltests/validators/tests.py index 6c1e6d780f..44ad176747 100644 --- a/tests/modeltests/validators/tests.py +++ b/tests/modeltests/validators/tests.py @@ -137,7 +137,20 @@ def create_simple_test_method(validator, expected, value, num): # Dynamically assemble a test class with the contents of TEST_DATA class TestSimpleValidators(TestCase): - pass + def test_single_message(self): + v = ValidationError('Not Valid') + self.assertEquals(str(v), "[u'Not Valid']") + self.assertEquals(repr(v), "ValidationError([u'Not Valid'])") + + def test_message_list(self): + v = ValidationError(['First Problem', 'Second Problem']) + self.assertEquals(str(v), "[u'First Problem', u'Second Problem']") + self.assertEquals(repr(v), "ValidationError([u'First Problem', u'Second Problem'])") + + def test_message_dict(self): + v = ValidationError({'first': 'First Problem'}) + self.assertEquals(str(v), "{'first': 'First Problem'}") + self.assertEquals(repr(v), "ValidationError({'first': 'First Problem'})") test_counter = 0 for validator, value, expected in TEST_DATA: |
