test request with callback

This commit is contained in:
Kay0u 2020-01-08 23:05:34 +07:00
parent 88cdeb0b96
commit c603a4e41b
No known key found for this signature in database
GPG key ID: 7FF262C033518333
3 changed files with 30 additions and 1 deletions

View file

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

View file

@ -36,3 +36,7 @@ def testauth_only_cli():
def testauth_ldap():
return "some_data_from_ldap"
def yoloswag_version(*args, **kwargs):
return "666"

View file

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