mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Be able to run test on the API
This commit is contained in:
parent
6899217fa0
commit
6d44c46740
3 changed files with 35 additions and 6 deletions
|
@ -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:
|
||||
|
|
|
@ -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'
|
||||
|
|
3
tox.ini
3
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}
|
||||
|
||||
|
|
Loading…
Reference in a new issue