test_validators.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from django.core.exceptions import ValidationError
  2. from django.test import TestCase
  3. from misago.conf import settings
  4. from misago.threads.validators import validate_post, validate_title
  5. class ValidatePostTests(TestCase):
  6. def test_valid_posts(self):
  7. """valid post passes validation"""
  8. validate_post("Lorem ipsum dolor met sit amet elit.")
  9. def test_empty_post(self):
  10. """empty post is rejected"""
  11. with self.assertRaises(ValidationError):
  12. validate_post("")
  13. def test_too_short_post(self):
  14. """too short post is rejected"""
  15. with self.assertRaises(ValidationError):
  16. post = 'a' * settings.post_length_min
  17. validate_post(post[1:])
  18. def test_too_long_post(self):
  19. """too long post is rejected"""
  20. with self.assertRaises(ValidationError):
  21. post = 'a' * settings.post_length_max
  22. validate_post(post * 2)
  23. class ValidateTitleTests(TestCase):
  24. def test_valid_titles(self):
  25. """validate_title is ok with valid titles"""
  26. VALID_TITLES = ('Lorem ipsum dolor met', '123 456 789 112' 'Ugabugagagagagaga', )
  27. for title in VALID_TITLES:
  28. validate_title(title)
  29. def test_empty_title(self):
  30. """empty title is rejected"""
  31. with self.assertRaises(ValidationError):
  32. validate_title("")
  33. def test_too_short_title(self):
  34. """too short title is rejected"""
  35. with self.assertRaises(ValidationError):
  36. title = 'a' * settings.thread_title_length_min
  37. validate_title(title[1:])
  38. def test_too_long_title(self):
  39. """too long title is rejected"""
  40. with self.assertRaises(ValidationError):
  41. title = 'a' * settings.thread_title_length_max
  42. validate_title(title * 2)
  43. def test_unsluggable_title(self):
  44. """unsluggable title is rejected"""
  45. with self.assertRaises(ValidationError):
  46. title = '--' * settings.thread_title_length_min
  47. validate_title(title)