Merge pull request #248 from YunoHost/tests-fix

Tests fix
This commit is contained in:
Kayou 2020-05-19 23:42:10 +02:00 committed by GitHub
commit 7da5b19320
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 4 deletions

View file

@ -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")

View file

@ -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

View file

@ -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]

View file

@ -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)

View file

@ -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")