From c603a4e41b143859126b3e19a537372e110d3f60 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Wed, 8 Jan 2020 23:05:34 +0700 Subject: [PATCH] test request with callback --- test/actionsmap/moulitest.yml | 9 ++++++++- test/src/testauth.py | 4 ++++ test/test_auth.py | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/test/actionsmap/moulitest.yml b/test/actionsmap/moulitest.yml index 5a99135f..76d61c20 100644 --- a/test/actionsmap/moulitest.yml +++ b/test/actionsmap/moulitest.yml @@ -26,7 +26,14 @@ _global: help: Display Yoloswag versions action: callback callback: - method: yoloswag_version + method: test.src.testauth.yoloswag_version + return: true + -w: + full: --wersion + help: Not existing function + action: callback + callback: + method: test.src.testauth.not_existing_function return: true ############################# diff --git a/test/src/testauth.py b/test/src/testauth.py index 572e13de..87dcf5a0 100644 --- a/test/src/testauth.py +++ b/test/src/testauth.py @@ -36,3 +36,7 @@ def testauth_only_cli(): def testauth_ldap(): return "some_data_from_ldap" + + +def yoloswag_version(*args, **kwargs): + return "666" diff --git a/test/test_auth.py b/test/test_auth.py index 84a66462..a2c8dce5 100644 --- a/test/test_auth.py +++ b/test/test_auth.py @@ -244,3 +244,21 @@ class TestAuthCLI: translation = m18n.g("invalid_password") expected_msg = translation.format() assert expected_msg in str(exception) + + def test_request_with_callback(self, moulinette_cli, capsys, mocker): + mocker.patch("getpass.getpass", return_value="default") + moulinette_cli.run(["--version"], output_as="plain") + message = capsys.readouterr() + + assert "666" in message.out + + moulinette_cli.run(["-v"], output_as="plain") + message = capsys.readouterr() + + assert "666" in message.out + + with pytest.raises(MoulinetteError): + moulinette_cli.run(["--wersion"], output_as="plain") + message = capsys.readouterr() + + assert "cannot get value from callback method" in message.err