Skip to content

Commit

Permalink
Add PluginInstanceParameter
Browse files Browse the repository at this point in the history
  • Loading branch information
jennydaman committed Jul 28, 2024
1 parent e6b3acf commit ec4f845
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
30 changes: 29 additions & 1 deletion src/aiochris/models/logged_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *


Expand Down Expand Up @@ -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):
Expand All @@ -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":
"""
Expand Down
2 changes: 1 addition & 1 deletion src/aiochris/models/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
9 changes: 6 additions & 3 deletions src/aiochris/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ec4f845

Please sign in to comment.