diff options
| author | Preston Timmons <prestontimmons@gmail.com> | 2013-04-06 14:01:32 -0500 |
|---|---|---|
| committer | Carl Meyer <carl@oddbird.net> | 2013-04-12 15:33:22 -0600 |
| commit | e8446be5600a8f5022e82541df432268ae5f737d (patch) | |
| tree | 071a6cb15b349c07146e01d8bec7c98668fe8bc0 /tests/validation/test_validators.py | |
| parent | 612ef3e5c9ba172868d22d93be64a340b7742fc6 (diff) | |
Modified validation to work with unittest2 discovery.
Diffstat (limited to 'tests/validation/test_validators.py')
| -rw-r--r-- | tests/validation/test_validators.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/validation/test_validators.py b/tests/validation/test_validators.py new file mode 100644 index 0000000000..e58d9fd4a6 --- /dev/null +++ b/tests/validation/test_validators.py @@ -0,0 +1,19 @@ +from __future__ import absolute_import, unicode_literals + +from . import ValidationTestCase +from .models import ModelToValidate + + +class TestModelsWithValidators(ValidationTestCase): + def test_custom_validator_passes_for_correct_value(self): + mtv = ModelToValidate(number=10, name='Some Name', f_with_custom_validator=42) + self.assertEqual(None, mtv.full_clean()) + + def test_custom_validator_raises_error_for_incorrect_value(self): + mtv = ModelToValidate(number=10, name='Some Name', f_with_custom_validator=12) + self.assertFailsValidation(mtv.full_clean, ['f_with_custom_validator']) + self.assertFieldFailsValidationWithMessage( + mtv.full_clean, + 'f_with_custom_validator', + ['This is not the answer to life, universe and everything!'] + ) |
