mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
fix tests
This commit is contained in:
parent
a2a6e6fe7c
commit
e8309384e5
3 changed files with 13 additions and 17 deletions
|
@ -419,6 +419,7 @@ class ActionsMap(object):
|
|||
|
||||
actionsmaps = OrderedDict()
|
||||
|
||||
self.from_cache = False
|
||||
# Iterate over actions map namespaces
|
||||
for n in self.get_namespaces():
|
||||
logger.debug("loading actions map namespace '%s'", n)
|
||||
|
@ -433,17 +434,16 @@ class ActionsMap(object):
|
|||
)
|
||||
|
||||
if os.path.exists(actionsmap_pkl):
|
||||
self.from_cache = True
|
||||
try:
|
||||
# Attempt to load cache
|
||||
with open(actionsmap_pkl) as f:
|
||||
actionsmaps[n] = pickle.load(f)
|
||||
|
||||
self.from_cache = True
|
||||
# TODO: Switch to python3 and catch proper exception
|
||||
except (IOError, EOFError):
|
||||
self.from_cache = False
|
||||
actionsmaps[n] = self.generate_cache(n)
|
||||
else: # cache file doesn't exists
|
||||
self.from_cache = False
|
||||
actionsmaps[n] = self.generate_cache(n)
|
||||
|
||||
# If load_only_category is set, and *if* the target category
|
||||
|
|
|
@ -158,10 +158,10 @@ def test_required_paremeter_missing_value(iface, caplog):
|
|||
|
||||
def test_actions_map_unknown_authenticator(monkeypatch, tmp_path):
|
||||
monkeypatch.setenv("MOULINETTE_DATA_DIR", str(tmp_path))
|
||||
actionsmap_dir = actionsmap_dir = tmp_path / "actionsmap"
|
||||
actionsmap_dir = tmp_path / "actionsmap"
|
||||
actionsmap_dir.mkdir()
|
||||
|
||||
amap = ActionsMap(BaseActionsMapParser)
|
||||
amap = ActionsMap(BaseActionsMapParser())
|
||||
with pytest.raises(ValueError) as exception:
|
||||
amap.get_authenticator_for_profile("unknown")
|
||||
assert "Unknown authenticator" in str(exception)
|
||||
|
@ -233,7 +233,7 @@ def test_actions_map_api():
|
|||
assert ("GET", "/test-auth/default") in amap.parser.routes
|
||||
assert ("POST", "/test-auth/subcat/post") in amap.parser.routes
|
||||
|
||||
amap.generate_cache()
|
||||
amap.generate_cache("moulitest")
|
||||
|
||||
amap = ActionsMap(ActionsMapParser())
|
||||
|
||||
|
@ -247,7 +247,7 @@ def test_actions_map_api():
|
|||
def test_actions_map_import_error(mocker):
|
||||
from moulinette.interfaces.api import ActionsMapParser
|
||||
|
||||
amap = ActionsMap(ActionsMapParser)
|
||||
amap = ActionsMap(ActionsMapParser())
|
||||
|
||||
from moulinette.core import MoulinetteLock
|
||||
|
||||
|
@ -291,7 +291,7 @@ def test_actions_map_cli():
|
|||
.choices
|
||||
)
|
||||
|
||||
amap.generate_cache()
|
||||
amap.generate_cache("moulitest")
|
||||
|
||||
amap = ActionsMap(ActionsMapParser(top_parser=parser))
|
||||
|
||||
|
|
|
@ -216,18 +216,15 @@ class TestAuthCLI:
|
|||
|
||||
assert "some_data_from_default" in message.out
|
||||
|
||||
moulinette_cli.run(
|
||||
["testauth", "default"], output_as="plain", password="default"
|
||||
)
|
||||
moulinette_cli.run(["testauth", "default"], output_as="plain")
|
||||
message = capsys.readouterr()
|
||||
|
||||
assert "some_data_from_default" in message.out
|
||||
|
||||
def test_login_bad_password(self, moulinette_cli, capsys, mocker):
|
||||
mocker.patch("getpass.getpass", return_value="Bad Password")
|
||||
with pytest.raises(MoulinetteError):
|
||||
moulinette_cli.run(
|
||||
["testauth", "default"], output_as="plain", password="Bad Password"
|
||||
)
|
||||
moulinette_cli.run(["testauth", "default"], output_as="plain")
|
||||
|
||||
mocker.patch("getpass.getpass", return_value="Bad Password")
|
||||
with pytest.raises(MoulinetteError):
|
||||
|
@ -242,10 +239,9 @@ class TestAuthCLI:
|
|||
expected_msg = translation.format()
|
||||
assert expected_msg in str(exception)
|
||||
|
||||
mocker.patch("getpass.getpass", return_value="yoloswag")
|
||||
with pytest.raises(MoulinetteError) as exception:
|
||||
moulinette_cli.run(
|
||||
["testauth", "default"], output_as="none", password="yoloswag"
|
||||
)
|
||||
moulinette_cli.run(["testauth", "default"], output_as="none")
|
||||
|
||||
expected_msg = translation.format()
|
||||
assert expected_msg in str(exception)
|
||||
|
|
Loading…
Add table
Reference in a new issue