Author: russellm
Date: 2010-04-15 06:19:59 -0500 (Thu, 15 Apr 2010)
New Revision: 12976

Modified:
   django/trunk/django/core/exceptions.py
   django/trunk/tests/modeltests/validators/tests.py
Log:
Fixed #13352 -- Added __repr__ method for Validation Error. Thanks to elpaso66 
for the report.

Modified: django/trunk/django/core/exceptions.py
===================================================================
--- django/trunk/django/core/exceptions.py      2010-04-14 21:27:21 UTC (rev 
12975)
+++ django/trunk/django/core/exceptions.py      2010-04-15 11:19:59 UTC (rev 
12976)
@@ -64,6 +64,11 @@
             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:

Modified: django/trunk/tests/modeltests/validators/tests.py
===================================================================
--- django/trunk/tests/modeltests/validators/tests.py   2010-04-14 21:27:21 UTC 
(rev 12975)
+++ django/trunk/tests/modeltests/validators/tests.py   2010-04-15 11:19:59 UTC 
(rev 12976)
@@ -137,8 +137,21 @@
 # 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:
     name, method = create_simple_test_method(validator, expected, value, 
test_counter)

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to