test_momentjs.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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",
  21. "ar-sa",
  22. "ar-sasa",
  23. "de",
  24. "et",
  25. "pl",
  26. "pl-pl",
  27. "ru",
  28. "pt_BR",
  29. "zh_Hans",
  30. )
  31. for language in EXISTING_LOCALES:
  32. self.assertIsNotNone(get_locale_url(language))
  33. NONEXISTING_LOCALES = ("ga", "en", "en-us", "martian")
  34. for language in NONEXISTING_LOCALES:
  35. self.assertIsNone(get_locale_url(language))