PageRenderTime 101ms CodeModel.GetById 40ms app.highlight 2ms RepoModel.GetById 58ms app.codeStats 0ms

/tests/modeltests/validation/__init__.py

https://code.google.com/p/mango-py/
Python | 21 lines | 16 code | 5 blank | 0 comment | 1 complexity | bbe70b7ea4c22f442e5cd9ab7525fb93 MD5 | raw file
 1from django.test import TestCase
 2
 3from django.core.exceptions import ValidationError
 4
 5class ValidationTestCase(TestCase):
 6    def assertFailsValidation(self, clean, failed_fields):
 7        self.assertRaises(ValidationError, clean)
 8        try:
 9            clean()
10        except ValidationError, e:
11            self.assertEqual(sorted(failed_fields), sorted(e.message_dict.keys()))
12    
13    def assertFieldFailsValidationWithMessage(self, clean, field_name, message):
14        self.assertRaises(ValidationError, clean)
15        try:
16            clean()
17        except ValidationError, e:
18            self.assertTrue(field_name in e.message_dict)
19            self.assertEqual(message, e.message_dict[field_name])
20
21