1
0
mirror of https://github.com/django/django.git synced 2024-12-25 18:46:22 +00:00
django/tests/modeltests/validation/__init__.py
2011-10-13 18:04:12 +00:00

19 lines
670 B
Python

from __future__ import with_statement
from django.core.exceptions import ValidationError
from django.test import TestCase
class ValidationTestCase(TestCase):
def assertFailsValidation(self, clean, failed_fields):
with self.assertRaises(ValidationError) as cm:
clean()
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])