manifestv2: iterate on notifications/doc + implement tests for it

This commit is contained in:
Alexandre Aubin 2022-05-21 14:23:08 +02:00
parent 9902d191aa
commit 8b1333a837
4 changed files with 83 additions and 5 deletions

View file

@ -760,8 +760,8 @@ def app_manifest(app):
shutil.rmtree(extracted_app_folder) shutil.rmtree(extracted_app_folder)
raw_questions = manifest.get("arguments", {}).get("install", []) raw_questions = manifest.get("install", {}).values()
manifest["arguments"]["install"] = hydrate_questions_with_choices(raw_questions) manifest["install"] = hydrate_questions_with_choices(raw_questions)
return manifest return manifest
@ -1978,18 +1978,18 @@ def _parse_app_doc_and_notifications(path):
for pagename in glob.glob(os.path.join(path, "doc") + "/*.md"): for pagename in glob.glob(os.path.join(path, "doc") + "/*.md"):
name = os.path.basename(pagename)[:-len('.md')] name = os.path.basename(pagename)[:-len('.md')]
doc[name] = read_file(pagename) doc[name] = read_file(pagename).strip()
notifications = {} notifications = {}
for step in ["pre_install", "post_install", "pre_upgrade", "post_upgrade"]: for step in ["pre_install", "post_install", "pre_upgrade", "post_upgrade"]:
notifications[step] = {} notifications[step] = {}
if os.path.exists(os.path.join(path, "doc", "notifications", f"{step}.md")): if os.path.exists(os.path.join(path, "doc", "notifications", f"{step}.md")):
notifications[step]["main"] = read_file(os.path.join(path, "doc", "notifications", f"{step}.md")) notifications[step]["main"] = read_file(os.path.join(path, "doc", "notifications", f"{step}.md")).strip()
else: else:
for notification in glob.glob(os.path.join(path, "doc", "notifications", f"{step}.d") + "/*.md"): for notification in glob.glob(os.path.join(path, "doc", "notifications", f"{step}.d") + "/*.md"):
name = os.path.basename(notification)[:-len('.md')] name = os.path.basename(notification)[:-len('.md')]
notifications[step][name].append(read_file(notification)) notifications[step][name].append(read_file(notification).strip())
return doc, notifications return doc, notifications

View file

@ -232,6 +232,8 @@ def _load_apps_catalog():
) )
continue continue
# FIXME: we may want to autoconvert all v0/v1 manifest to v2 here
# so that everything is consistent in terms of APIs, datastructure format etc
info["repository"] = apps_catalog_id info["repository"] = apps_catalog_id
merged_catalog["apps"][app] = info merged_catalog["apps"][app] = info

View file

@ -15,6 +15,8 @@ from yunohost.app import (
_is_installed, _is_installed,
app_upgrade, app_upgrade,
app_map, app_map,
app_manifest,
app_info,
) )
from yunohost.domain import _get_maindomain, domain_add, domain_remove, domain_list from yunohost.domain import _get_maindomain, domain_add, domain_remove, domain_list
from yunohost.utils.error import YunohostError from yunohost.utils.error import YunohostError
@ -208,6 +210,32 @@ def test_legacy_app_install_main_domain():
assert app_is_not_installed(main_domain, "legacy_app") assert app_is_not_installed(main_domain, "legacy_app")
def test_legacy_app_manifest_preinstall():
m = app_manifest(os.path.join(get_test_apps_dir(), "legacy_app_ynh"))
# v1 manifesto are expected to have been autoconverted to v2
assert "id" in m
assert "description" in m
assert "integration" in m
assert "install" in m
assert "doc" in m and not m["doc"]
assert "notifications" in m and not m["notifications"]
def test_manifestv2_app_manifest_preinstall():
m = app_manifest(os.path.join(get_test_apps_dir(), "manifestv2_app_ynh"))
assert "id" in m
assert "install" in m
assert "description" in m
assert "doc" in m
assert "This is a dummy description of this app features" in m["doc"]["DESCRIPTION"]
assert "notifications" in m
assert "This is a dummy disclaimer to display prior to the install" in m["notifications"]["pre_install"]
def test_manifestv2_app_install_main_domain(): def test_manifestv2_app_install_main_domain():
main_domain = _get_maindomain() main_domain = _get_maindomain()
@ -228,6 +256,53 @@ def test_manifestv2_app_install_main_domain():
assert app_is_not_installed(main_domain, "manifestv2_app") assert app_is_not_installed(main_domain, "manifestv2_app")
def test_manifestv2_app_info_postinstall():
main_domain = _get_maindomain()
install_manifestv2_app(main_domain, "/manifestv2")
m = app_info("manifestv2_app", full=True)["manifest"]
assert "id" in m
assert "install" in m
assert "description" in m
assert "doc" in m
assert "The app install dir is /var/www/manifestv2_app" in m["doc"]["ADMIN"]
assert "notifications" in m
assert "The app install dir is /var/www/manifestv2_app" in m["notifications"]["post_install"]
assert "The app id is manifestv2_app" in m["notifications"]["post_install"]
assert f"The app url is {main_domain}/manifestv2" in m["notifications"]["post_install"]
def test_manifestv2_app_info_preupgrade(monkeypatch):
from yunohost.app_catalog import _load_apps_catalog as original_load_apps_catalog
def custom_load_apps_catalog(*args, **kwargs):
res = original_load_apps_catalog(*args, **kwargs)
res["apps"]["manifestv2_app"] = {
"id": "manifestv2_app",
"level": 10,
"lastUpdate": 999999999,
"maintained": True,
"manifest": app_manifest(os.path.join(get_test_apps_dir(), "manifestv2_app_ynh")),
}
res["apps"]["manifestv2_app"]["manifest"]["version"] = "99999~ynh1"
return res
monkeypatch.setattr("yunohost.app._load_apps_catalog", custom_load_apps_catalog)
main_domain = _get_maindomain()
install_manifestv2_app(main_domain, "/manifestv2")
i = app_info("manifestv2_app", full=True)
assert i["upgradable"] == "yes"
assert i["new_version"] == "99999~ynh1"
# FIXME : as I write this test, I realize that this implies the catalog API
# does provide the notifications, which means the list builder script
# should parse the files in the original app repo, possibly with proper i18n etc
assert "This is a dummy disclaimer to display prior to any upgrade" \
in i["from_catalog"]["manifest"]["notifications"]["pre_upgrade"]
def test_app_from_catalog(): def test_app_from_catalog():
main_domain = _get_maindomain() main_domain = _get_maindomain()

View file

@ -69,6 +69,7 @@ class AppResourceManager:
elif todo == "update": elif todo == "update":
logger.info(f"Updating {name} ...") logger.info(f"Updating {name} ...")
new.provision_or_update(context=context) new.provision_or_update(context=context)
# FIXME FIXME FIXME : this exception doesnt catch Ctrl+C ?!?!
except Exception as e: except Exception as e:
exception = e exception = e
# FIXME: better error handling ? display stacktrace ? # FIXME: better error handling ? display stacktrace ?