Added test for ValidationError.messages

This commit is contained in:
Brad Walker 2014-11-20 14:26:48 -05:00 committed by Tim Graham
parent 5c481db295
commit f273cedc76
2 changed files with 16 additions and 0 deletions

View File

View File

@ -0,0 +1,16 @@
import unittest
from django.core.exceptions import ValidationError
class TestValidationError(unittest.TestCase):
def test_messages_concatenates_error_dict_values(self):
message_dict = {}
with self.assertRaises(TypeError):
ValidationError(message_dict).messages
message_dict['field1'] = ['E1', 'E2']
exception = ValidationError(message_dict)
self.assertEqual(sorted(exception.messages), ['E1', 'E2'])
message_dict['field2'] = ['E3', 'E4']
exception = ValidationError(message_dict)
self.assertEqual(sorted(exception.messages), ['E1', 'E2', 'E3', 'E4'])