3
3
import unittest
4
4
from collections .abc import Sequence
5
5
6
- from cmem_plugin_base .dataintegration .context import ExecutionContext
6
+ from cmem_plugin_base .dataintegration .context import ExecutionContext , PluginContext
7
7
from cmem_plugin_base .dataintegration .description import Plugin , PluginAction
8
8
from cmem_plugin_base .dataintegration .entity import Entities
9
9
from cmem_plugin_base .dataintegration .plugins import TransformPlugin , WorkflowPlugin
@@ -71,8 +71,15 @@ def test__actions(self) -> None:
71
71
label = "My Workflow Plugin" ,
72
72
actions = [
73
73
PluginAction (
74
- name = "get_name" , label = "Get name" , description = "Returns the supplied name"
75
- )
74
+ name = "get_name" ,
75
+ label = "Get name" ,
76
+ description = "Returns the supplied name" ,
77
+ ),
78
+ PluginAction (
79
+ name = "get_project" ,
80
+ label = "Get project" ,
81
+ description = "Returns the current project." ,
82
+ ),
76
83
],
77
84
)
78
85
class MyWorkflowPlugin (WorkflowPlugin ):
@@ -87,19 +94,25 @@ def execute(self, inputs: Sequence[Entities], context: ExecutionContext) -> Enti
87
94
def get_name (self ) -> str :
88
95
return self .name
89
96
97
+ def get_project (self , context : PluginContext ) -> str :
98
+ return context .project_id
99
+
90
100
# Get plugin description
91
101
plugin = Plugin .plugins [0 ]
92
102
93
- # Check action
94
- assert len (plugin .actions ) == 1
103
+ # There should be two actions
104
+ assert len (plugin .actions ) == 2
105
+
106
+ # Check first action
95
107
action = plugin .actions [0 ]
96
108
assert action .name == "get_name"
97
109
assert action .label == "Get name"
98
110
assert action .description == "Returns the supplied name"
99
111
100
- # Call action on a plugin instance
112
+ # Call actions on a plugin instance
101
113
plugin_instance = MyWorkflowPlugin ("My Name" )
102
- action .execute (plugin_instance , TestPluginContext ())
114
+ assert action .execute (plugin_instance , TestPluginContext ()) == "My Name"
115
+ assert action .execute (plugin_instance , TestPluginContext (project_id = "movies" )) == "movies"
103
116
104
117
105
118
if __name__ == "__main__" :
0 commit comments