/tests/modeltests/validation/validators.py

https://code.google.com/p/mango-py/ · Python · 19 lines · 15 code · 4 blank · 0 comment · 0 complexity · 974c2e6e62eba45a9be6c3156ade2771 MD5 · raw file

  1. from django.utils.unittest import TestCase
  2. from modeltests.validation import ValidationTestCase
  3. from models import *
  4. class TestModelsWithValidators(ValidationTestCase):
  5. def test_custom_validator_passes_for_correct_value(self):
  6. mtv = ModelToValidate(number=10, name='Some Name', f_with_custom_validator=42)
  7. self.assertEqual(None, mtv.full_clean())
  8. def test_custom_validator_raises_error_for_incorrect_value(self):
  9. mtv = ModelToValidate(number=10, name='Some Name', f_with_custom_validator=12)
  10. self.assertFailsValidation(mtv.full_clean, ['f_with_custom_validator'])
  11. self.assertFieldFailsValidationWithMessage(
  12. mtv.full_clean,
  13. 'f_with_custom_validator',
  14. [u'This is not the answer to life, universe and everything!']
  15. )