From ec9b020376b974653647e9e7edfab09a9d9733a9 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Sat, 16 May 2020 01:42:41 +0200 Subject: [PATCH 01/11] [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] From e41d6186eee6cc76c2304d30b8a1afacac28ca52 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Sat, 16 May 2020 01:59:28 +0200 Subject: [PATCH 02/11] [mod] and more tests --- .../tests/test_apps_arguments_parsing.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/yunohost/tests/test_apps_arguments_parsing.py b/src/yunohost/tests/test_apps_arguments_parsing.py index c92007873..1b155656f 100644 --- a/src/yunohost/tests/test_apps_arguments_parsing.py +++ b/src/yunohost/tests/test_apps_arguments_parsing.py @@ -195,3 +195,26 @@ def test_parse_args_in_yunohost_format_string_input_test_ask_with_help(): _parse_args_in_yunohost_format(answers, questions) assert ask_text in prompt.call_args[0] assert help_text in prompt.call_args[0] + + +def test_parse_args_in_yunohost_format_string_with_choice(): + questions = [{ + "name": "some_string", + "type": "string", + "choices": ["fr", "en"] + }] + answers = {"some_string": "fr"} + expected_result = OrderedDict({"some_string": ("fr", "string")}) + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +def test_parse_args_in_yunohost_format_string_with_choice_bad(): + questions = [{ + "name": "some_string", + "type": "string", + "choices": ["fr", "en"] + }] + answers = {"some_string": "bad"} + + with pytest.raises(YunohostError): + assert _parse_args_in_yunohost_format(answers, questions) From 1b52eafcb723cf0307eefbead1e99b9c23ae322b Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Sat, 16 May 2020 02:48:01 +0200 Subject: [PATCH 03/11] [mod] blablabla testin' --- .../tests/test_apps_arguments_parsing.py | 50 +++++++++++++++++-- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/src/yunohost/tests/test_apps_arguments_parsing.py b/src/yunohost/tests/test_apps_arguments_parsing.py index 1b155656f..a4acc20f4 100644 --- a/src/yunohost/tests/test_apps_arguments_parsing.py +++ b/src/yunohost/tests/test_apps_arguments_parsing.py @@ -176,8 +176,8 @@ def test_parse_args_in_yunohost_format_string_input_test_ask_with_example(): 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] + 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 @@ -193,8 +193,8 @@ def test_parse_args_in_yunohost_format_string_input_test_ask_with_help(): 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] + 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_string_with_choice(): @@ -208,6 +208,18 @@ def test_parse_args_in_yunohost_format_string_with_choice(): assert _parse_args_in_yunohost_format(answers, questions) == expected_result +def test_parse_args_in_yunohost_format_string_with_choice_prompt(): + questions = [{ + "name": "some_string", + "type": "string", + "choices": ["fr", "en"] + }] + answers = {"some_string": "fr"} + expected_result = OrderedDict({"some_string": ("fr", "string")}) + with patch.object(msignals, "prompt", return_value="fr"): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + def test_parse_args_in_yunohost_format_string_with_choice_bad(): questions = [{ "name": "some_string", @@ -218,3 +230,33 @@ def test_parse_args_in_yunohost_format_string_with_choice_bad(): with pytest.raises(YunohostError): assert _parse_args_in_yunohost_format(answers, questions) + + +def test_parse_args_in_yunohost_format_string_with_choice_ask(): + ask_text = "some question" + choices = ["fr", "en", "es", "it", "ru"] + questions = [{ + "name": "some_string", + "ask": ask_text, + "choices": choices, + }] + answers = {} + + with patch.object(msignals, "prompt", return_value="ru") as prompt: + _parse_args_in_yunohost_format(answers, questions) + assert ask_text in prompt.call_args[0][0] + + for choice in choices: + assert choice in prompt.call_args[0][0] + + +def test_parse_args_in_yunohost_format_string_with_choice_default(): + questions = [{ + "name": "some_string", + "type": "string", + "choices": ["fr", "en"], + "default": "en", + }] + answers = {} + expected_result = OrderedDict({"some_string": ("en", "string")}) + assert _parse_args_in_yunohost_format(answers, questions) == expected_result From ebf9fa9d71b3f93083617dda8c15191fca4790fa Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Sat, 16 May 2020 03:19:15 +0200 Subject: [PATCH 04/11] [mod] moar tests and tests for password argument parsing --- .../tests/test_apps_arguments_parsing.py | 176 ++++++++++++++++++ 1 file changed, 176 insertions(+) diff --git a/src/yunohost/tests/test_apps_arguments_parsing.py b/src/yunohost/tests/test_apps_arguments_parsing.py index a4acc20f4..f3ec8e8f1 100644 --- a/src/yunohost/tests/test_apps_arguments_parsing.py +++ b/src/yunohost/tests/test_apps_arguments_parsing.py @@ -260,3 +260,179 @@ def test_parse_args_in_yunohost_format_string_with_choice_default(): answers = {} expected_result = OrderedDict({"some_string": ("en", "string")}) assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +def test_parse_args_in_yunohost_format_password(): + 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_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", + "type": "password", + }] + answers = {} + + with pytest.raises(YunohostError): + _parse_args_in_yunohost_format(answers, questions) + + +def test_parse_args_in_yunohost_format_password_input(): + questions = [{ + "name": "some_password", + "type": "password", + "ask": "some question", + }] + answers = {} + expected_result = OrderedDict({"some_password": ("some_value", "password")}) + + 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_password_input_no_ask(): + questions = [{ + "name": "some_password", + "type": "password", + }] + answers = {} + expected_result = OrderedDict({"some_password": ("some_value", "password")}) + + 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_password_no_input_optional(): + questions = [{ + "name": "some_password", + "type": "password", + "optional": True, + }] + answers = {} + expected_result = OrderedDict({"some_password": ("", "password")}) + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +def test_parse_args_in_yunohost_format_password_optional_with_input(): + questions = [{ + "name": "some_password", + "ask": "some question", + "type": "password", + "optional": True, + }] + answers = {} + expected_result = OrderedDict({"some_password": ("some_value", "password")}) + + 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_password_optional_with_input_without_ask(): + questions = [{ + "name": "some_password", + "type": "password", + "optional": True, + }] + answers = {} + expected_result = OrderedDict({"some_password": ("some_value", "password")}) + + with patch.object(msignals, "prompt", return_value="some_value"): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +@pytest.mark.skip # this should raises +def test_parse_args_in_yunohost_format_password_no_input_default(): + questions = [{ + "name": "some_password", + "type": "password", + "ask": "some question", + "default": "some_value", + }] + answers = {} + + # no default for password! + with pytest.raises(YunohostError): + _parse_args_in_yunohost_format(answers, questions) + + +@pytest.mark.skip # this should raises +def test_parse_args_in_yunohost_format_password_no_input_example(): + questions = [{ + "name": "some_password", + "type": "password", + "ask": "some question", + "example": "some_value", + }] + answers = {"some_password": "some_value"} + + # no example for password! + with pytest.raises(YunohostError): + _parse_args_in_yunohost_format(answers, questions) + + +def test_parse_args_in_yunohost_format_password_input_test_ask(): + ask_text = "some question" + questions = [{ + "name": "some_password", + "type": "password", + "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, True) + + +@pytest.mark.skip # we should do something with this example +def test_parse_args_in_yunohost_format_password_input_test_ask_with_example(): + ask_text = "some question" + example_text = "some example" + questions = [{ + "name": "some_password", + "type": "password", + "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_password_input_test_ask_with_help(): + ask_text = "some question" + help_text = "some_help" + questions = [{ + "name": "some_password", + "type": "password", + "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] From d1d38b173cc404eccf165ffa2e8c82dfb815178e Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Sat, 16 May 2020 03:25:51 +0200 Subject: [PATCH 05/11] [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] From e181866dcafb105a2604687bf202dc435526d3a4 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Sun, 17 May 2020 00:46:57 +0200 Subject: [PATCH 06/11] [mod] add tests for password --- .../tests/test_apps_arguments_parsing.py | 188 ++++++++++++++++++ 1 file changed, 188 insertions(+) diff --git a/src/yunohost/tests/test_apps_arguments_parsing.py b/src/yunohost/tests/test_apps_arguments_parsing.py index da24245dd..26cb4e9ab 100644 --- a/src/yunohost/tests/test_apps_arguments_parsing.py +++ b/src/yunohost/tests/test_apps_arguments_parsing.py @@ -590,3 +590,191 @@ def test_parse_args_in_yunohost_format_path_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_boolean(): + questions = [{ + "name": "some_boolean", + "type": "boolean", + }] + answers = {"some_boolean": "y"} + expected_result = OrderedDict({"some_boolean": (1, "boolean")}) + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +def test_parse_args_in_yunohost_format_boolean_all_yes(): + questions = [{ + "name": "some_boolean", + "type": "boolean", + }] + expected_result = OrderedDict({"some_boolean": (1, "boolean")}) + assert _parse_args_in_yunohost_format({"some_boolean": "y"}, questions) == expected_result + assert _parse_args_in_yunohost_format({"some_boolean": "Y"}, questions) == expected_result + assert _parse_args_in_yunohost_format({"some_boolean": "yes"}, questions) == expected_result + assert _parse_args_in_yunohost_format({"some_boolean": "Yes"}, questions) == expected_result + assert _parse_args_in_yunohost_format({"some_boolean": "YES"}, questions) == expected_result + assert _parse_args_in_yunohost_format({"some_boolean": "1"}, questions) == expected_result + assert _parse_args_in_yunohost_format({"some_boolean": 1}, questions) == expected_result + assert _parse_args_in_yunohost_format({"some_boolean": True}, questions) == expected_result + + +def test_parse_args_in_yunohost_format_boolean_all_no(): + questions = [{ + "name": "some_boolean", + "type": "boolean", + }] + expected_result = OrderedDict({"some_boolean": (0, "boolean")}) + assert _parse_args_in_yunohost_format({"some_boolean": "n"}, questions) == expected_result + assert _parse_args_in_yunohost_format({"some_boolean": "N"}, questions) == expected_result + assert _parse_args_in_yunohost_format({"some_boolean": "no"}, questions) == expected_result + assert _parse_args_in_yunohost_format({"some_boolean": "No"}, questions) == expected_result + assert _parse_args_in_yunohost_format({"some_boolean": "No"}, questions) == expected_result + assert _parse_args_in_yunohost_format({"some_boolean": "0"}, questions) == expected_result + assert _parse_args_in_yunohost_format({"some_boolean": 0}, questions) == expected_result + assert _parse_args_in_yunohost_format({"some_boolean": False}, questions) == expected_result + + +# XXX apparently boolean are always False (0) by default, I'm not sure what to think about that +def test_parse_args_in_yunohost_format_boolean_no_input(): + questions = [{ + "name": "some_boolean", + "type": "boolean", + }] + answers = {} + + expected_result = OrderedDict({"some_boolean": (0, "boolean")}) + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +def test_parse_args_in_yunohost_format_boolean_bad_input(): + questions = [{ + "name": "some_boolean", + "type": "boolean", + }] + answers = {"some_boolean": "stuff"} + + with pytest.raises(YunohostError): + _parse_args_in_yunohost_format(answers, questions) + + +def test_parse_args_in_yunohost_format_boolean_input(): + questions = [{ + "name": "some_boolean", + "type": "boolean", + "ask": "some question", + }] + answers = {} + + expected_result = OrderedDict({"some_boolean": (1, "boolean")}) + with patch.object(msignals, "prompt", return_value="y"): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + expected_result = OrderedDict({"some_boolean": (0, "boolean")}) + with patch.object(msignals, "prompt", return_value="n"): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +@pytest.mark.skip # we should work +def test_parse_args_in_yunohost_format_boolean_input_no_ask(): + questions = [{ + "name": "some_boolean", + "type": "boolean", + }] + answers = {} + expected_result = OrderedDict({"some_boolean": ("some_value", "boolean")}) + + with patch.object(msignals, "prompt", return_value="y"): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +def test_parse_args_in_yunohost_format_boolean_no_input_optional(): + questions = [{ + "name": "some_boolean", + "type": "boolean", + "optional": True, + }] + answers = {} + expected_result = OrderedDict({"some_boolean": (0, "boolean")}) # default to false + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +def test_parse_args_in_yunohost_format_boolean_optional_with_input(): + questions = [{ + "name": "some_boolean", + "ask": "some question", + "type": "boolean", + "optional": True, + }] + answers = {} + expected_result = OrderedDict({"some_boolean": (1, "boolean")}) + + with patch.object(msignals, "prompt", return_value="y"): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +def test_parse_args_in_yunohost_format_boolean_optional_with_input_without_ask(): + questions = [{ + "name": "some_boolean", + "type": "boolean", + "optional": True, + }] + answers = {} + expected_result = OrderedDict({"some_boolean": (0, "boolean")}) + + with patch.object(msignals, "prompt", return_value="n"): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +def test_parse_args_in_yunohost_format_boolean_no_input_default(): + questions = [{ + "name": "some_boolean", + "ask": "some question", + "type": "boolean", + "default": 0, + }] + answers = {} + expected_result = OrderedDict({"some_boolean": (0, "boolean")}) + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +@pytest.mark.skip # we should raise +def test_parse_args_in_yunohost_format_boolean_bad_default(): + questions = [{ + "name": "some_boolean", + "ask": "some question", + "type": "boolean", + "default": "bad default", + }] + answers = {} + with pytest.raises(YunohostError): + _parse_args_in_yunohost_format(answers, questions) + + +def test_parse_args_in_yunohost_format_boolean_input_test_ask(): + ask_text = "some question" + questions = [{ + "name": "some_boolean", + "type": "boolean", + "ask": ask_text, + }] + answers = {} + + with patch.object(msignals, "prompt", return_value=0) as prompt: + _parse_args_in_yunohost_format(answers, questions) + prompt.assert_called_with(ask_text + " [yes | no] (default: no)", False) + + +def test_parse_args_in_yunohost_format_boolean_input_test_ask_with_default(): + ask_text = "some question" + default_text = 1 + questions = [{ + "name": "some_boolean", + "type": "boolean", + "ask": ask_text, + "default": default_text, + }] + answers = {} + + with patch.object(msignals, "prompt", return_value=1) as prompt: + _parse_args_in_yunohost_format(answers, questions) + prompt.assert_called_with("%s [yes | no] (default: yes)" % ask_text, False) From 69f8ab1ac45eb3f0d93c3ff1dd070f7240420f3c Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Sun, 17 May 2020 02:04:50 +0200 Subject: [PATCH 07/11] [mod] black file --- .../tests/test_apps_arguments_parsing.py | 495 ++++++++---------- 1 file changed, 207 insertions(+), 288 deletions(-) diff --git a/src/yunohost/tests/test_apps_arguments_parsing.py b/src/yunohost/tests/test_apps_arguments_parsing.py index 26cb4e9ab..641823506 100644 --- a/src/yunohost/tests/test_apps_arguments_parsing.py +++ b/src/yunohost/tests/test_apps_arguments_parsing.py @@ -36,28 +36,21 @@ def test_parse_args_in_yunohost_format_empty(): def test_parse_args_in_yunohost_format_string(): - questions = [{ - "name": "some_string", - "type": "string", - }] + questions = [{"name": "some_string", "type": "string",}] answers = {"some_string": "some_value"} 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_default_type(): - questions = [{ - "name": "some_string", - }] + questions = [{"name": "some_string",}] answers = {"some_string": "some_value"} 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_no_input(): - questions = [{ - "name": "some_string", - }] + questions = [{"name": "some_string",}] answers = {} with pytest.raises(YunohostError): @@ -65,10 +58,7 @@ def test_parse_args_in_yunohost_format_string_no_input(): def test_parse_args_in_yunohost_format_string_input(): - questions = [{ - "name": "some_string", - "ask": "some question", - }] + questions = [{"name": "some_string", "ask": "some question",}] answers = {} expected_result = OrderedDict({"some_string": ("some_value", "string")}) @@ -78,9 +68,7 @@ def test_parse_args_in_yunohost_format_string_input(): @pytest.mark.skip # that shit should work x( def test_parse_args_in_yunohost_format_string_input_no_ask(): - questions = [{ - "name": "some_string", - }] + questions = [{"name": "some_string",}] answers = {} expected_result = OrderedDict({"some_string": ("some_value", "string")}) @@ -89,21 +77,14 @@ def test_parse_args_in_yunohost_format_string_input_no_ask(): def test_parse_args_in_yunohost_format_string_no_input_optional(): - questions = [{ - "name": "some_string", - "optional": True, - }] + questions = [{"name": "some_string", "optional": True,}] answers = {} expected_result = OrderedDict({"some_string": ("", "string")}) 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, - }] + questions = [{"name": "some_string", "ask": "some question", "optional": True,}] answers = {} expected_result = OrderedDict({"some_string": ("some_value", "string")}) @@ -113,10 +94,7 @@ def test_parse_args_in_yunohost_format_string_optional_with_input(): @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, - }] + questions = [{"name": "some_string", "optional": True,}] answers = {} expected_result = OrderedDict({"some_string": ("some_value", "string")}) @@ -125,11 +103,9 @@ def test_parse_args_in_yunohost_format_string_optional_with_input_without_ask(): def test_parse_args_in_yunohost_format_string_no_input_default(): - questions = [{ - "name": "some_string", - "ask": "some question", - "default": "some_value", - }] + questions = [ + {"name": "some_string", "ask": "some question", "default": "some_value",} + ] answers = {} expected_result = OrderedDict({"some_string": ("some_value", "string")}) assert _parse_args_in_yunohost_format(answers, questions) == expected_result @@ -137,10 +113,7 @@ def test_parse_args_in_yunohost_format_string_no_input_default(): def test_parse_args_in_yunohost_format_string_input_test_ask(): ask_text = "some question" - questions = [{ - "name": "some_string", - "ask": ask_text, - }] + questions = [{"name": "some_string", "ask": ask_text,}] answers = {} with patch.object(msignals, "prompt", return_value="some_value") as prompt: @@ -151,11 +124,7 @@ def test_parse_args_in_yunohost_format_string_input_test_ask(): 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, - }] + questions = [{"name": "some_string", "ask": ask_text, "default": default_text,}] answers = {} with patch.object(msignals, "prompt", return_value="some_value") as prompt: @@ -167,11 +136,7 @@ def test_parse_args_in_yunohost_format_string_input_test_ask_with_default(): 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, - }] + questions = [{"name": "some_string", "ask": ask_text, "example": example_text,}] answers = {} with patch.object(msignals, "prompt", return_value="some_value") as prompt: @@ -184,11 +149,7 @@ def test_parse_args_in_yunohost_format_string_input_test_ask_with_example(): 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, - }] + questions = [{"name": "some_string", "ask": ask_text, "help": help_text,}] answers = {} with patch.object(msignals, "prompt", return_value="some_value") as prompt: @@ -198,22 +159,14 @@ def test_parse_args_in_yunohost_format_string_input_test_ask_with_help(): def test_parse_args_in_yunohost_format_string_with_choice(): - questions = [{ - "name": "some_string", - "type": "string", - "choices": ["fr", "en"] - }] + questions = [{"name": "some_string", "type": "string", "choices": ["fr", "en"]}] answers = {"some_string": "fr"} expected_result = OrderedDict({"some_string": ("fr", "string")}) assert _parse_args_in_yunohost_format(answers, questions) == expected_result def test_parse_args_in_yunohost_format_string_with_choice_prompt(): - questions = [{ - "name": "some_string", - "type": "string", - "choices": ["fr", "en"] - }] + questions = [{"name": "some_string", "type": "string", "choices": ["fr", "en"]}] answers = {"some_string": "fr"} expected_result = OrderedDict({"some_string": ("fr", "string")}) with patch.object(msignals, "prompt", return_value="fr"): @@ -221,11 +174,7 @@ def test_parse_args_in_yunohost_format_string_with_choice_prompt(): def test_parse_args_in_yunohost_format_string_with_choice_bad(): - questions = [{ - "name": "some_string", - "type": "string", - "choices": ["fr", "en"] - }] + questions = [{"name": "some_string", "type": "string", "choices": ["fr", "en"]}] answers = {"some_string": "bad"} with pytest.raises(YunohostError): @@ -235,11 +184,7 @@ def test_parse_args_in_yunohost_format_string_with_choice_bad(): def test_parse_args_in_yunohost_format_string_with_choice_ask(): ask_text = "some question" choices = ["fr", "en", "es", "it", "ru"] - questions = [{ - "name": "some_string", - "ask": ask_text, - "choices": choices, - }] + questions = [{"name": "some_string", "ask": ask_text, "choices": choices,}] answers = {} with patch.object(msignals, "prompt", return_value="ru") as prompt: @@ -251,32 +196,28 @@ def test_parse_args_in_yunohost_format_string_with_choice_ask(): def test_parse_args_in_yunohost_format_string_with_choice_default(): - questions = [{ - "name": "some_string", - "type": "string", - "choices": ["fr", "en"], - "default": "en", - }] + questions = [ + { + "name": "some_string", + "type": "string", + "choices": ["fr", "en"], + "default": "en", + } + ] answers = {} expected_result = OrderedDict({"some_string": ("en", "string")}) assert _parse_args_in_yunohost_format(answers, questions) == expected_result def test_parse_args_in_yunohost_format_password(): - questions = [{ - "name": "some_password", - "type": "password", - }] + 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", - "type": "password", - }] + questions = [{"name": "some_password", "type": "password",}] answers = {} with pytest.raises(YunohostError): @@ -284,11 +225,7 @@ def test_parse_args_in_yunohost_format_password_no_input(): def test_parse_args_in_yunohost_format_password_input(): - questions = [{ - "name": "some_password", - "type": "password", - "ask": "some question", - }] + questions = [{"name": "some_password", "type": "password", "ask": "some question",}] answers = {} expected_result = OrderedDict({"some_password": ("some_value", "password")}) @@ -298,10 +235,7 @@ def test_parse_args_in_yunohost_format_password_input(): @pytest.mark.skip # that shit should work x( def test_parse_args_in_yunohost_format_password_input_no_ask(): - questions = [{ - "name": "some_password", - "type": "password", - }] + questions = [{"name": "some_password", "type": "password",}] answers = {} expected_result = OrderedDict({"some_password": ("some_value", "password")}) @@ -310,23 +244,21 @@ def test_parse_args_in_yunohost_format_password_input_no_ask(): def test_parse_args_in_yunohost_format_password_no_input_optional(): - questions = [{ - "name": "some_password", - "type": "password", - "optional": True, - }] + questions = [{"name": "some_password", "type": "password", "optional": True,}] answers = {} expected_result = OrderedDict({"some_password": ("", "password")}) assert _parse_args_in_yunohost_format(answers, questions) == expected_result def test_parse_args_in_yunohost_format_password_optional_with_input(): - questions = [{ - "name": "some_password", - "ask": "some question", - "type": "password", - "optional": True, - }] + questions = [ + { + "name": "some_password", + "ask": "some question", + "type": "password", + "optional": True, + } + ] answers = {} expected_result = OrderedDict({"some_password": ("some_value", "password")}) @@ -336,11 +268,7 @@ def test_parse_args_in_yunohost_format_password_optional_with_input(): @pytest.mark.skip # this should work without ask def test_parse_args_in_yunohost_format_password_optional_with_input_without_ask(): - questions = [{ - "name": "some_password", - "type": "password", - "optional": True, - }] + questions = [{"name": "some_password", "type": "password", "optional": True,}] answers = {} expected_result = OrderedDict({"some_password": ("some_value", "password")}) @@ -350,12 +278,14 @@ def test_parse_args_in_yunohost_format_password_optional_with_input_without_ask( @pytest.mark.skip # this should raises def test_parse_args_in_yunohost_format_password_no_input_default(): - questions = [{ - "name": "some_password", - "type": "password", - "ask": "some question", - "default": "some_value", - }] + questions = [ + { + "name": "some_password", + "type": "password", + "ask": "some question", + "default": "some_value", + } + ] answers = {} # no default for password! @@ -365,12 +295,14 @@ def test_parse_args_in_yunohost_format_password_no_input_default(): @pytest.mark.skip # this should raises def test_parse_args_in_yunohost_format_password_no_input_example(): - questions = [{ - "name": "some_password", - "type": "password", - "ask": "some question", - "example": "some_value", - }] + questions = [ + { + "name": "some_password", + "type": "password", + "ask": "some question", + "example": "some_value", + } + ] answers = {"some_password": "some_value"} # no example for password! @@ -380,11 +312,7 @@ def test_parse_args_in_yunohost_format_password_no_input_example(): def test_parse_args_in_yunohost_format_password_input_test_ask(): ask_text = "some question" - questions = [{ - "name": "some_password", - "type": "password", - "ask": ask_text, - }] + questions = [{"name": "some_password", "type": "password", "ask": ask_text,}] answers = {} with patch.object(msignals, "prompt", return_value="some_value") as prompt: @@ -396,12 +324,14 @@ def test_parse_args_in_yunohost_format_password_input_test_ask(): def test_parse_args_in_yunohost_format_password_input_test_ask_with_example(): ask_text = "some question" example_text = "some example" - questions = [{ - "name": "some_password", - "type": "password", - "ask": ask_text, - "example": example_text, - }] + questions = [ + { + "name": "some_password", + "type": "password", + "ask": ask_text, + "example": example_text, + } + ] answers = {} with patch.object(msignals, "prompt", return_value="some_value") as prompt: @@ -414,12 +344,14 @@ def test_parse_args_in_yunohost_format_password_input_test_ask_with_example(): def test_parse_args_in_yunohost_format_password_input_test_ask_with_help(): ask_text = "some question" help_text = "some_help" - questions = [{ - "name": "some_password", - "type": "password", - "ask": ask_text, - "help": help_text, - }] + questions = [ + { + "name": "some_password", + "type": "password", + "ask": ask_text, + "help": help_text, + } + ] answers = {} with patch.object(msignals, "prompt", return_value="some_value") as prompt: @@ -429,20 +361,14 @@ def test_parse_args_in_yunohost_format_password_input_test_ask_with_help(): def test_parse_args_in_yunohost_format_path(): - questions = [{ - "name": "some_path", - "type": "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", - }] + questions = [{"name": "some_path", "type": "path",}] answers = {} with pytest.raises(YunohostError): @@ -450,11 +376,7 @@ def test_parse_args_in_yunohost_format_path_no_input(): def test_parse_args_in_yunohost_format_path_input(): - questions = [{ - "name": "some_path", - "type": "path", - "ask": "some question", - }] + questions = [{"name": "some_path", "type": "path", "ask": "some question",}] answers = {} expected_result = OrderedDict({"some_path": ("some_value", "path")}) @@ -464,10 +386,7 @@ def test_parse_args_in_yunohost_format_path_input(): @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", - }] + questions = [{"name": "some_path", "type": "path",}] answers = {} expected_result = OrderedDict({"some_path": ("some_value", "path")}) @@ -476,23 +395,16 @@ def test_parse_args_in_yunohost_format_path_input_no_ask(): def test_parse_args_in_yunohost_format_path_no_input_optional(): - questions = [{ - "name": "some_path", - "type": "path", - "optional": True, - }] + 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, - }] + questions = [ + {"name": "some_path", "ask": "some question", "type": "path", "optional": True,} + ] answers = {} expected_result = OrderedDict({"some_path": ("some_value", "path")}) @@ -502,11 +414,7 @@ def test_parse_args_in_yunohost_format_path_optional_with_input(): @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, - }] + questions = [{"name": "some_path", "type": "path", "optional": True,}] answers = {} expected_result = OrderedDict({"some_path": ("some_value", "path")}) @@ -515,12 +423,14 @@ def test_parse_args_in_yunohost_format_path_optional_with_input_without_ask(): def test_parse_args_in_yunohost_format_path_no_input_default(): - questions = [{ - "name": "some_path", - "ask": "some question", - "type": "path", - "default": "some_value", - }] + 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 @@ -528,11 +438,7 @@ def test_parse_args_in_yunohost_format_path_no_input_default(): def test_parse_args_in_yunohost_format_path_input_test_ask(): ask_text = "some question" - questions = [{ - "name": "some_path", - "type": "path", - "ask": ask_text, - }] + questions = [{"name": "some_path", "type": "path", "ask": ask_text,}] answers = {} with patch.object(msignals, "prompt", return_value="some_value") as prompt: @@ -543,12 +449,9 @@ def test_parse_args_in_yunohost_format_path_input_test_ask(): 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, - }] + questions = [ + {"name": "some_path", "type": "path", "ask": ask_text, "default": default_text,} + ] answers = {} with patch.object(msignals, "prompt", return_value="some_value") as prompt: @@ -560,12 +463,9 @@ def test_parse_args_in_yunohost_format_path_input_test_ask_with_default(): 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, - }] + questions = [ + {"name": "some_path", "type": "path", "ask": ask_text, "example": example_text,} + ] answers = {} with patch.object(msignals, "prompt", return_value="some_value") as prompt: @@ -578,12 +478,9 @@ def test_parse_args_in_yunohost_format_path_input_test_ask_with_example(): 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, - }] + questions = [ + {"name": "some_path", "type": "path", "ask": ask_text, "help": help_text,} + ] answers = {} with patch.object(msignals, "prompt", return_value="some_value") as prompt: @@ -593,53 +490,89 @@ def test_parse_args_in_yunohost_format_path_input_test_ask_with_help(): def test_parse_args_in_yunohost_format_boolean(): - questions = [{ - "name": "some_boolean", - "type": "boolean", - }] + questions = [{"name": "some_boolean", "type": "boolean",}] answers = {"some_boolean": "y"} expected_result = OrderedDict({"some_boolean": (1, "boolean")}) assert _parse_args_in_yunohost_format(answers, questions) == expected_result def test_parse_args_in_yunohost_format_boolean_all_yes(): - questions = [{ - "name": "some_boolean", - "type": "boolean", - }] + questions = [{"name": "some_boolean", "type": "boolean",}] expected_result = OrderedDict({"some_boolean": (1, "boolean")}) - assert _parse_args_in_yunohost_format({"some_boolean": "y"}, questions) == expected_result - assert _parse_args_in_yunohost_format({"some_boolean": "Y"}, questions) == expected_result - assert _parse_args_in_yunohost_format({"some_boolean": "yes"}, questions) == expected_result - assert _parse_args_in_yunohost_format({"some_boolean": "Yes"}, questions) == expected_result - assert _parse_args_in_yunohost_format({"some_boolean": "YES"}, questions) == expected_result - assert _parse_args_in_yunohost_format({"some_boolean": "1"}, questions) == expected_result - assert _parse_args_in_yunohost_format({"some_boolean": 1}, questions) == expected_result - assert _parse_args_in_yunohost_format({"some_boolean": True}, questions) == expected_result + assert ( + _parse_args_in_yunohost_format({"some_boolean": "y"}, questions) + == expected_result + ) + assert ( + _parse_args_in_yunohost_format({"some_boolean": "Y"}, questions) + == expected_result + ) + assert ( + _parse_args_in_yunohost_format({"some_boolean": "yes"}, questions) + == expected_result + ) + assert ( + _parse_args_in_yunohost_format({"some_boolean": "Yes"}, questions) + == expected_result + ) + assert ( + _parse_args_in_yunohost_format({"some_boolean": "YES"}, questions) + == expected_result + ) + assert ( + _parse_args_in_yunohost_format({"some_boolean": "1"}, questions) + == expected_result + ) + assert ( + _parse_args_in_yunohost_format({"some_boolean": 1}, questions) + == expected_result + ) + assert ( + _parse_args_in_yunohost_format({"some_boolean": True}, questions) + == expected_result + ) def test_parse_args_in_yunohost_format_boolean_all_no(): - questions = [{ - "name": "some_boolean", - "type": "boolean", - }] + questions = [{"name": "some_boolean", "type": "boolean",}] expected_result = OrderedDict({"some_boolean": (0, "boolean")}) - assert _parse_args_in_yunohost_format({"some_boolean": "n"}, questions) == expected_result - assert _parse_args_in_yunohost_format({"some_boolean": "N"}, questions) == expected_result - assert _parse_args_in_yunohost_format({"some_boolean": "no"}, questions) == expected_result - assert _parse_args_in_yunohost_format({"some_boolean": "No"}, questions) == expected_result - assert _parse_args_in_yunohost_format({"some_boolean": "No"}, questions) == expected_result - assert _parse_args_in_yunohost_format({"some_boolean": "0"}, questions) == expected_result - assert _parse_args_in_yunohost_format({"some_boolean": 0}, questions) == expected_result - assert _parse_args_in_yunohost_format({"some_boolean": False}, questions) == expected_result + assert ( + _parse_args_in_yunohost_format({"some_boolean": "n"}, questions) + == expected_result + ) + assert ( + _parse_args_in_yunohost_format({"some_boolean": "N"}, questions) + == expected_result + ) + assert ( + _parse_args_in_yunohost_format({"some_boolean": "no"}, questions) + == expected_result + ) + assert ( + _parse_args_in_yunohost_format({"some_boolean": "No"}, questions) + == expected_result + ) + assert ( + _parse_args_in_yunohost_format({"some_boolean": "No"}, questions) + == expected_result + ) + assert ( + _parse_args_in_yunohost_format({"some_boolean": "0"}, questions) + == expected_result + ) + assert ( + _parse_args_in_yunohost_format({"some_boolean": 0}, questions) + == expected_result + ) + assert ( + _parse_args_in_yunohost_format({"some_boolean": False}, questions) + == expected_result + ) # XXX apparently boolean are always False (0) by default, I'm not sure what to think about that def test_parse_args_in_yunohost_format_boolean_no_input(): - questions = [{ - "name": "some_boolean", - "type": "boolean", - }] + questions = [{"name": "some_boolean", "type": "boolean",}] answers = {} expected_result = OrderedDict({"some_boolean": (0, "boolean")}) @@ -647,10 +580,7 @@ def test_parse_args_in_yunohost_format_boolean_no_input(): def test_parse_args_in_yunohost_format_boolean_bad_input(): - questions = [{ - "name": "some_boolean", - "type": "boolean", - }] + questions = [{"name": "some_boolean", "type": "boolean",}] answers = {"some_boolean": "stuff"} with pytest.raises(YunohostError): @@ -658,11 +588,7 @@ def test_parse_args_in_yunohost_format_boolean_bad_input(): def test_parse_args_in_yunohost_format_boolean_input(): - questions = [{ - "name": "some_boolean", - "type": "boolean", - "ask": "some question", - }] + questions = [{"name": "some_boolean", "type": "boolean", "ask": "some question",}] answers = {} expected_result = OrderedDict({"some_boolean": (1, "boolean")}) @@ -676,10 +602,7 @@ def test_parse_args_in_yunohost_format_boolean_input(): @pytest.mark.skip # we should work def test_parse_args_in_yunohost_format_boolean_input_no_ask(): - questions = [{ - "name": "some_boolean", - "type": "boolean", - }] + questions = [{"name": "some_boolean", "type": "boolean",}] answers = {} expected_result = OrderedDict({"some_boolean": ("some_value", "boolean")}) @@ -688,23 +611,21 @@ def test_parse_args_in_yunohost_format_boolean_input_no_ask(): def test_parse_args_in_yunohost_format_boolean_no_input_optional(): - questions = [{ - "name": "some_boolean", - "type": "boolean", - "optional": True, - }] + questions = [{"name": "some_boolean", "type": "boolean", "optional": True,}] answers = {} expected_result = OrderedDict({"some_boolean": (0, "boolean")}) # default to false assert _parse_args_in_yunohost_format(answers, questions) == expected_result def test_parse_args_in_yunohost_format_boolean_optional_with_input(): - questions = [{ - "name": "some_boolean", - "ask": "some question", - "type": "boolean", - "optional": True, - }] + questions = [ + { + "name": "some_boolean", + "ask": "some question", + "type": "boolean", + "optional": True, + } + ] answers = {} expected_result = OrderedDict({"some_boolean": (1, "boolean")}) @@ -713,11 +634,7 @@ def test_parse_args_in_yunohost_format_boolean_optional_with_input(): def test_parse_args_in_yunohost_format_boolean_optional_with_input_without_ask(): - questions = [{ - "name": "some_boolean", - "type": "boolean", - "optional": True, - }] + questions = [{"name": "some_boolean", "type": "boolean", "optional": True,}] answers = {} expected_result = OrderedDict({"some_boolean": (0, "boolean")}) @@ -726,12 +643,14 @@ def test_parse_args_in_yunohost_format_boolean_optional_with_input_without_ask() def test_parse_args_in_yunohost_format_boolean_no_input_default(): - questions = [{ - "name": "some_boolean", - "ask": "some question", - "type": "boolean", - "default": 0, - }] + questions = [ + { + "name": "some_boolean", + "ask": "some question", + "type": "boolean", + "default": 0, + } + ] answers = {} expected_result = OrderedDict({"some_boolean": (0, "boolean")}) assert _parse_args_in_yunohost_format(answers, questions) == expected_result @@ -739,12 +658,14 @@ def test_parse_args_in_yunohost_format_boolean_no_input_default(): @pytest.mark.skip # we should raise def test_parse_args_in_yunohost_format_boolean_bad_default(): - questions = [{ - "name": "some_boolean", - "ask": "some question", - "type": "boolean", - "default": "bad default", - }] + questions = [ + { + "name": "some_boolean", + "ask": "some question", + "type": "boolean", + "default": "bad default", + } + ] answers = {} with pytest.raises(YunohostError): _parse_args_in_yunohost_format(answers, questions) @@ -752,11 +673,7 @@ def test_parse_args_in_yunohost_format_boolean_bad_default(): def test_parse_args_in_yunohost_format_boolean_input_test_ask(): ask_text = "some question" - questions = [{ - "name": "some_boolean", - "type": "boolean", - "ask": ask_text, - }] + questions = [{"name": "some_boolean", "type": "boolean", "ask": ask_text,}] answers = {} with patch.object(msignals, "prompt", return_value=0) as prompt: @@ -767,12 +684,14 @@ def test_parse_args_in_yunohost_format_boolean_input_test_ask(): def test_parse_args_in_yunohost_format_boolean_input_test_ask_with_default(): ask_text = "some question" default_text = 1 - questions = [{ - "name": "some_boolean", - "type": "boolean", - "ask": ask_text, - "default": default_text, - }] + questions = [ + { + "name": "some_boolean", + "type": "boolean", + "ask": ask_text, + "default": default_text, + } + ] answers = {} with patch.object(msignals, "prompt", return_value=1) as prompt: From 306f4e06ab0a40c568671c12b77ab45d5901ccb8 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Sun, 24 May 2020 01:11:30 +0200 Subject: [PATCH 08/11] [mod] add tests for domains --- .../tests/test_apps_arguments_parsing.py | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/src/yunohost/tests/test_apps_arguments_parsing.py b/src/yunohost/tests/test_apps_arguments_parsing.py index 641823506..61df50d87 100644 --- a/src/yunohost/tests/test_apps_arguments_parsing.py +++ b/src/yunohost/tests/test_apps_arguments_parsing.py @@ -4,6 +4,7 @@ from mock import patch from moulinette import msignals +from yunohost import domain from yunohost.app import _parse_args_in_yunohost_format from yunohost.utils.error import YunohostError @@ -697,3 +698,119 @@ def test_parse_args_in_yunohost_format_boolean_input_test_ask_with_default(): with patch.object(msignals, "prompt", return_value=1) as prompt: _parse_args_in_yunohost_format(answers, questions) prompt.assert_called_with("%s [yes | no] (default: yes)" % ask_text, False) + + +def test_parse_args_in_yunohost_format_domain_empty(): + questions = [{"name": "some_domain", "type": "domain",}] + answers = {} + + with patch.object( + domain, "_get_maindomain", return_value="my_main_domain.com" + ), patch.object( + domain, "domain_list", return_value={"domains": ["my_main_domain.com"]} + ): + with pytest.raises(YunohostError): + _parse_args_in_yunohost_format(answers, questions) + + +def test_parse_args_in_yunohost_format_domain(): + main_domain = "my_main_domain.com" + domains = [main_domain] + questions = [{"name": "some_domain", "type": "domain",}] + + answers = {"some_domain": main_domain} + expected_result = OrderedDict({"some_domain": (main_domain, "domain")}) + + with patch.object( + domain, "_get_maindomain", return_value=main_domain + ), patch.object(domain, "domain_list", return_value={"domains": domains}): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +def test_parse_args_in_yunohost_format_domain_two_domains(): + main_domain = "my_main_domain.com" + other_domain = "some_other_domain.tld" + domains = [main_domain, other_domain] + + questions = [{"name": "some_domain", "type": "domain",}] + answers = {"some_domain": other_domain} + expected_result = OrderedDict({"some_domain": (other_domain, "domain")}) + + with patch.object( + domain, "_get_maindomain", return_value=main_domain + ), patch.object(domain, "domain_list", return_value={"domains": domains}): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + answers = {"some_domain": main_domain} + expected_result = OrderedDict({"some_domain": (main_domain, "domain")}) + + with patch.object( + domain, "_get_maindomain", return_value=main_domain + ), patch.object(domain, "domain_list", return_value={"domains": domains}): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +def test_parse_args_in_yunohost_format_domain_two_domains_wrong_answer(): + main_domain = "my_main_domain.com" + other_domain = "some_other_domain.tld" + domains = [main_domain, other_domain] + + questions = [{"name": "some_domain", "type": "domain",}] + answers = {"some_domain": "doesnt_exist.pouet"} + + with patch.object( + domain, "_get_maindomain", return_value=main_domain + ), patch.object(domain, "domain_list", return_value={"domains": domains}): + with pytest.raises(YunohostError): + _parse_args_in_yunohost_format(answers, questions) + + +@pytest.mark.skip # XXX should work +def test_parse_args_in_yunohost_format_domain_two_domains_default_no_ask(): + main_domain = "my_main_domain.com" + other_domain = "some_other_domain.tld" + domains = [main_domain, other_domain] + + questions = [{"name": "some_domain", "type": "domain",}] + answers = {} + expected_result = OrderedDict({"some_domain": (main_domain, "domain")}) + + with patch.object( + domain, "_get_maindomain", return_value=main_domain + ), patch.object(domain, "domain_list", return_value={"domains": domains}): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +def test_parse_args_in_yunohost_format_domain_two_domains_default(): + main_domain = "my_main_domain.com" + other_domain = "some_other_domain.tld" + domains = [main_domain, other_domain] + + questions = [{"name": "some_domain", "type": "domain", "ask": "choose a domain"}] + answers = {} + expected_result = OrderedDict({"some_domain": (main_domain, "domain")}) + + with patch.object( + domain, "_get_maindomain", return_value=main_domain + ), patch.object(domain, "domain_list", return_value={"domains": domains}): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +def test_parse_args_in_yunohost_format_domain_two_domains_default_input(): + main_domain = "my_main_domain.com" + other_domain = "some_other_domain.tld" + domains = [main_domain, other_domain] + + questions = [{"name": "some_domain", "type": "domain", "ask": "choose a domain"}] + answers = {} + + with patch.object( + domain, "_get_maindomain", return_value=main_domain + ), patch.object(domain, "domain_list", return_value={"domains": domains}): + expected_result = OrderedDict({"some_domain": (main_domain, "domain")}) + with patch.object(msignals, "prompt", return_value=main_domain): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + expected_result = OrderedDict({"some_domain": (other_domain, "domain")}) + with patch.object(msignals, "prompt", return_value=other_domain): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result From a8f8ee5e6cacc2a2e7248ffc081ffda2ac8e7b7f Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Sun, 24 May 2020 04:22:34 +0200 Subject: [PATCH 09/11] [mod] add tests for user arguments parsing --- .../tests/test_apps_arguments_parsing.py | 175 +++++++++++++++++- 1 file changed, 174 insertions(+), 1 deletion(-) diff --git a/src/yunohost/tests/test_apps_arguments_parsing.py b/src/yunohost/tests/test_apps_arguments_parsing.py index 61df50d87..12ce9f693 100644 --- a/src/yunohost/tests/test_apps_arguments_parsing.py +++ b/src/yunohost/tests/test_apps_arguments_parsing.py @@ -4,7 +4,7 @@ from mock import patch from moulinette import msignals -from yunohost import domain +from yunohost import domain, user from yunohost.app import _parse_args_in_yunohost_format from yunohost.utils.error import YunohostError @@ -814,3 +814,176 @@ def test_parse_args_in_yunohost_format_domain_two_domains_default_input(): expected_result = OrderedDict({"some_domain": (other_domain, "domain")}) with patch.object(msignals, "prompt", return_value=other_domain): assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +def test_parse_args_in_yunohost_format_user_empty(): + users = { + "some_user": { + "ssh_allowed": False, + "username": "some_user", + "shell": "/bin/false", + "mailbox-quota": "0", + "mail": "p@ynh.local", + "fullname": "the first name the last name", + } + } + + questions = [{"name": "some_user", "type": "user",}] + answers = {} + + with patch.object(user, "user_list", return_value={"users": users}): + with pytest.raises(YunohostError): + _parse_args_in_yunohost_format(answers, questions) + + +def test_parse_args_in_yunohost_format_user(): + username = "some_user" + users = { + username: { + "ssh_allowed": False, + "username": "some_user", + "shell": "/bin/false", + "mailbox-quota": "0", + "mail": "p@ynh.local", + "fullname": "the first name the last name", + } + } + + questions = [{"name": "some_user", "type": "user",}] + answers = {"some_user": username} + + expected_result = OrderedDict({"some_user": (username, "user")}) + + with patch.object(user, "user_list", return_value={"users": users}): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +def test_parse_args_in_yunohost_format_user_two_users(): + username = "some_user" + other_user = "some_other_user" + users = { + username: { + "ssh_allowed": False, + "username": "some_user", + "shell": "/bin/false", + "mailbox-quota": "0", + "mail": "p@ynh.local", + "fullname": "the first name the last name", + }, + other_user: { + "ssh_allowed": False, + "username": "some_user", + "shell": "/bin/false", + "mailbox-quota": "0", + "mail": "z@ynh.local", + "fullname": "john doe", + }, + } + + questions = [{"name": "some_user", "type": "user",}] + answers = {"some_user": other_user} + expected_result = OrderedDict({"some_user": (other_user, "user")}) + + with patch.object(user, "user_list", return_value={"users": users}): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + answers = {"some_user": username} + expected_result = OrderedDict({"some_user": (username, "user")}) + + with patch.object(user, "user_list", return_value={"users": users}): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +def test_parse_args_in_yunohost_format_user_two_users_wrong_answer(): + username = "my_username.com" + other_user = "some_other_user" + users = { + username: { + "ssh_allowed": False, + "username": "some_user", + "shell": "/bin/false", + "mailbox-quota": "0", + "mail": "p@ynh.local", + "fullname": "the first name the last name", + }, + other_user: { + "ssh_allowed": False, + "username": "some_user", + "shell": "/bin/false", + "mailbox-quota": "0", + "mail": "z@ynh.local", + "fullname": "john doe", + }, + } + + questions = [{"name": "some_user", "type": "user",}] + answers = {"some_user": "doesnt_exist.pouet"} + + with patch.object(user, "user_list", return_value={"users": users}): + with pytest.raises(YunohostError): + _parse_args_in_yunohost_format(answers, questions) + + +def test_parse_args_in_yunohost_format_user_two_users_no_default(): + username = "my_username.com" + other_user = "some_other_user.tld" + users = { + username: { + "ssh_allowed": False, + "username": "some_user", + "shell": "/bin/false", + "mailbox-quota": "0", + "mail": "p@ynh.local", + "fullname": "the first name the last name", + }, + other_user: { + "ssh_allowed": False, + "username": "some_user", + "shell": "/bin/false", + "mailbox-quota": "0", + "mail": "z@ynh.local", + "fullname": "john doe", + }, + } + + questions = [{"name": "some_user", "type": "user", "ask": "choose a user"}] + answers = {} + + with patch.object(user, "user_list", return_value={"users": users}): + with pytest.raises(YunohostError): + _parse_args_in_yunohost_format(answers, questions) + + +def test_parse_args_in_yunohost_format_user_two_users_default_input(): + username = "my_username.com" + other_user = "some_other_user.tld" + users = { + username: { + "ssh_allowed": False, + "username": "some_user", + "shell": "/bin/false", + "mailbox-quota": "0", + "mail": "p@ynh.local", + "fullname": "the first name the last name", + }, + other_user: { + "ssh_allowed": False, + "username": "some_user", + "shell": "/bin/false", + "mailbox-quota": "0", + "mail": "z@ynh.local", + "fullname": "john doe", + }, + } + + questions = [{"name": "some_user", "type": "user", "ask": "choose a user"}] + answers = {} + + with patch.object(user, "user_list", return_value={"users": users}): + expected_result = OrderedDict({"some_user": (username, "user")}) + with patch.object(msignals, "prompt", return_value=username): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + expected_result = OrderedDict({"some_user": (other_user, "user")}) + with patch.object(msignals, "prompt", return_value=other_user): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result From 61e539f4ea9ba8db031d0c861d5eeb795c032edd Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Mon, 25 May 2020 06:10:57 +0200 Subject: [PATCH 10/11] [mod] add tests for apps arguments parsing --- .../tests/test_apps_arguments_parsing.py | 199 +++++++++++++++++- 1 file changed, 198 insertions(+), 1 deletion(-) diff --git a/src/yunohost/tests/test_apps_arguments_parsing.py b/src/yunohost/tests/test_apps_arguments_parsing.py index 12ce9f693..491d7c512 100644 --- a/src/yunohost/tests/test_apps_arguments_parsing.py +++ b/src/yunohost/tests/test_apps_arguments_parsing.py @@ -4,7 +4,7 @@ from mock import patch from moulinette import msignals -from yunohost import domain, user +from yunohost import domain, user, app from yunohost.app import _parse_args_in_yunohost_format from yunohost.utils.error import YunohostError @@ -987,3 +987,200 @@ def test_parse_args_in_yunohost_format_user_two_users_default_input(): expected_result = OrderedDict({"some_user": (other_user, "user")}) with patch.object(msignals, "prompt", return_value=other_user): assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +def test_parse_args_in_yunohost_format_app_empty(): + apps = [ + { + "id": "my_webapp", + "version": "1.0~ynh2", + "description": "Custom Web app with SFTP access", + "name": "Custom Webapp", + } + ] + + questions = [{"name": "some_app", "type": "app",}] + answers = {} + + with patch.object(app, "app_list", return_value={"apps": apps}): + with pytest.raises(YunohostError): + _parse_args_in_yunohost_format(answers, questions) + + +def test_parse_args_in_yunohost_format_app_no_apps(): + apps = [] + questions = [{"name": "some_app", "type": "app",}] + answers = {} + + with patch.object(app, "app_list", return_value={"apps": apps}): + with pytest.raises(YunohostError): + _parse_args_in_yunohost_format(answers, questions) + + +@pytest.mark.skip # XXX should work +def test_parse_args_in_yunohost_format_app_no_apps_optional(): + apps = [] + questions = [{"name": "some_app", "type": "app", "optional": True}] + answers = {} + + with patch.object(app, "app_list", return_value={"apps": apps}): + assert _parse_args_in_yunohost_format(answers, questions) == [] + + +def test_parse_args_in_yunohost_format_app(): + app_name = "my_webapp" + apps = [ + { + "id": app_name, + "version": "1.0~ynh2", + "description": "Custom Web app with SFTP access", + "name": "Custom Webapp", + } + ] + + questions = [{"name": "some_app", "type": "app",}] + answers = {"some_app": app_name} + + expected_result = OrderedDict({"some_app": (app_name, "app")}) + + with patch.object(app, "app_list", return_value={"apps": apps}), patch.object( + app, + "_is_installed", + new_callable=lambda: lambda app_id: app_id in {x["id"] for x in apps}, + ): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +def test_parse_args_in_yunohost_format_app_two_apps(): + app_name = "my_webapp" + other_app = "some_other_app" + apps = [ + { + "id": app_name, + "version": "1.0~ynh2", + "description": "Custom Web app with SFTP access", + "name": "Custom Webapp", + }, + { + "id": other_app, + "version": "1.0", + "description": "blabla", + "name": "stuff", + }, + ] + + questions = [{"name": "some_app", "type": "app",}] + answers = {"some_app": other_app} + expected_result = OrderedDict({"some_app": (other_app, "app")}) + + with patch.object(app, "app_list", return_value={"apps": apps}), patch.object( + app, + "_is_installed", + new_callable=lambda: lambda app_id: app_id in {x["id"] for x in apps}, + ): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + answers = {"some_app": app_name} + expected_result = OrderedDict({"some_app": (app_name, "app")}) + + with patch.object(app, "app_list", return_value={"apps": apps}), patch.object( + app, + "_is_installed", + new_callable=lambda: lambda app_id: app_id in {x["id"] for x in apps}, + ): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +def test_parse_args_in_yunohost_format_app_two_apps_wrong_answer(): + app_name = "my_webapp" + other_app = "some_other_app" + apps = [ + { + "id": app_name, + "version": "1.0~ynh2", + "description": "Custom Web app with SFTP access", + "name": "Custom Webapp", + }, + { + "id": other_app, + "version": "1.0", + "description": "blabla", + "name": "stuff", + }, + ] + + questions = [{"name": "some_app", "type": "app",}] + answers = {"some_app": "doesnt_exist"} + + with pytest.raises(YunohostError): + with patch.object(app, "app_list", return_value={"apps": apps}), patch.object( + app, + "_is_installed", + new_callable=lambda: lambda app_id: app_id in {x["id"] for x in apps}, + ): + _parse_args_in_yunohost_format(answers, questions) + + +def test_parse_args_in_yunohost_format_app_two_apps_no_default(): + app_name = "my_app_name.com" + other_app = "some_other_app" + apps = [ + { + "id": app_name, + "version": "1.0~ynh2", + "description": "Custom Web app with SFTP access", + "name": "Custom Webapp", + }, + { + "id": other_app, + "version": "1.0", + "description": "blabla", + "name": "stuff", + }, + ] + + questions = [{"name": "some_app", "type": "app", "ask": "choose a app"}] + answers = {} + + with patch.object(app, "app_list", return_value={"apps": apps}), patch.object( + app, + "_is_installed", + new_callable=lambda: lambda app_id: app_id in {x["id"] for x in apps}, + ): + with pytest.raises(YunohostError): + _parse_args_in_yunohost_format(answers, questions) + + +def test_parse_args_in_yunohost_format_app_two_apps_default_input(): + app_name = "my_app_name.com" + other_app = "some_other_app" + apps = [ + { + "id": app_name, + "version": "1.0~ynh2", + "description": "Custom Web app with SFTP access", + "name": "Custom Webapp", + }, + { + "id": other_app, + "version": "1.0", + "description": "blabla", + "name": "stuff", + }, + ] + + questions = [{"name": "some_app", "type": "app", "ask": "choose a app"}] + answers = {} + + with patch.object(app, "app_list", return_value={"apps": apps}), patch.object( + app, + "_is_installed", + new_callable=lambda: lambda app_id: app_id in {x["id"] for x in apps}, + ): + expected_result = OrderedDict({"some_app": (app_name, "app")}) + with patch.object(msignals, "prompt", return_value=app_name): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + expected_result = OrderedDict({"some_app": (other_app, "app")}) + with patch.object(msignals, "prompt", return_value=other_app): + assert _parse_args_in_yunohost_format(answers, questions) == expected_result From 0aebd575f7215174bf9a11b80a99c0aeb38898bb Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Mon, 25 May 2020 06:33:19 +0200 Subject: [PATCH 11/11] [mod] add tests for display_text arguments parsing --- src/yunohost/tests/test_apps_arguments_parsing.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/yunohost/tests/test_apps_arguments_parsing.py b/src/yunohost/tests/test_apps_arguments_parsing.py index 491d7c512..a3d5b7f09 100644 --- a/src/yunohost/tests/test_apps_arguments_parsing.py +++ b/src/yunohost/tests/test_apps_arguments_parsing.py @@ -1,6 +1,9 @@ +import sys import pytest -from collections import OrderedDict + from mock import patch +from StringIO import StringIO +from collections import OrderedDict from moulinette import msignals @@ -1184,3 +1187,12 @@ def test_parse_args_in_yunohost_format_app_two_apps_default_input(): expected_result = OrderedDict({"some_app": (other_app, "app")}) with patch.object(msignals, "prompt", return_value=other_app): assert _parse_args_in_yunohost_format(answers, questions) == expected_result + + +def test_parse_args_in_yunohost_format_display_text(): + questions = [{"name": "some_app", "type": "display_text", "ask": "foobar"}] + answers = {} + + with patch.object(sys, "stdout", new_callable=StringIO) as stdout: + _parse_args_in_yunohost_format(answers, questions) + assert "foobar" in stdout.getvalue()