Fix tests + allow to bypass m18n in YunohostError if a raw message is provided

This commit is contained in:
Alexandre Aubin 2018-12-12 19:38:05 +00:00
parent 712f742ef6
commit b93e96d33b
5 changed files with 15 additions and 11 deletions

View file

@ -840,9 +840,9 @@ def app_install(operation_logger, auth, app, label=None, args=None, no_remove_on
if install_retcode == -1:
msg = m18n.n('operation_interrupted') + " " + error_msg
raise YunohostError(msg)
raise YunohostError(msg, __raw_msg__=True)
msg = error_msg
raise YunohostError(msg)
raise YunohostError(msg, __raw_msg__=True)
# Clean hooks and add new ones
hook_remove(app_instance_name)

View file

@ -1,7 +1,7 @@
import pytest
from yunohost.utils.error import YunohostError, init_authenticator
from moulinette.core import init_authenticator
from yunohost.utils.error import YunohostError
from yunohost.app import app_install, app_remove
from yunohost.domain import _get_maindomain, domain_url_available, _normalize_domain_path

View file

@ -39,7 +39,8 @@ import apt
import apt.progress
from moulinette import msettings, msignals, m18n
from yunohost.utils.error import YunohostError, init_authenticator
from moulinette.core import init_authenticator
from yunohost.utils.error import YunohostError
from moulinette.utils.log import getActionLogger
from moulinette.utils.process import check_output
from moulinette.utils.filesystem import read_json, write_to_json

View file

@ -24,7 +24,10 @@ from moulinette import m18n
class YunohostError(MoulinetteError):
"""Yunohost base exception"""
def __init__(self, key, *args, **kwargs):
msg = m18n.n(key, *args, **kwargs)
super(YunohostError, self).__init__(msg)
def __init__(self, key, __raw_msg__=False, *args, **kwargs):
if __raw_msg__:
msg = key
else:
msg = m18n.n(key, *args, **kwargs)
super(YunohostError, self).__init__(msg, __raw_msg__=True)

View file

@ -12,14 +12,14 @@ def yunopaste(data):
try:
r = requests.post("%s/documents" % paste_server, data=data, timeout=30)
except Exception as e:
raise YunohostError("Something wrong happened while trying to paste data on paste.yunohost.org : %s" % str(e))
raise YunohostError("Something wrong happened while trying to paste data on paste.yunohost.org : %s" % str(e), __raw_msg__=True)
if r.status_code != 200:
raise YunohostError("Something wrong happened while trying to paste data on paste.yunohost.org : %s, %s" % (r.status_code, r.text))
raise YunohostError("Something wrong happened while trying to paste data on paste.yunohost.org : %s, %s" % (r.status_code, r.text), __raw_msg__=True)
try:
url = json.loads(r.text)["key"]
except:
raise YunohostError("Uhoh, couldn't parse the answer from paste.yunohost.org : %s" % r.text)
raise YunohostError("Uhoh, couldn't parse the answer from paste.yunohost.org : %s" % r.text, __raw_msg__=True)
return "%s/raw/%s" % (paste_server, url)