From ec4f845bd963ef301c61447eaf5b1809d65ee457 Mon Sep 17 00:00:00 2001 From: Jennings Zhang Date: Sun, 28 Jul 2024 18:33:50 -0400 Subject: [PATCH] Add PluginInstanceParameter --- src/aiochris/models/logged_in.py | 30 +++++++++++++++++++++++++++++- src/aiochris/models/public.py | 2 +- src/aiochris/types.py | 9 ++++++--- tests/test_client.py | 10 ++++++++++ 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/aiochris/models/logged_in.py b/src/aiochris/models/logged_in.py index 8ccd456..2973e2e 100644 --- a/src/aiochris/models/logged_in.py +++ b/src/aiochris/models/logged_in.py @@ -16,7 +16,8 @@ from aiochris.link import http from aiochris.link.linked import LinkedModel from aiochris.models.data import PluginInstanceData, FeedData, UserData, FeedNoteData -from aiochris.models.public import PublicPlugin +from aiochris.models.public import PublicPlugin, PluginParameter +from aiochris.util.search import Search from aiochris.types import * @@ -86,6 +87,28 @@ class PACSFile(File): pacs_identifier: str +@serde +@dataclass(frozen=True) +class PluginInstanceParameter(LinkedModel): + url: PluginInstanceParameterUrl + id: PluginInstanceParameterId + param_name: ParameterName + value: ParameterValue + type: ParameterType + plugin_inst: PluginInstanceUrl + plugin_param: PluginParameterUrl + + @http.get("plugin_inst") + async def get_plugin_instance(self) -> "PluginInstance": + """Get the plugin instance of this parameter instance.""" + ... + + @http.get("plugin_param") + async def get_plugin_parameter(self) -> PluginParameter: + """Get the plugin parameter of this plugin instance parameter.""" + ... + + @serde @dataclass(frozen=True) class PluginInstance(PluginInstanceData): @@ -94,6 +117,11 @@ async def get_feed(self) -> "Feed": """Get the feed this plugin instance belongs to.""" ... + @http.search("parameters", subpath="") + def get_parameters(self) -> Search[PluginInstanceParameter]: + """Get the parameters of this plugin instance.""" + ... + @http.put("url") async def get(self) -> "PluginInstance": """ diff --git a/src/aiochris/models/public.py b/src/aiochris/models/public.py index 29335c9..f895f20 100644 --- a/src/aiochris/models/public.py +++ b/src/aiochris/models/public.py @@ -41,7 +41,7 @@ class PluginParameter(LinkedModel): name: ParameterName type: ParameterType optional: bool - default: Optional[ParameterType] + default: Optional[ParameterValue] flag: str short_flag: str action: Literal["store", "store_true", "store_false"] diff --git a/src/aiochris/types.py b/src/aiochris/types.py index a4d105a..f290c05 100644 --- a/src/aiochris/types.py +++ b/src/aiochris/types.py @@ -2,7 +2,7 @@ NewTypes for _ChRIS_ models. """ -from typing import NewType, Union +from typing import NewType, Union, Literal Username = NewType("Username", str) """ChRIS user account username""" @@ -58,9 +58,12 @@ PipingId = NewType("PipingId", int) PipelineId = NewType("PipelineId", int) - ParameterName = NewType("ParameterName", str) -ParameterType = Union[str, int, float, bool] +ParameterValue = Union[str, int, float, bool] +ParameterType = Literal["boolean", "integer", "float", "string", "path", "unextpath"] + +PluginInstanceParameterUrl = NewType("PluginInstanceParameterUrl", str) +PluginInstanceParameterId = NewType("PluginInstanceParameterId", int) PipelineParameterId = NewType("ParameterLocalId", int) PluginParameterId = NewType("ParameterGlobalId", int) diff --git a/tests/test_client.py b/tests/test_client.py index 2665257..91fe419 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -242,6 +242,16 @@ async def test_plugin_instances( found_plinst = await normal_client.plugin_instances(id=changed_inst.id).get_only() assert found_plinst.title == changed_inst.title + params = await acollect(dircopy_instance.get_parameters()) + dir_param_inst = next(filter(lambda p: p.param_name == "dir", params), None) + assert dir_param_inst is not None + assert dir_param_inst.type == "unextpath" + dir_param = await dir_param_inst.get_plugin_parameter() + assert dir_param.url == dir_param_inst.plugin_param + assert dir_param.action == "store" + assert not dir_param.optional + assert dir_param.default is None + async def test_delete( normal_client: ChrisClient, dircopy_instance: PluginInstance, simpledsapp: Plugin