|
@@ -1,13 +1,33 @@
|
|
|
+import subprocess
|
|
|
+import os
|
|
|
from flask import current_app
|
|
|
+from babel.support import Translations, NullTranslations
|
|
|
from flaskbb.utils.translations import FlaskBBDomain
|
|
|
+from flaskbb.extensions import plugin_manager
|
|
|
|
|
|
|
|
|
-def test_flaskbbdomain_translations():
|
|
|
+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])
|
|
|
+
|
|
|
+
|
|
|
+def test_flaskbbdomain_translations(default_settings):
|
|
|
domain = FlaskBBDomain(current_app)
|
|
|
|
|
|
- assert domain.get_translations_cache() == {}
|
|
|
+ with current_app.test_request_context():
|
|
|
+ assert domain.get_translations_cache() == {}
|
|
|
+
|
|
|
+ # no compiled translations are available
|
|
|
+ assert isinstance(domain.get_translations(), NullTranslations)
|
|
|
|
|
|
- # returns an translation object
|
|
|
- assert domain.get_translations() is not None
|
|
|
+ # lets compile them and test again
|
|
|
+ _compile_translations()
|
|
|
|
|
|
- assert len(domain.get_translations_cache()) > 0
|
|
|
+ # now there should be translations :)
|
|
|
+ assert isinstance(domain.get_translations(), Translations)
|