/tests/modeltests/validation/validators.py
Python | 19 lines | 15 code | 4 blank | 0 comment | 0 complexity | 974c2e6e62eba45a9be6c3156ade2771 MD5 | raw file
Possible License(s): BSD-3-Clause
1from django.utils.unittest import TestCase 2 3from modeltests.validation import ValidationTestCase 4from models import * 5 6 7class TestModelsWithValidators(ValidationTestCase): 8 def test_custom_validator_passes_for_correct_value(self): 9 mtv = ModelToValidate(number=10, name='Some Name', f_with_custom_validator=42) 10 self.assertEqual(None, mtv.full_clean()) 11 12 def test_custom_validator_raises_error_for_incorrect_value(self): 13 mtv = ModelToValidate(number=10, name='Some Name', f_with_custom_validator=12) 14 self.assertFailsValidation(mtv.full_clean, ['f_with_custom_validator']) 15 self.assertFieldFailsValidationWithMessage( 16 mtv.full_clean, 17 'f_with_custom_validator', 18 [u'This is not the answer to life, universe and everything!'] 19 )