From 932bfb8f97013315537aae0a38f99019513d2bf0 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Tue, 17 Dec 2024 21:48:57 +1100 Subject: [PATCH 1/5] fix function typo and name --- ci/src/_utils.py | 6 +++--- ci/src/validator.py | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ci/src/_utils.py b/ci/src/_utils.py index bcd6ae527..27b449e3f 100644 --- a/ci/src/_utils.py +++ b/ci/src/_utils.py @@ -41,7 +41,7 @@ def plugin_reader() -> P: - plugin_files = get_plugin_files() + plugin_files = get_plugin_file_paths() manifests = [] @@ -52,11 +52,11 @@ def plugin_reader() -> P: return manifests -def get_plugin_files() -> list[str]: +def get_plugin_file_paths() -> list[str]: return [os.path.join(plugin_dir, filename) for filename in get_plugin_filenames()] def get_plugin_filenames() -> list[str]: - return [file for file in os.listdir(plugin_dir)] + return os.listdir(plugin_dir) def etag_reader() -> ETagsType: with open(etag_file, "r", encoding="utf-8") as f: diff --git a/ci/src/validator.py b/ci/src/validator.py index 985414b6e..6391efb4c 100644 --- a/ci/src/validator.py +++ b/ci/src/validator.py @@ -1,5 +1,9 @@ # -*-coding: utf-8 -*- -from _utils import clean, id_name, language_list, language_name, plugin_reader, check_url, icon_path, get_plugin_files, get_plugin_filenames +import re +import uuid + +from _utils import (check_url, clean, get_file_plugins_json_info, get_plugin_file_paths, get_plugin_filenames, + icon_path, id_name, language_list, language_name, plugin_reader) plugin_infos = plugin_reader() @@ -25,7 +29,7 @@ def test_valid_icon_url(): assert check_url(plugin[icon_path]), msg def test_file_type_json(): - incorrect_ext_files = [file for file in get_plugin_files() if not file.endswith(".json")] + incorrect_ext_files = [file_path for file_path in get_plugin_file_paths() if not file_path.endswith(".json")] assert len(incorrect_ext_files) == 0, f"Expected the following file to be of .json extension: {incorrect_ext_files}" From 4c758644eeb06618e3950043088aefdb320f62de Mon Sep 17 00:00:00 2001 From: Jeremy Date: Tue, 17 Dec 2024 21:49:28 +1100 Subject: [PATCH 2/5] add test valid ID for plugin submissions --- ci/src/_utils.py | 10 ++++++++++ ci/src/validator.py | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/ci/src/_utils.py b/ci/src/_utils.py index 27b449e3f..951d17ba4 100644 --- a/ci/src/_utils.py +++ b/ci/src/_utils.py @@ -91,3 +91,13 @@ def check_url(url: str) -> bool: re.IGNORECASE, ) return re.match(regex, url) is not None + + +def get_file_plugins_json_info(required_key: str = "") -> list[dict[str, str]]: + with open("plugins.json", "r", encoding="utf-8") as f: + data = json.load(f) + + if not required_key: + return data + + return [{required_key: plugin[required_key]} for plugin in data] diff --git a/ci/src/validator.py b/ci/src/validator.py index 6391efb4c..3e1c4695b 100644 --- a/ci/src/validator.py +++ b/ci/src/validator.py @@ -39,3 +39,19 @@ def test_file_name_construct(): assert ( f"{info['Name']}-{info['ID']}.json" in filenames ), f"Plugin {info['Name']} with ID {info['ID']} does not have the correct filename. Make sure it's name + ID, i.e. {info['Name']}-{info['ID']}.json" + +def test_submitted_plugin_id_is_valid_uuid(): + plugins_json_ids = [item["ID"] for item in get_file_plugins_json_info("ID")] + existing_plugin_file_ids = [info["ID"] for info in plugin_infos] + + for id in existing_plugin_file_ids: + if id in plugins_json_ids: + continue + + try: + uuid.UUID(id, version=4) + outcome = True + except ValueError: + outcome = False + + assert outcome is True, f"The submission plugin ID {id} is not a valid v4 UUID" From ecc7ba955443a4d5e8710905353aabf2145b305d Mon Sep 17 00:00:00 2001 From: Jeremy Date: Tue, 17 Dec 2024 21:59:39 +1100 Subject: [PATCH 3/5] fix naming --- ci/src/_utils.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ci/src/_utils.py b/ci/src/_utils.py index 951d17ba4..b29ec75af 100644 --- a/ci/src/_utils.py +++ b/ci/src/_utils.py @@ -41,14 +41,13 @@ def plugin_reader() -> P: - plugin_files = get_plugin_file_paths() + plugin_file_paths = get_plugin_file_paths() manifests = [] - for plugin in plugin_files: - with open(plugin, "r", encoding="utf-8") as f: - manifest = json.load(f) - manifests.append(manifest) + for plugin_path in plugin_file_paths: + with open(plugin_path, "r", encoding="utf-8") as f: + manifests.append(json.load(f)) return manifests From 6ebf86d5cbf5f3a32bd3c2b05a5550ba420c2b9f Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Wed, 18 Dec 2024 17:55:23 +1100 Subject: [PATCH 4/5] remove unused import --- ci/src/validator.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ci/src/validator.py b/ci/src/validator.py index 3e1c4695b..3943db7b1 100644 --- a/ci/src/validator.py +++ b/ci/src/validator.py @@ -1,5 +1,4 @@ # -*-coding: utf-8 -*- -import re import uuid from _utils import (check_url, clean, get_file_plugins_json_info, get_plugin_file_paths, get_plugin_filenames, From 5eddc407dc4125226b8b7e765b0a39b2e1f0084d Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Wed, 18 Dec 2024 17:57:49 +1100 Subject: [PATCH 5/5] add comment --- ci/src/validator.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/src/validator.py b/ci/src/validator.py index 3943db7b1..6040a8a64 100644 --- a/ci/src/validator.py +++ b/ci/src/validator.py @@ -44,6 +44,7 @@ def test_submitted_plugin_id_is_valid_uuid(): existing_plugin_file_ids = [info["ID"] for info in plugin_infos] for id in existing_plugin_file_ids: + # plugins.json would not contain new submission's ID. if id in plugins_json_ids: continue