From 9f69f04e3f57ffb0fb13a31b055d8cf7b7244b18 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Tue, 12 May 2020 19:13:30 +0200 Subject: [PATCH 1/3] fix import mock --- test/test_actionsmap.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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) From 7fed0e5051ac9df68855394f5c34c6f1c38a1e05 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Tue, 12 May 2020 19:13:37 +0200 Subject: [PATCH 2/3] fix linter --- moulinette/actionsmap.py | 1 + moulinette/interfaces/__init__.py | 1 + moulinette/interfaces/cli.py | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) 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] From f2370c0444c55fcb853a73364829e2de83b26b68 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Tue, 12 May 2020 19:29:13 +0200 Subject: [PATCH 3/3] don't restart ldap in tests --- test/test_ldap.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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")