From ec9b020376b974653647e9e7edfab09a9d9733a9 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Sat, 16 May 2020 01:42:41 +0200 Subject: [PATCH] [mod] moar test for arguments parsing --- .../tests/test_apps_arguments_parsing.py | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/src/yunohost/tests/test_apps_arguments_parsing.py b/src/yunohost/tests/test_apps_arguments_parsing.py index 8fe3d7728..c92007873 100644 --- a/src/yunohost/tests/test_apps_arguments_parsing.py +++ b/src/yunohost/tests/test_apps_arguments_parsing.py @@ -98,6 +98,32 @@ def test_parse_args_in_yunohost_format_string_no_input_optional(): assert _parse_args_in_yunohost_format(answers, questions) == expected_result +def test_parse_args_in_yunohost_format_string_optional_with_input(): + questions = [{ + "name": "some_string", + "ask": "some question", + "optional": True, + }] + answers = {} + expected_result = OrderedDict({"some_string": ("some_value", "string")}) + + with patch.object(msignals, "prompt", return_value="some_value"): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +@pytest.mark.skip # this should work without ask +def test_parse_args_in_yunohost_format_string_optional_with_input_without_ask(): + questions = [{ + "name": "some_string", + "optional": True, + }] + answers = {} + expected_result = OrderedDict({"some_string": ("some_value", "string")}) + + with patch.object(msignals, "prompt", return_value="some_value"): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + def test_parse_args_in_yunohost_format_string_no_input_default(): questions = [{ "name": "some_string", @@ -107,3 +133,65 @@ def test_parse_args_in_yunohost_format_string_no_input_default(): answers = {} expected_result = OrderedDict({"some_string": ("some_value", "string")}) assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +def test_parse_args_in_yunohost_format_string_input_test_ask(): + ask_text = "some question" + questions = [{ + "name": "some_string", + "ask": ask_text, + }] + answers = {} + + with patch.object(msignals, "prompt", return_value="some_value") as prompt: + _parse_args_in_yunohost_format(answers, questions) + prompt.assert_called_with(ask_text, False) + + +def test_parse_args_in_yunohost_format_string_input_test_ask_with_default(): + ask_text = "some question" + default_text = "some example" + questions = [{ + "name": "some_string", + "ask": ask_text, + "default": default_text, + }] + answers = {} + + with patch.object(msignals, "prompt", return_value="some_value") as prompt: + _parse_args_in_yunohost_format(answers, questions) + prompt.assert_called_with("%s (default: %s)" % (ask_text, default_text), False) + + +@pytest.mark.skip # we should do something with this example +def test_parse_args_in_yunohost_format_string_input_test_ask_with_example(): + ask_text = "some question" + example_text = "some example" + questions = [{ + "name": "some_string", + "ask": ask_text, + "example": example_text, + }] + answers = {} + + with patch.object(msignals, "prompt", return_value="some_value") as prompt: + _parse_args_in_yunohost_format(answers, questions) + assert ask_text in prompt.call_args[0] + assert example_text in prompt.call_args[0] + + +@pytest.mark.skip # we should do something with this help +def test_parse_args_in_yunohost_format_string_input_test_ask_with_help(): + ask_text = "some question" + help_text = "some_help" + questions = [{ + "name": "some_string", + "ask": ask_text, + "help": help_text, + }] + answers = {} + + with patch.object(msignals, "prompt", return_value="some_value") as prompt: + _parse_args_in_yunohost_format(answers, questions) + assert ask_text in prompt.call_args[0] + assert help_text in prompt.call_args[0]