From b93e96d33bb999fd0e96ef6e6c1293d0ddc85d49 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Wed, 12 Dec 2018 19:38:05 +0000 Subject: [PATCH] Fix tests + allow to bypass m18n in YunohostError if a raw message is provided --- src/yunohost/app.py | 4 ++-- src/yunohost/tests/test_appurl.py | 4 ++-- src/yunohost/tools.py | 3 ++- src/yunohost/utils/error.py | 9 ++++++--- src/yunohost/utils/yunopaste.py | 6 +++--- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 510b60e95..3177407c1 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -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) diff --git a/src/yunohost/tests/test_appurl.py b/src/yunohost/tests/test_appurl.py index 58c345dea..85f290b5d 100644 --- a/src/yunohost/tests/test_appurl.py +++ b/src/yunohost/tests/test_appurl.py @@ -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 diff --git a/src/yunohost/tools.py b/src/yunohost/tools.py index 6102b9f7a..58bdd23d3 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -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 diff --git a/src/yunohost/utils/error.py b/src/yunohost/utils/error.py index 8a73e52b7..7c00ee5a4 100644 --- a/src/yunohost/utils/error.py +++ b/src/yunohost/utils/error.py @@ -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) diff --git a/src/yunohost/utils/yunopaste.py b/src/yunohost/utils/yunopaste.py index e349ebc32..436f94911 100644 --- a/src/yunohost/utils/yunopaste.py +++ b/src/yunohost/utils/yunopaste.py @@ -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)