Skip to content

Commit 64379d1

Browse files
committed
fix-inject-state-hydration
Signed-off-by: Antonio Mendoza Pérez <antmendoza@gmail.com>
1 parent 4ef905b commit 64379d1

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
lines changed

serverlessworkflow/sdk/inject_state.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def __init__(self,
4444
def f_hydration(p_key, p_value):
4545

4646
if p_key == 'end':
47-
return HydratableParameter(value=p_value).hydrateAs(UnionTypeOf(SimpleTypeOf(bool),
48-
ComplexTypeOf(End)))
47+
return HydratableParameter(value=p_value).hydrateAs(UnionTypeOf([SimpleTypeOf(bool),
48+
ComplexTypeOf(End)]))
4949
if p_key == 'data':
5050
return HydratableParameter(value=p_value).hydrateAs(UnionTypeOf([SimpleTypeOf(str),
5151
ComplexTypeOf(dict)]))

tests/examples/helloworld.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"id": "helloworld",
3+
"version": "1.0",
4+
"specVersion": "0.8",
5+
"name": "Hello World Workflow",
6+
"description": "Inject Hello World",
7+
"start": "Hello State",
8+
"states": [
9+
{
10+
"name": "Hello State",
11+
"type": "inject",
12+
"data": {
13+
"result": "Hello World!"
14+
},
15+
"end": true
16+
}
17+
]
18+
}

tests/serverlessworkflow/sdk/test_workflow.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import json
12
import os
23
import unittest
4+
from os import listdir
35

46
from serverlessworkflow.sdk.action import Action
57
from serverlessworkflow.sdk.function import Function
@@ -8,7 +10,6 @@
810

911

1012
class TestWorkflow(unittest.TestCase):
11-
1213
workflow = Workflow(id_="greeting",
1314
name="Greeting Workflow",
1415
description="Greet Someone",
@@ -106,8 +107,26 @@ def test_workflow_to_yaml(self):
106107
self.assertEqual(expected, self.workflow.to_yaml())
107108

108109
def test_workflow_from_source_json(self):
109-
wf_file = os.path.join(os.path.dirname(__file__), 'test_workflow.json')
110-
self.assert_test_workflow_file(wf_file)
110+
examples_dir = os.path.join(os.path.dirname(__file__), '../../examples')
111+
examples = listdir(examples_dir)
112+
self.assertEqual(len(examples), 10)
113+
114+
for example in examples:
115+
with self.subTest(f"test_{example}"):
116+
with open(examples_dir + "/" + example, "r") as swf_file:
117+
workflow = Workflow.from_source(swf_file)
118+
self.assertTrue(isinstance(workflow, Workflow))
119+
120+
def test_instance_workflow_class(self):
121+
examples_dir = os.path.join(os.path.dirname(__file__), '../../examples')
122+
examples = listdir(examples_dir)
123+
self.assertEqual(len(examples), 10)
124+
125+
for example in examples:
126+
with self.subTest(f"test_{example}"):
127+
with open(examples_dir + "/" + example, "r") as swf_file:
128+
workflow = Workflow(**json.load(swf_file))
129+
self.assertTrue(isinstance(workflow, Workflow))
111130

112131
def test_workflow_from_source_yaml(self):
113132
wf_file = os.path.join(os.path.dirname(__file__), 'test_workflow.yaml')
@@ -125,4 +144,3 @@ def assert_test_workflow_file(self, wf_file):
125144
self.assertTrue(isinstance(workflow.states[0].actions[0], Action))
126145
self.assertTrue(isinstance(workflow.states[0].actions[0].functionRef, FunctionRef))
127146
self.assertTrue(isinstance(workflow.functions[0], Function))
128-

tests/serverlessworkflow/sdk/test_workflow_validator.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ class TestWorkflowValidator(unittest.TestCase):
1414
def test_validate_examples(self):
1515
examples_dir = os.path.join(os.path.dirname(__file__), '../../examples')
1616
examples = listdir(examples_dir)
17-
self.assertEqual(len(examples), 9)
17+
self.assertEqual(len(examples), 10)
1818

1919
for example in examples:
2020
with self.subTest(f"test_{example}"):
21-
2221
with open(examples_dir + "/" + example, "r") as swf_file:
2322
swf_file_content = json.load(swf_file)
2423
workflow = Workflow(**swf_file_content)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy