mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[mod] add tests for apps arguments parsing
This commit is contained in:
parent
a8f8ee5e6c
commit
61e539f4ea
1 changed files with 198 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue