From d1d38b173cc404eccf165ffa2e8c82dfb815178e Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Sat, 16 May 2020 03:25:51 +0200 Subject: [PATCH] [mod] add tests for path --- .../tests/test_apps_arguments_parsing.py | 174 +++++++++++++++++- 1 file changed, 164 insertions(+), 10 deletions(-) diff --git a/src/yunohost/tests/test_apps_arguments_parsing.py b/src/yunohost/tests/test_apps_arguments_parsing.py index f3ec8e8f1..da24245dd 100644 --- a/src/yunohost/tests/test_apps_arguments_parsing.py +++ b/src/yunohost/tests/test_apps_arguments_parsing.py @@ -272,16 +272,6 @@ def test_parse_args_in_yunohost_format_password(): assert _parse_args_in_yunohost_format(answers, questions) == expected_result -def test_parse_args_in_yunohost_format_password_default_type(): - questions = [{ - "name": "some_password", - "type": "password", - }] - answers = {"some_password": "some_value"} - expected_result = OrderedDict({"some_password": ("some_value", "password")}) - assert _parse_args_in_yunohost_format(answers, questions) == expected_result - - def test_parse_args_in_yunohost_format_password_no_input(): questions = [{ "name": "some_password", @@ -436,3 +426,167 @@ def test_parse_args_in_yunohost_format_password_input_test_ask_with_help(): _parse_args_in_yunohost_format(answers, questions) assert ask_text in prompt.call_args[0][0] assert help_text in prompt.call_args[0][0] + + +def test_parse_args_in_yunohost_format_path(): + questions = [{ + "name": "some_path", + "type": "path", + }] + answers = {"some_path": "some_value"} + expected_result = OrderedDict({"some_path": ("some_value", "path")}) + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +def test_parse_args_in_yunohost_format_path_no_input(): + questions = [{ + "name": "some_path", + "type": "path", + }] + answers = {} + + with pytest.raises(YunohostError): + _parse_args_in_yunohost_format(answers, questions) + + +def test_parse_args_in_yunohost_format_path_input(): + questions = [{ + "name": "some_path", + "type": "path", + "ask": "some question", + }] + answers = {} + expected_result = OrderedDict({"some_path": ("some_value", "path")}) + + with patch.object(msignals, "prompt", return_value="some_value"): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +@pytest.mark.skip # that shit should work x( +def test_parse_args_in_yunohost_format_path_input_no_ask(): + questions = [{ + "name": "some_path", + "type": "path", + }] + answers = {} + expected_result = OrderedDict({"some_path": ("some_value", "path")}) + + 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_path_no_input_optional(): + questions = [{ + "name": "some_path", + "type": "path", + "optional": True, + }] + answers = {} + expected_result = OrderedDict({"some_path": ("", "path")}) + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +def test_parse_args_in_yunohost_format_path_optional_with_input(): + questions = [{ + "name": "some_path", + "ask": "some question", + "type": "path", + "optional": True, + }] + answers = {} + expected_result = OrderedDict({"some_path": ("some_value", "path")}) + + 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_path_optional_with_input_without_ask(): + questions = [{ + "name": "some_path", + "type": "path", + "optional": True, + }] + answers = {} + expected_result = OrderedDict({"some_path": ("some_value", "path")}) + + 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_path_no_input_default(): + questions = [{ + "name": "some_path", + "ask": "some question", + "type": "path", + "default": "some_value", + }] + answers = {} + expected_result = OrderedDict({"some_path": ("some_value", "path")}) + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +def test_parse_args_in_yunohost_format_path_input_test_ask(): + ask_text = "some question" + questions = [{ + "name": "some_path", + "type": "path", + "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_path_input_test_ask_with_default(): + ask_text = "some question" + default_text = "some example" + questions = [{ + "name": "some_path", + "type": "path", + "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_path_input_test_ask_with_example(): + ask_text = "some question" + example_text = "some example" + questions = [{ + "name": "some_path", + "type": "path", + "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][0] + assert example_text in prompt.call_args[0][0] + + +@pytest.mark.skip # we should do something with this help +def test_parse_args_in_yunohost_format_path_input_test_ask_with_help(): + ask_text = "some question" + help_text = "some_help" + questions = [{ + "name": "some_path", + "type": "path", + "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][0] + assert help_text in prompt.call_args[0][0]