diff --git a/moulinette/actionsmap.py b/moulinette/actionsmap.py index da2df8e0..8170e95a 100644 --- a/moulinette/actionsmap.py +++ b/moulinette/actionsmap.py @@ -564,6 +564,7 @@ class ActionsMap(object): func = getattr(mod, func_name) except (AttributeError, ImportError): import traceback + traceback.print_exc() logger.exception("unable to load function %s.%s", namespace, func_name) raise MoulinetteError("error_see_log") diff --git a/moulinette/interfaces/__init__.py b/moulinette/interfaces/__init__.py index 08b0cb98..e1650e97 100644 --- a/moulinette/interfaces/__init__.py +++ b/moulinette/interfaces/__init__.py @@ -362,6 +362,7 @@ class _CallbackAction(argparse.Action): func = getattr(mod, func_name) except (AttributeError, ImportError): import traceback + traceback.print_exc() raise ValueError("unable to import method {0}".format(self.callback_method)) self._callback = func diff --git a/moulinette/interfaces/cli.py b/moulinette/interfaces/cli.py index aa339866..1b8e0ef9 100644 --- a/moulinette/interfaces/cli.py +++ b/moulinette/interfaces/cli.py @@ -175,7 +175,7 @@ def get_locale(): except Exception: # In some edge case the locale lib fails ... # c.f. https://forum.yunohost.org/t/error-when-trying-to-enter-user-information-in-admin-panel/11390/11 - lang = os.getenv('LANG') + lang = os.getenv("LANG") if not lang: return "" return lang[:2] diff --git a/test/test_actionsmap.py b/test/test_actionsmap.py index b69b5179..bf45adda 100644 --- a/test/test_actionsmap.py +++ b/test/test_actionsmap.py @@ -253,11 +253,18 @@ def test_actions_map_import_error(mocker): mocker.patch.object(MoulinetteLock, "_is_son_of", return_value=False) - mocker.patch("__builtin__.__import__", side_effect=ImportError) + orig_import = __import__ + + def import_mock(name, globals={}, locals={}, fromlist=[], level=-1): + if name == "moulitest.testauth": + mocker.stopall() + raise ImportError + return orig_import(name, globals, locals, fromlist, level) + + mocker.patch("__builtin__.__import__", side_effect=import_mock) with pytest.raises(MoulinetteError) as exception: amap.process({}, timeout=30, route=("GET", "/test-auth/none")) - mocker.stopall() translation = m18n.g("error_see_log") expected_msg = translation.format() assert expected_msg in str(exception) diff --git a/test/test_ldap.py b/test/test_ldap.py index fadff9e6..13fff019 100644 --- a/test/test_ldap.py +++ b/test/test_ldap.py @@ -66,11 +66,14 @@ class TestLDAP: assert ldap_interface.con - def test_authenticate_server_down(self, ldap_server): + def test_authenticate_server_down(self, ldap_server, mocker): self.ldap_conf["parameters"]["uri"] = ldap_server.uri self.ldap_conf["parameters"]["user_rdn"] = "cn=admin,dc=yunohost,dc=org" ldap_server.stop() ldap_interface = m_ldap.Authenticator(**self.ldap_conf) + + # Now if slapd is down, moulinette tries to restart it + mocker.patch("os.system") with pytest.raises(MoulinetteError) as exception: ldap_interface.authenticate(password="yunohost")