test_jsi18n.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import os
  2. from django.conf import settings
  3. from django.test import TestCase
  4. from django.urls import reverse
  5. from django.utils import translation
  6. MISAGO_DIR = os.path.dirname(
  7. os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  8. )
  9. LOCALES_DIR = os.path.join(MISAGO_DIR, "locale")
  10. class JsI18nUrlTests(TestCase):
  11. def test_url_cache_buster(self):
  12. """js i18n catalog link has cachebuster with lang code"""
  13. url = "%s?%s" % (reverse("django-i18n"), settings.LANGUAGE_CODE)
  14. response = self.client.get(reverse("misago:index"))
  15. self.assertContains(response, url)
  16. def test_js_catalogs_are_correct(self):
  17. """no JS catalogs have showstoppers"""
  18. failed_languages = []
  19. for language in os.listdir(LOCALES_DIR):
  20. if "." in language:
  21. continue
  22. try:
  23. with translation.override(language):
  24. response = self.client.get(reverse("django-i18n"))
  25. if response.status_code != 200:
  26. failed_languages.append(language)
  27. except:
  28. failed_languages.append(language)
  29. if failed_languages:
  30. self.fail(
  31. "JS catalog failed for languages: %s" % (", ".join(failed_languages))
  32. )