test_momentjs.py 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. from django.test import TestCase
  2. from misago.core.momentjs import clean_language_name, get_locale_url
  3. class MomentJSTests(TestCase):
  4. def test_clean_language_name(self):
  5. """clean_language_name returns valid name"""
  6. TEST_CASES = [
  7. ('AF', 'af'),
  8. ('ar-SA', 'ar-sa'),
  9. ('de', 'de'),
  10. ('de-NO', 'de'),
  11. ('pl-pl', 'pl'),
  12. ('zz', None),
  13. ]
  14. for dirty, clean in TEST_CASES:
  15. self.assertEqual(clean_language_name(dirty), clean)
  16. def test_get_locale_path(self):
  17. """get_locale_path returns path to locale or null if it doesnt exist"""
  18. EXISTING_LOCALES = (
  19. 'af', 'ar-sa', 'ar-sasa', 'de', 'et', 'pl', 'pl-pl', 'ru', 'pt-br', 'zh-tw'
  20. )
  21. for language in EXISTING_LOCALES:
  22. self.assertIsNotNone(get_locale_url(language))
  23. NONEXISTING_LOCALES = ('ga', 'en', 'en-us', 'martian', )
  24. for language in NONEXISTING_LOCALES:
  25. self.assertIsNone(get_locale_url(language))