test_validators.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from django.core.exceptions import ValidationError
  2. from django.test import TestCase
  3. from ..validators import validate_sluggable
  4. class ValidateSluggableTests(TestCase):
  5. def test_error_messages_set(self):
  6. """custom error messages are set and used"""
  7. error_short = "I'm short custom error!"
  8. error_long = "I'm long custom error!"
  9. validator = validate_sluggable(error_short, error_long)
  10. self.assertEqual(validator.error_short, error_short)
  11. self.assertEqual(validator.error_long, error_long)
  12. def test_faulty_input_validation(self):
  13. """invalid values raise errors"""
  14. validator = validate_sluggable()
  15. with self.assertRaises(ValidationError):
  16. validator("!#@! !@#@")
  17. with self.assertRaises(ValidationError):
  18. validator(
  19. "!#@! !@#@ 1234567890 1234567890 1234567890 1234567890"
  20. "1234567890 1234567890 1234567890 1234567890 1234567890"
  21. "1234567890 1234567890 1234567890 1234567890 1234567890"
  22. "1234567890 1234567890 1234567890 1234567890 1234567890"
  23. "1234567890 1234567890 1234567890 1234567890 1234567890"
  24. )
  25. def test_valid_input_validation(self):
  26. """valid values don't raise errors"""
  27. validator = validate_sluggable()
  28. validator("User")
  29. validator("Lorem ipsum123!")