You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_utils.py 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # coding=utf-8
  2. from django.test import TestCase
  3. from django.test.utils import override_settings
  4. from oscar.core import utils
  5. # pylint: disable=unused-argument
  6. def sluggish(value, allow_unicode=False):
  7. return value.upper()
  8. class TestSlugify(TestCase):
  9. def test_default_unicode_to_ascii(self):
  10. self.assertEqual("konig-der-straxdfe", utils.slugify("König der Straße"))
  11. self.assertEqual("not-fancy", utils.slugify("Not fancy"))
  12. self.assertEqual("u4e01u4e02-u4e03u4e04u4e05", utils.slugify("丁丂 七丄丅"))
  13. @override_settings(OSCAR_SLUG_ALLOW_UNICODE=True)
  14. def test_allow_unicode(self):
  15. self.assertEqual("könig-der-straße", utils.slugify("König der Straße"))
  16. self.assertEqual("丁丂-七丄丅", utils.slugify("丁丂 七丄丅"))
  17. self.assertEqual("not-fancy", utils.slugify("Not fancy"))
  18. @override_settings(OSCAR_SLUG_FUNCTION="tests.integration.core.test_utils.sluggish")
  19. def test_custom_slugifier(self):
  20. self.assertEqual("HAM AND EGGS", utils.slugify("Ham and eggs"))
  21. @override_settings(OSCAR_SLUG_MAP={"c++": "cpp"})
  22. def test_uses_custom_mappings(self):
  23. self.assertEqual("cpp", utils.slugify("c++"))
  24. @override_settings(OSCAR_SLUG_BLACKLIST=["the"])
  25. def test_uses_blacklist(self):
  26. self.assertEqual("bible", utils.slugify("The Bible"))
  27. @override_settings(OSCAR_SLUG_BLACKLIST=["the", "bible"])
  28. def test_uses_blacklist_doesnt_reduce_to_nothing(self):
  29. self.assertEqual("bible", utils.slugify("The Bible"))