From 8b1333a83747d52c1c7478319b6334d78f4e8071 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sat, 21 May 2022 14:23:08 +0200 Subject: [PATCH] manifestv2: iterate on notifications/doc + implement tests for it --- src/app.py | 10 +++--- src/app_catalog.py | 2 ++ src/tests/test_apps.py | 75 ++++++++++++++++++++++++++++++++++++++++++ src/utils/resources.py | 1 + 4 files changed, 83 insertions(+), 5 deletions(-) diff --git a/src/app.py b/src/app.py index 7d6efbc0d..0eb06d33b 100644 --- a/src/app.py +++ b/src/app.py @@ -760,8 +760,8 @@ def app_manifest(app): shutil.rmtree(extracted_app_folder) - raw_questions = manifest.get("arguments", {}).get("install", []) - manifest["arguments"]["install"] = hydrate_questions_with_choices(raw_questions) + raw_questions = manifest.get("install", {}).values() + manifest["install"] = hydrate_questions_with_choices(raw_questions) return manifest @@ -1978,18 +1978,18 @@ def _parse_app_doc_and_notifications(path): for pagename in glob.glob(os.path.join(path, "doc") + "/*.md"): name = os.path.basename(pagename)[:-len('.md')] - doc[name] = read_file(pagename) + doc[name] = read_file(pagename).strip() notifications = {} for step in ["pre_install", "post_install", "pre_upgrade", "post_upgrade"]: notifications[step] = {} 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: for notification in glob.glob(os.path.join(path, "doc", "notifications", f"{step}.d") + "/*.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 diff --git a/src/app_catalog.py b/src/app_catalog.py index 5244d4d81..d635f8ba4 100644 --- a/src/app_catalog.py +++ b/src/app_catalog.py @@ -232,6 +232,8 @@ def _load_apps_catalog(): ) 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 merged_catalog["apps"][app] = info diff --git a/src/tests/test_apps.py b/src/tests/test_apps.py index 76397093d..2c6deac7d 100644 --- a/src/tests/test_apps.py +++ b/src/tests/test_apps.py @@ -15,6 +15,8 @@ from yunohost.app import ( _is_installed, app_upgrade, app_map, + app_manifest, + app_info, ) from yunohost.domain import _get_maindomain, domain_add, domain_remove, domain_list 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") +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(): main_domain = _get_maindomain() @@ -228,6 +256,53 @@ def test_manifestv2_app_install_main_domain(): 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(): main_domain = _get_maindomain() diff --git a/src/utils/resources.py b/src/utils/resources.py index 5bde70e83..46f2eba33 100644 --- a/src/utils/resources.py +++ b/src/utils/resources.py @@ -69,6 +69,7 @@ class AppResourceManager: elif todo == "update": logger.info(f"Updating {name} ...") new.provision_or_update(context=context) + # FIXME FIXME FIXME : this exception doesnt catch Ctrl+C ?!?! except Exception as e: exception = e # FIXME: better error handling ? display stacktrace ?