mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
test with args/extra/type
This commit is contained in:
parent
c603a4e41b
commit
b6cb1b5e7e
3 changed files with 114 additions and 0 deletions
|
@ -75,6 +75,29 @@ testauth:
|
|||
- all
|
||||
authenticator: ldap
|
||||
|
||||
with_arg:
|
||||
api: GET /test-auth/with_arg/<super_arg>
|
||||
arguments:
|
||||
super_arg:
|
||||
help: Super Arg
|
||||
|
||||
with_extra_str_only:
|
||||
api: GET /test-auth/with_extra_str_only/<only_a_str>
|
||||
arguments:
|
||||
only_a_str:
|
||||
help: Only a String
|
||||
extra:
|
||||
pattern:
|
||||
- !!str ^[a-zA-Z]
|
||||
- "pattern_only_a_str"
|
||||
|
||||
with_type_int:
|
||||
api: GET /test-auth/with_type_int/<only_an_int>
|
||||
arguments:
|
||||
only_an_int:
|
||||
help: Only an Int
|
||||
type: int
|
||||
|
||||
subcategories:
|
||||
subcat:
|
||||
actions:
|
||||
|
|
|
@ -38,5 +38,17 @@ def testauth_ldap():
|
|||
return "some_data_from_ldap"
|
||||
|
||||
|
||||
def testauth_with_arg(super_arg):
|
||||
return super_arg
|
||||
|
||||
|
||||
def testauth_with_extra_str_only(only_a_str):
|
||||
return only_a_str
|
||||
|
||||
|
||||
def testauth_with_type_int(only_an_int):
|
||||
return only_an_int
|
||||
|
||||
|
||||
def yoloswag_version(*args, **kwargs):
|
||||
return "666"
|
||||
|
|
|
@ -170,6 +170,43 @@ class TestAuthAPI:
|
|||
== '"some_data_from_ldap"'
|
||||
)
|
||||
|
||||
def test_request_with_arg(self, moulinette_webapi, capsys):
|
||||
self.login(moulinette_webapi)
|
||||
|
||||
assert (
|
||||
moulinette_webapi.get("/test-auth/with_arg/yoloswag", status=200).text
|
||||
== '"yoloswag"'
|
||||
)
|
||||
|
||||
def test_request_arg_with_extra(self, moulinette_webapi, caplog, mocker):
|
||||
self.login(moulinette_webapi)
|
||||
|
||||
assert (
|
||||
moulinette_webapi.get(
|
||||
"/test-auth/with_extra_str_only/YoLoSwAg", status=200
|
||||
).text
|
||||
== '"YoLoSwAg"'
|
||||
)
|
||||
|
||||
error = "error_message"
|
||||
mocker.patch("moulinette.Moulinette18n.n", return_value=error)
|
||||
|
||||
moulinette_webapi.get("/test-auth/with_extra_str_only/12345", status=400)
|
||||
|
||||
assert any("doesn't match pattern" in message for message in caplog.messages)
|
||||
|
||||
def test_request_arg_with_type(self, moulinette_webapi, caplog, mocker):
|
||||
self.login(moulinette_webapi)
|
||||
|
||||
assert (
|
||||
moulinette_webapi.get("/test-auth/with_type_int/12345", status=200).text
|
||||
== "12345"
|
||||
)
|
||||
|
||||
error = "error_message"
|
||||
mocker.patch("moulinette.Moulinette18n.g", return_value=error)
|
||||
moulinette_webapi.get("/test-auth/with_type_int/yoloswag", status=400)
|
||||
|
||||
|
||||
class TestAuthCLI:
|
||||
def test_login(self, moulinette_cli, capsys, mocker):
|
||||
|
@ -262,3 +299,45 @@ class TestAuthCLI:
|
|||
message = capsys.readouterr()
|
||||
|
||||
assert "cannot get value from callback method" in message.err
|
||||
|
||||
def test_request_with_arg(self, moulinette_cli, capsys, mocker):
|
||||
mocker.patch("getpass.getpass", return_value="default")
|
||||
moulinette_cli.run(["testauth", "with_arg", "yoloswag"], output_as="plain")
|
||||
message = capsys.readouterr()
|
||||
|
||||
assert "yoloswag" in message.out
|
||||
|
||||
def test_request_arg_with_extra(self, moulinette_cli, capsys, mocker):
|
||||
mocker.patch("getpass.getpass", return_value="default")
|
||||
moulinette_cli.run(
|
||||
["testauth", "with_extra_str_only", "YoLoSwAg"], output_as="plain"
|
||||
)
|
||||
message = capsys.readouterr()
|
||||
|
||||
assert "YoLoSwAg" in message.out
|
||||
|
||||
error = "error_message"
|
||||
mocker.patch("moulinette.Moulinette18n.n", return_value=error)
|
||||
with pytest.raises(MoulinetteError):
|
||||
moulinette_cli.run(
|
||||
["testauth", "with_extra_str_only", "12345"], output_as="plain"
|
||||
)
|
||||
|
||||
message = capsys.readouterr()
|
||||
assert "doesn't match pattern" in message.err
|
||||
|
||||
def test_request_arg_with_type(self, moulinette_cli, capsys, mocker):
|
||||
mocker.patch("getpass.getpass", return_value="default")
|
||||
moulinette_cli.run(["testauth", "with_type_int", "12345"], output_as="plain")
|
||||
message = capsys.readouterr()
|
||||
|
||||
assert "12345" in message.out
|
||||
|
||||
mocker.patch("sys.exit")
|
||||
with pytest.raises(MoulinetteError):
|
||||
moulinette_cli.run(
|
||||
["testauth", "with_type_int", "yoloswag"], output_as="plain"
|
||||
)
|
||||
|
||||
message = capsys.readouterr()
|
||||
assert "invalid int value" in message.err
|
||||
|
|
Loading…
Reference in a new issue