test_validators.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from django.core.exceptions import ValidationError
  2. from django.test import TestCase
  3. from misago.core.validators import validate_sluggable
  4. class ValidateSluggableTests(TestCase):
  5. serialized_rollback = True
  6. def test_error_messages_set(self):
  7. """custom error messages are set and used"""
  8. error_short = "I'm short custom error!"
  9. error_long = "I'm long custom error!"
  10. validator = validate_sluggable(error_short, error_long)
  11. self.assertEqual(validator.error_short, error_short)
  12. self.assertEqual(validator.error_long, error_long)
  13. def test_faulty_input_validation(self):
  14. """invalid values raise errors"""
  15. validator = validate_sluggable()
  16. with self.assertRaises(ValidationError):
  17. validator('!#@! !@#@')
  18. with self.assertRaises(ValidationError):
  19. validator('!#@! !@#@ 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. def test_valid_input_validation(self):
  25. """valid values don't raise errors"""
  26. validator = validate_sluggable()
  27. validator('Bob')
  28. validator('Lorem ipsum123!')