test_momentjs.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  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. ('ar_SA', 'ar-sa'),
  10. ('de', 'de'),
  11. ('de-NO', 'de'),
  12. ('pl-pl', 'pl'),
  13. ('zz', None),
  14. ]
  15. for dirty, clean in TEST_CASES:
  16. self.assertEqual(clean_language_name(dirty), clean)
  17. def test_get_locale_path(self):
  18. """get_locale_path returns path to locale or null if it doesnt exist"""
  19. EXISTING_LOCALES = (
  20. 'af', 'ar-sa', 'ar-sasa', 'de', 'et', 'pl', 'pl-pl', 'ru', 'pt_BR', 'zh_Hans'
  21. )
  22. for language in EXISTING_LOCALES:
  23. self.assertIsNotNone(get_locale_url(language))
  24. NONEXISTING_LOCALES = ('ga', 'en', 'en-us', 'martian', )
  25. for language in NONEXISTING_LOCALES:
  26. self.assertIsNone(get_locale_url(language))