2010-01-05 11:56:19 +08:00
|
|
|
from unittest import TestCase
|
|
|
|
from modeltests.validation import ValidationTestCase
|
|
|
|
from models import *
|
|
|
|
|
|
|
|
|
|
|
|
class TestModelsWithValidators(ValidationTestCase):
|
|
|
|
def test_custom_validator_passes_for_correct_value(self):
|
|
|
|
mtv = ModelToValidate(number=10, name='Some Name', f_with_custom_validator=42)
|
2010-01-12 10:29:45 +08:00
|
|
|
self.assertEqual(None, mtv.full_clean())
|
2010-01-05 11:56:19 +08:00
|
|
|
|
|
|
|
def test_custom_validator_raises_error_for_incorrect_value(self):
|
|
|
|
mtv = ModelToValidate(number=10, name='Some Name', f_with_custom_validator=12)
|
2010-01-12 10:29:45 +08:00
|
|
|
self.assertFailsValidation(mtv.full_clean, ['f_with_custom_validator'])
|
2010-01-05 11:56:19 +08:00
|
|
|
self.assertFieldFailsValidationWithMessage(
|
2010-01-12 10:29:45 +08:00
|
|
|
mtv.full_clean,
|
2010-01-05 11:56:19 +08:00
|
|
|
'f_with_custom_validator',
|
|
|
|
[u'This is not the answer to life, universe and everything!']
|
|
|
|
)
|