|  | 
| 4 | 4 | from os import listdir | 
| 5 | 5 | 
 | 
| 6 | 6 | from serverlessworkflow.sdk.action import Action | 
|  | 7 | +from serverlessworkflow.sdk.action_data_filter import ActionDataFilter | 
| 7 | 8 | from serverlessworkflow.sdk.function import Function | 
| 8 | 9 | from serverlessworkflow.sdk.function_ref import FunctionRef | 
|  | 10 | +from serverlessworkflow.sdk.operation_state import OperationState | 
| 9 | 11 | from serverlessworkflow.sdk.workflow import Workflow | 
| 10 | 12 | 
 | 
| 11 | 13 | 
 | 
| 12 | 14 | class TestWorkflow(unittest.TestCase): | 
| 13 |  | -    workflow = Workflow(id_="greeting", | 
| 14 |  | -                        name="Greeting Workflow", | 
| 15 |  | -                        description="Greet Someone", | 
| 16 |  | -                        version='1.0', | 
| 17 |  | -                        specVersion='0.8', | 
| 18 |  | -                        start="Greet", | 
| 19 |  | -                        states=[ | 
| 20 |  | -                            { | 
| 21 |  | -                                "name": "Greet", | 
| 22 |  | -                                "type": "operation", | 
| 23 |  | -                                "actions": [ | 
| 24 |  | -                                    { | 
| 25 |  | -                                        "functionRef": { | 
| 26 |  | -                                            "refName": "greetingFunction", | 
| 27 |  | -                                            "arguments": { | 
| 28 |  | -                                                "name": "${ .person.name }" | 
| 29 |  | -                                            } | 
| 30 |  | -                                        }, | 
| 31 |  | -                                        "actionDataFilter": { | 
| 32 |  | -                                            "results": "${ .greeting }" | 
| 33 |  | -                                        } | 
| 34 |  | -                                    } | 
| 35 |  | -                                ], | 
| 36 |  | -                                "end": True | 
|  | 15 | +    workflow = Workflow( | 
|  | 16 | +        id_="greeting", | 
|  | 17 | +        name="Greeting Workflow", | 
|  | 18 | +        description="Greet Someone", | 
|  | 19 | +        version='1.0', | 
|  | 20 | +        specVersion='0.8', | 
|  | 21 | +        start="Greet", | 
|  | 22 | +        states=[ | 
|  | 23 | +            OperationState( | 
|  | 24 | +                name="Greet", | 
|  | 25 | +                type="operation", | 
|  | 26 | +                actions=[ | 
|  | 27 | +                    Action( | 
|  | 28 | +                        functionRef=FunctionRef( | 
|  | 29 | +                            refName="greetingFunction", | 
|  | 30 | +                            arguments={ | 
|  | 31 | +                                "name": "${ .person.name }" | 
| 37 | 32 |                             } | 
| 38 |  | -                        ], | 
| 39 |  | -                        functions=[ | 
| 40 |  | -                            { | 
| 41 |  | -                                "name": "greetingFunction", | 
| 42 |  | -                                "operation": "file://myapis/greetingapis.json#greeting" | 
| 43 |  | -                            } | 
| 44 |  | -                        ] | 
|  | 33 | +                        ), | 
|  | 34 | +                        actionDataFilter=ActionDataFilter( | 
|  | 35 | +                            results="${ .greeting }" | 
| 45 | 36 |                         ) | 
|  | 37 | +                    ) | 
|  | 38 | +                ], | 
|  | 39 | +                end=True | 
|  | 40 | +            ) | 
|  | 41 | +        ], | 
|  | 42 | +        functions=[ | 
|  | 43 | +            Function(name="greetingFunction", | 
|  | 44 | +                     operation="file://myapis/greetingapis.json#greeting") | 
|  | 45 | +        ] | 
|  | 46 | +    ) | 
| 46 | 47 | 
 | 
| 47 | 48 |     def test_workflow_to_json(self): | 
| 48 | 49 |         expected = """{ | 
| @@ -106,6 +107,16 @@ def test_workflow_to_yaml(self): | 
| 106 | 107 | """ | 
| 107 | 108 |         self.assertEqual(expected, self.workflow.to_yaml()) | 
| 108 | 109 | 
 | 
|  | 110 | +    def test_programmatically_create_workflow(self): | 
|  | 111 | + | 
|  | 112 | +        self.assertEqual("greeting", self.workflow.id) | 
|  | 113 | +        self.assertEqual("operation", self.workflow.states[0].type) | 
|  | 114 | +        self.assertTrue(isinstance(self.workflow.states[0], OperationState)) | 
|  | 115 | +        self.assertEqual(True, self.workflow.states[0].end) | 
|  | 116 | +        self.assertTrue(isinstance(self.workflow.states[0].actions[0], Action)) | 
|  | 117 | +        self.assertTrue(isinstance(self.workflow.states[0].actions[0].functionRef, FunctionRef)) | 
|  | 118 | +        self.assertTrue(isinstance(self.workflow.functions[0], Function)) | 
|  | 119 | + | 
| 109 | 120 |     def test_workflow_from_source_json(self): | 
| 110 | 121 |         examples_dir = os.path.join(os.path.dirname(__file__), '../../examples') | 
| 111 | 122 |         examples = listdir(examples_dir) | 
|  | 
0 commit comments