2010-01-05 11:56:19 +08:00
|
|
|
from django.core.exceptions import ValidationError
|
2011-10-14 02:04:12 +08:00
|
|
|
|
2010-01-05 11:56:19 +08:00
|
|
|
|
2018-11-27 03:05:02 +08:00
|
|
|
class ValidationAssertions:
|
2014-05-01 17:55:52 +08:00
|
|
|
def assertFailsValidation(self, clean, failed_fields, **kwargs):
|
2011-10-14 02:04:12 +08:00
|
|
|
with self.assertRaises(ValidationError) as cm:
|
2014-05-01 17:55:52 +08:00
|
|
|
clean(**kwargs)
|
2011-10-14 02:04:12 +08:00
|
|
|
self.assertEqual(sorted(failed_fields), sorted(cm.exception.message_dict))
|
|
|
|
|
2010-01-05 11:56:19 +08:00
|
|
|
def assertFieldFailsValidationWithMessage(self, clean, field_name, message):
|
2011-10-14 02:04:12 +08:00
|
|
|
with self.assertRaises(ValidationError) as cm:
|
2010-01-05 11:56:19 +08:00
|
|
|
clean()
|
2011-10-14 02:04:12 +08:00
|
|
|
self.assertIn(field_name, cm.exception.message_dict)
|
|
|
|
self.assertEqual(message, cm.exception.message_dict[field_name])
|