test_utils.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #-*- coding: utf-8 -*-
  2. from django.core.urlresolvers import reverse
  3. from django.test import TestCase
  4. from django.test.client import RequestFactory
  5. from misago.core.utils import is_request_to_misago, slugify
  6. VALID_PATHS = (
  7. "/",
  8. "/threads/",
  9. )
  10. INVALID_PATHS = (
  11. "",
  12. "somewhere/",
  13. )
  14. class IsRequestToMisagoTests(TestCase):
  15. def test_is_request_to_misago(self):
  16. """
  17. is_request_to_misago correctly detects requests directed at Misago
  18. """
  19. misago_prefix = reverse('misago:index')
  20. for path in VALID_PATHS:
  21. request = RequestFactory().get('/')
  22. request.path_info = path
  23. self.assertTrue(
  24. is_request_to_misago(request),
  25. '"%s" is not overlapped by "%s"' % (path, misago_prefix))
  26. for path in INVALID_PATHS:
  27. request = RequestFactory().get('/')
  28. request.path_info = path
  29. self.assertFalse(
  30. is_request_to_misago(request),
  31. '"%s" is overlapped by "%s"' % (path, misago_prefix))
  32. class SlugifyTests(TestCase):
  33. def test_valid_slugify_output(self):
  34. """Misago's slugify correcly slugifies string"""
  35. test_cases = (
  36. (u'Bob', u'bob'),
  37. (u'Eric The Fish', u'eric-the-fish'),
  38. (u'John Snow', u'john-snow'),
  39. (u'J0n', u'j0n'),
  40. (u'An###ne', u'anne'),
  41. (u'S**t', u'st'),
  42. )
  43. for original, slug in test_cases:
  44. self.assertEqual(slugify(original), slug)