2010-01-05 03:56:19 +00:00
|
|
|
from django.core.exceptions import ValidationError
|
2011-10-13 18:04:12 +00:00
|
|
|
from django.test import TestCase
|
|
|
|
|
2010-01-05 03:56:19 +00:00
|
|
|
|
2011-09-10 00:47:00 +00:00
|
|
|
class ValidationTestCase(TestCase):
|
2014-05-01 09:55:52 +00:00
|
|
|
def assertFailsValidation(self, clean, failed_fields, **kwargs):
|
2011-10-13 18:04:12 +00:00
|
|
|
with self.assertRaises(ValidationError) as cm:
|
2014-05-01 09:55:52 +00:00
|
|
|
clean(**kwargs)
|
2011-10-13 18:04:12 +00:00
|
|
|
self.assertEqual(sorted(failed_fields), sorted(cm.exception.message_dict))
|
|
|
|
|
2010-01-05 03:56:19 +00:00
|
|
|
def assertFieldFailsValidationWithMessage(self, clean, field_name, message):
|
2011-10-13 18:04:12 +00:00
|
|
|
with self.assertRaises(ValidationError) as cm:
|
2010-01-05 03:56:19 +00:00
|
|
|
clean()
|
2011-10-13 18:04:12 +00:00
|
|
|
self.assertIn(field_name, cm.exception.message_dict)
|
|
|
|
self.assertEqual(message, cm.exception.message_dict[field_name])
|