1
0
mirror of https://github.com/django/django.git synced 2024-12-29 04:26:28 +00:00
django/tests/validation/__init__.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

15 lines
607 B
Python
Raw Normal View History

from django.core.exceptions import ValidationError
class ValidationAssertions:
def assertFailsValidation(self, clean, failed_fields, **kwargs):
with self.assertRaises(ValidationError) as cm:
clean(**kwargs)
self.assertEqual(sorted(failed_fields), sorted(cm.exception.message_dict))
def assertFieldFailsValidationWithMessage(self, clean, field_name, message):
with self.assertRaises(ValidationError) as cm:
clean()
self.assertIn(field_name, cm.exception.message_dict)
self.assertEqual(message, cm.exception.message_dict[field_name])