Skip to content

Commit

Permalink
Merge branch 'plugin_api_v2' into plugin_api_v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghost-Miner authored Dec 19, 2024
2 parents 6b875ba + cea60bb commit ebe26fd
Show file tree
Hide file tree
Showing 5 changed files with 256 additions and 226 deletions.
23 changes: 16 additions & 7 deletions ci/src/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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]
24 changes: 22 additions & 2 deletions ci/src/validator.py
Original file line number Diff line number Diff line change
@@ -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()

Expand All @@ -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}"

Expand All @@ -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"
Loading

0 comments on commit ebe26fd

Please sign in to comment.