diff --git a/ci/src/_utils.py b/ci/src/_utils.py index bcd6ae527..b29ec75af 100644 --- a/ci/src/_utils.py +++ b/ci/src/_utils.py @@ -41,22 +41,21 @@ def plugin_reader() -> P: - plugin_files = get_plugin_files() + 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 -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: @@ -91,3 +90,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 985414b6e..6040a8a64 100644 --- a/ci/src/validator.py +++ b/ci/src/validator.py @@ -1,5 +1,8 @@ # -*-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 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 +28,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}" @@ -35,3 +38,20 @@ 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: + # plugins.json would not contain new submission's ID. + 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"