From e8309384e565cb0bb6081d3621b79b5bb94c5e74 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Fri, 1 May 2020 14:00:10 +0200 Subject: [PATCH] fix tests --- moulinette/actionsmap.py | 6 +++--- test/test_actionsmap.py | 10 +++++----- test/test_auth.py | 14 +++++--------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/moulinette/actionsmap.py b/moulinette/actionsmap.py index 4329160e..2fe17d71 100644 --- a/moulinette/actionsmap.py +++ b/moulinette/actionsmap.py @@ -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 diff --git a/test/test_actionsmap.py b/test/test_actionsmap.py index de2942fe..69af0472 100644 --- a/test/test_actionsmap.py +++ b/test/test_actionsmap.py @@ -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)) diff --git a/test/test_auth.py b/test/test_auth.py index dd95d9c7..a7a79c90 100644 --- a/test/test_auth.py +++ b/test/test_auth.py @@ -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)