From 3a23f9715f5b927be54c4756bbb16c0a0116ee2b Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 8 Oct 2020 20:04:50 +0200 Subject: [PATCH] We don't need app-type argument for manifest questions --- src/yunohost/app.py | 17 -- .../tests/test_apps_arguments_parsing.py | 197 ------------------ 2 files changed, 214 deletions(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 7d5d36c4d..5c2a7de8a 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -2631,22 +2631,6 @@ class UserArgumentParser(YunoHostArgumentFormatParser): error=m18n.n('user_unknown', user=question.value)) -class AppArgumentParser(YunoHostArgumentFormatParser): - argument_type = "app" - - def parse_question(self, question, user_answers): - from yunohost.app import app_list - - question = super(AppArgumentParser, self).parse_question(question, user_answers) - question.choices = [x["id"] for x in app_list()["apps"]] - - return question - - def _raise_invalid_answer(self, question): - raise YunohostError('app_argument_invalid', name=question.name, - error=m18n.n('app_unknown')) - - class DisplayTextArgumentParser(YunoHostArgumentFormatParser): argument_type = "display_text" @@ -2661,7 +2645,6 @@ ARGUMENTS_TYPE_PARSERS = { "boolean": BooleanArgumentParser, "domain": DomainArgumentParser, "user": UserArgumentParser, - "app": AppArgumentParser, "display_text": DisplayTextArgumentParser, } diff --git a/src/yunohost/tests/test_apps_arguments_parsing.py b/src/yunohost/tests/test_apps_arguments_parsing.py index dede7a0f9..ad1eeab65 100644 --- a/src/yunohost/tests/test_apps_arguments_parsing.py +++ b/src/yunohost/tests/test_apps_arguments_parsing.py @@ -1021,203 +1021,6 @@ def test_parse_args_in_yunohost_format_user_two_users_default_input(): 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) - - -def test_parse_args_in_yunohost_format_app_no_apps_optional(): - apps = [] - questions = [{"name": "some_app", "type": "app", "optional": True}] - answers = {} - expected_result = OrderedDict({"some_app": (None, "app")}) - - with patch.object(app, "app_list", return_value={"apps": apps}): - assert _parse_args_in_yunohost_format(answers, questions) == expected_result - - -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 - - def test_parse_args_in_yunohost_format_display_text(): questions = [{"name": "some_app", "type": "display_text", "ask": "foobar"}] answers = {}