Browse Source

Fix translation tests

Peter Justin 7 years ago
parent
commit
d4b403df68
2 changed files with 6 additions and 40 deletions
  1. 1 0
      flaskbb/utils/translations.py
  2. 5 40
      tests/unit/utils/test_translations.py

+ 1 - 0
flaskbb/utils/translations.py

@@ -41,6 +41,7 @@ class FlaskBBDomain(Domain):
         locale = get_locale()
         # now load and add the plugin translations
         for plugin in self.plugin_translations:
+            logger.debug("Loading plugin translation from: {}".format(plugin))
             plugin_translation = babel.support.Translations.load(
                 dirname=plugin,
                 locales=locale,

+ 5 - 40
tests/unit/utils/test_translations.py

@@ -1,49 +1,14 @@
-import subprocess
-import os
 from flask import current_app
-from babel.support import Translations, NullTranslations
+from babel.support import Translations
 from flaskbb.utils.translations import FlaskBBDomain
-import pytest
 
 
-def _remove_compiled_translations():
-    translations_folder = os.path.join(current_app.root_path, "translations")
-
-    # walks through the translations folder and deletes all files
-    # ending with .mo
-    for root, dirs, files in os.walk(translations_folder):
-        for name in files:
-            if name.endswith(".mo"):
-                os.unlink(os.path.join(root, name))
-
-
-def _compile_translations():
-    PLUGINS_FOLDER = os.path.join(current_app.root_path, "plugins")
-    translations_folder = os.path.join(current_app.root_path, "translations")
-
-    subprocess.call(["pybabel", "compile", "-d", translations_folder])
-
-    for plugin in plugin_manager.all_plugins:
-        plugin_folder = os.path.join(PLUGINS_FOLDER, plugin)
-        translations_folder = os.path.join(plugin_folder, "translations")
-        subprocess.call(["pybabel", "compile", "-d", translations_folder])
-
-
-@pytest.mark.skip(reason="Plugin transition")
 def test_flaskbbdomain_translations(default_settings):
-    domain = FlaskBBDomain(current_app)
+    domain = current_app.extensions.get("babel").domain
 
     with current_app.test_request_context():
+        # no translations accessed and thus the cache is empty
         assert domain.get_translations_cache() == {}
-
-        # just to be on the safe side that there are really no compiled
-        # translations available
-        _remove_compiled_translations()
-        # no compiled translations are available
-        assert isinstance(domain.get_translations(), NullTranslations)
-
-        # lets compile them and test again
-        _compile_translations()
-
-        # now there should be translations :)
+        # load translations into cache
         assert isinstance(domain.get_translations(), Translations)
+        assert len(domain.get_translations_cache()) == 1  # 'en'