diff --git a/moulinette/core.py b/moulinette/core.py index 6fe434b9..d2312afd 100644 --- a/moulinette/core.py +++ b/moulinette/core.py @@ -180,7 +180,6 @@ class Moulinette18n(object): moulinette_env = init_moulinette_env() self.locales_dir = moulinette_env['LOCALES_DIR'] - self.lib_dir = moulinette_env['LIB_DIR'] # Init global translator self._global = Translator(self.locales_dir, default_locale) @@ -201,7 +200,8 @@ class Moulinette18n(object): """ if namespace not in self._namespaces: # Create new Translator object - translator = Translator('%s/%s/locales' % (self.lib_dir, namespace), + lib_dir = init_moulinette_env()["LIB_DIR"] + translator = Translator('%s/%s/locales' % (lib_dir, namespace), self.default_locale) translator.set_locale(self.locale) self._namespaces[namespace] = translator @@ -371,8 +371,8 @@ def init_interface(name, kwargs={}, actionsmap={}): try: mod = import_module('moulinette.interfaces.%s' % name) - except ImportError: - logger.exception("unable to load interface '%s'", name) + except ImportError as e: + logger.exception("unable to load interface '%s' : %s", name, e) raise MoulinetteError('error_see_log') else: try: diff --git a/test/conftest.py b/test/conftest.py index b5669aac..d7f7700c 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,8 +1,10 @@ """Pytest fixtures for testing.""" +from multiprocessing import Process +import time import json import os - +import shutil import pytest @@ -42,7 +44,7 @@ def patch_logging(moulinette): root_handlers = set(handlers) level = 'INFO' - tty_level = 'SUCCESS' + tty_level = 'INFO' logging = { 'version': 1, @@ -61,6 +63,10 @@ def patch_logging(moulinette): }, }, 'handlers': { + 'api': { + 'level': level, + 'class': 'moulinette.interfaces.api.APIQueueHandler', + }, 'tty': { 'level': tty_level, 'class': 'moulinette.interfaces.cli.TTYHandler', @@ -102,6 +108,26 @@ def moulinette(): return moulinette +@pytest.fixture(scope='session') +def moulinette_webapi(moulinette, tmp_path_factory): + namespace = "test" + tmp_data = str(tmp_path_factory.mktemp("data")) + tmp_locales = str(tmp_path_factory.mktemp("data")) + os.environ['MOULINETTE_DATA_DIR'] = tmp_data + os.environ['MOULINETTE_LIB_DIR'] = tmp_locales + shutil.copytree("./data/actionsmap", "%s/actionsmap" % tmp_data) + shutil.copytree("./locales", "%s/%s/locales" % (tmp_locales, namespace)) + + api_thread = Process(target=moulinette.api, + args=([namespace],), + kwargs={"host": "localhost", "port": 12342, "use_websocket": False}) + api_thread.start() + time.sleep(0.5) + assert api_thread.is_alive() + yield "http://localhost:12342" + api_thread.terminate() + + @pytest.fixture def test_file(tmp_path): test_text = 'foo\nbar\n' diff --git a/tox.ini b/tox.ini index 895a8f06..6b645c2b 100644 --- a/tox.ini +++ b/tox.ini @@ -15,6 +15,9 @@ deps = pytest-env >= 0.6.2, < 1.0 requests >= 2.22.0, < 3.0 requests-mock >= 1.6.0, < 2.0 + toml >= 0.10 + gevent-websocket + bottle >= 0.12 commands = pytest {posargs}