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