Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit d9aaad4e36ba2ebba13fd1c36da9eced4f7688ad 1 parent 1cec641
Russell Keith-Magee authored April 15, 2010
5  django/core/exceptions.py
@@ -64,6 +64,11 @@ def __str__(self):
64 64
             return repr(self.message_dict)
65 65
         return repr(self.messages)
66 66
 
  67
+    def __repr__(self):
  68
+        if hasattr(self, 'message_dict'):
  69
+            return 'ValidationError(%s)' % repr(self.message_dict)
  70
+        return 'ValidationError(%s)' % repr(self.messages)
  71
+
67 72
     def update_error_dict(self, error_dict):
68 73
         if hasattr(self, 'message_dict'):
69 74
             if error_dict:
15  tests/modeltests/validators/tests.py
@@ -137,7 +137,20 @@ def test_func(self):
137 137
 # Dynamically assemble a test class with the contents of TEST_DATA
138 138
 
139 139
 class TestSimpleValidators(TestCase):
140  
-    pass
  140
+    def test_single_message(self):
  141
+        v = ValidationError('Not Valid')
  142
+        self.assertEquals(str(v), "[u'Not Valid']")
  143
+        self.assertEquals(repr(v), "ValidationError([u'Not Valid'])")
  144
+
  145
+    def test_message_list(self):
  146
+        v = ValidationError(['First Problem', 'Second Problem'])
  147
+        self.assertEquals(str(v), "[u'First Problem', u'Second Problem']")
  148
+        self.assertEquals(repr(v), "ValidationError([u'First Problem', u'Second Problem'])")
  149
+
  150
+    def test_message_dict(self):
  151
+        v = ValidationError({'first': 'First Problem'})
  152
+        self.assertEquals(str(v), "{'first': 'First Problem'}")
  153
+        self.assertEquals(repr(v), "ValidationError({'first': 'First Problem'})")
141 154
 
142 155
 test_counter = 0
143 156
 for validator, value, expected in TEST_DATA:

0 notes on commit d9aaad4

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