fix tests

This commit is contained in:
Kay0u 2020-05-01 14:00:10 +02:00
parent a2a6e6fe7c
commit e8309384e5
No known key found for this signature in database
GPG key ID: AE1DCADB6415A156
3 changed files with 13 additions and 17 deletions

View file

@ -419,6 +419,7 @@ class ActionsMap(object):
actionsmaps = OrderedDict() actionsmaps = OrderedDict()
self.from_cache = False
# Iterate over actions map namespaces # Iterate over actions map namespaces
for n in self.get_namespaces(): for n in self.get_namespaces():
logger.debug("loading actions map namespace '%s'", n) logger.debug("loading actions map namespace '%s'", n)
@ -433,17 +434,16 @@ class ActionsMap(object):
) )
if os.path.exists(actionsmap_pkl): if os.path.exists(actionsmap_pkl):
self.from_cache = True
try: try:
# Attempt to load cache # Attempt to load cache
with open(actionsmap_pkl) as f: with open(actionsmap_pkl) as f:
actionsmaps[n] = pickle.load(f) actionsmaps[n] = pickle.load(f)
self.from_cache = True
# TODO: Switch to python3 and catch proper exception # TODO: Switch to python3 and catch proper exception
except (IOError, EOFError): except (IOError, EOFError):
self.from_cache = False
actionsmaps[n] = self.generate_cache(n) actionsmaps[n] = self.generate_cache(n)
else: # cache file doesn't exists else: # cache file doesn't exists
self.from_cache = False
actionsmaps[n] = self.generate_cache(n) actionsmaps[n] = self.generate_cache(n)
# If load_only_category is set, and *if* the target category # If load_only_category is set, and *if* the target category

View file

@ -158,10 +158,10 @@ def test_required_paremeter_missing_value(iface, caplog):
def test_actions_map_unknown_authenticator(monkeypatch, tmp_path): def test_actions_map_unknown_authenticator(monkeypatch, tmp_path):
monkeypatch.setenv("MOULINETTE_DATA_DIR", str(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() actionsmap_dir.mkdir()
amap = ActionsMap(BaseActionsMapParser) amap = ActionsMap(BaseActionsMapParser())
with pytest.raises(ValueError) as exception: with pytest.raises(ValueError) as exception:
amap.get_authenticator_for_profile("unknown") amap.get_authenticator_for_profile("unknown")
assert "Unknown authenticator" in str(exception) 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 ("GET", "/test-auth/default") in amap.parser.routes
assert ("POST", "/test-auth/subcat/post") in amap.parser.routes assert ("POST", "/test-auth/subcat/post") in amap.parser.routes
amap.generate_cache() amap.generate_cache("moulitest")
amap = ActionsMap(ActionsMapParser()) amap = ActionsMap(ActionsMapParser())
@ -247,7 +247,7 @@ def test_actions_map_api():
def test_actions_map_import_error(mocker): def test_actions_map_import_error(mocker):
from moulinette.interfaces.api import ActionsMapParser from moulinette.interfaces.api import ActionsMapParser
amap = ActionsMap(ActionsMapParser) amap = ActionsMap(ActionsMapParser())
from moulinette.core import MoulinetteLock from moulinette.core import MoulinetteLock
@ -291,7 +291,7 @@ def test_actions_map_cli():
.choices .choices
) )
amap.generate_cache() amap.generate_cache("moulitest")
amap = ActionsMap(ActionsMapParser(top_parser=parser)) amap = ActionsMap(ActionsMapParser(top_parser=parser))

View file

@ -216,18 +216,15 @@ class TestAuthCLI:
assert "some_data_from_default" in message.out assert "some_data_from_default" in message.out
moulinette_cli.run( moulinette_cli.run(["testauth", "default"], output_as="plain")
["testauth", "default"], output_as="plain", password="default"
)
message = capsys.readouterr() message = capsys.readouterr()
assert "some_data_from_default" in message.out assert "some_data_from_default" in message.out
def test_login_bad_password(self, moulinette_cli, capsys, mocker): def test_login_bad_password(self, moulinette_cli, capsys, mocker):
mocker.patch("getpass.getpass", return_value="Bad Password")
with pytest.raises(MoulinetteError): with pytest.raises(MoulinetteError):
moulinette_cli.run( moulinette_cli.run(["testauth", "default"], output_as="plain")
["testauth", "default"], output_as="plain", password="Bad Password"
)
mocker.patch("getpass.getpass", return_value="Bad Password") mocker.patch("getpass.getpass", return_value="Bad Password")
with pytest.raises(MoulinetteError): with pytest.raises(MoulinetteError):
@ -242,10 +239,9 @@ class TestAuthCLI:
expected_msg = translation.format() expected_msg = translation.format()
assert expected_msg in str(exception) assert expected_msg in str(exception)
mocker.patch("getpass.getpass", return_value="yoloswag")
with pytest.raises(MoulinetteError) as exception: with pytest.raises(MoulinetteError) as exception:
moulinette_cli.run( moulinette_cli.run(["testauth", "default"], output_as="none")
["testauth", "default"], output_as="none", password="yoloswag"
)
expected_msg = translation.format() expected_msg = translation.format()
assert expected_msg in str(exception) assert expected_msg in str(exception)