Ticket #24988: 24988-test.diff

File 24988-test.diff, 1.2 KB (added by Tim Graham, 9 years ago)
  • django/core/exceptions.py

    diff --git a/django/core/exceptions.py b/django/core/exceptions.py
    index c92e8d4..ead960f 100644
    a b class ValidationError(Exception):  
    113113                if not isinstance(messages, ValidationError):
    114114                    messages = ValidationError(messages)
    115115                self.error_dict[field] = messages.error_list
     116            self.code = code
    116117
    117118        elif isinstance(message, list):
    118119            self.error_list = []
  • tests/test_exceptions/test_validation_error.py

    diff --git a/tests/test_exceptions/test_validation_error.py b/tests/test_exceptions/test_validation_error.py
    index a0bbfaf..65cb150 100644
    a b class TestValidationError(unittest.TestCase):  
    1414        message_dict['field2'] = ['E3', 'E4']
    1515        exception = ValidationError(message_dict)
    1616        self.assertEqual(sorted(exception.messages), ['E1', 'E2', 'E3', 'E4'])
     17
     18    def test_dict_and_code(self):
     19        message_dict = {
     20            'field1': ['E1', 'E2'],
     21            'field2': ['E3', 'E4'],
     22        }
     23        exception = ValidationError(message_dict, code='foo')
     24        self.assertEqual(exception.code, 'foo')
Back to Top