2010-01-05 03:56:19 +00:00
|
|
|
from django.core.exceptions import ValidationError
|
2011-10-13 18:04:12 +00:00
|
|
|
|
2010-01-05 03:56:19 +00:00
|
|
|
|
2018-11-26 19:05:02 +00:00
|
|
|
class ValidationAssertions:
|
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])
|