parts/django/tests/modeltests/validation/validators.py
changeset 307 c6bca38c1cbf
equal deleted inserted replaced
306:5ff1fc726848 307:c6bca38c1cbf
       
     1 from unittest import TestCase
       
     2 from modeltests.validation import ValidationTestCase
       
     3 from models import *
       
     4 
       
     5 
       
     6 class TestModelsWithValidators(ValidationTestCase):
       
     7     def test_custom_validator_passes_for_correct_value(self):
       
     8         mtv = ModelToValidate(number=10, name='Some Name', f_with_custom_validator=42)
       
     9         self.assertEqual(None, mtv.full_clean())
       
    10 
       
    11     def test_custom_validator_raises_error_for_incorrect_value(self):
       
    12         mtv = ModelToValidate(number=10, name='Some Name', f_with_custom_validator=12)
       
    13         self.assertFailsValidation(mtv.full_clean, ['f_with_custom_validator'])
       
    14         self.assertFieldFailsValidationWithMessage(
       
    15             mtv.full_clean,
       
    16             'f_with_custom_validator',
       
    17             [u'This is not the answer to life, universe and everything!']
       
    18         )