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.

utils_tests.py 977B

1234567891011121314151617181920212223242526272829
  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. sluggish = lambda s: s.upper()
  6. class TestSlugify(TestCase):
  7. def test_uses_custom_mappings(self):
  8. mapping = {'c++': 'cpp'}
  9. with override_settings(OSCAR_SLUG_MAP=mapping):
  10. self.assertEqual('cpp', utils.slugify('c++'))
  11. def test_uses_blacklist(self):
  12. blacklist = ['the']
  13. with override_settings(OSCAR_SLUG_BLACKLIST=blacklist):
  14. self.assertEqual('bible', utils.slugify('The Bible'))
  15. def test_handles_unicode(self):
  16. self.assertEqual('konig-der-strasse',
  17. utils.slugify(u'König der Straße'))
  18. def test_works_with_custom_slugifier(self):
  19. for fn in [sluggish, 'tests.unit.core.utils_tests.sluggish']:
  20. with override_settings(OSCAR_SLUG_FUNCTION=fn):
  21. self.assertEqual('HAM AND EGGS', utils.slugify('Ham and eggs'))