diff options
| author | Joseph Kocherhans <joseph@jkocherhans.com> | 2010-01-05 03:56:19 +0000 |
|---|---|---|
| committer | Joseph Kocherhans <joseph@jkocherhans.com> | 2010-01-05 03:56:19 +0000 |
| commit | 471596fc1afcb9c6258d317c619eaf5fd394e797 (patch) | |
| tree | 193767161be3cc23dc2e6be5e4f16d8fd21a2925 /tests/modeltests/validation/validators.py | |
| parent | 4e89105d64bb9e04c409139a41e9c7aac263df4c (diff) | |
Merged soc2009/model-validation to trunk. Thanks, Honza!
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12098 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/modeltests/validation/validators.py')
| -rw-r--r-- | tests/modeltests/validation/validators.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/modeltests/validation/validators.py b/tests/modeltests/validation/validators.py new file mode 100644 index 0000000000..dc4cd4eba1 --- /dev/null +++ b/tests/modeltests/validation/validators.py @@ -0,0 +1,18 @@ +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) + self.assertEqual(None, mtv.full_validate()) + + 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_validate, ['f_with_custom_validator']) + self.assertFieldFailsValidationWithMessage( + mtv.full_validate, + 'f_with_custom_validator', + [u'This is not the answer to life, universe and everything!'] + ) |
