forked from serverlessworkflow/sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_workflow_validator.py
More file actions
38 lines (28 loc) · 1.42 KB
/
test_workflow_validator.py
File metadata and controls
38 lines (28 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
import unittest
from os import listdir
from jsonschema.exceptions import ValidationError
from serverlessworkflow.sdk.workflow import Workflow
from serverlessworkflow.sdk.workflow_validator import WorkflowValidator
class TestWorkflowValidator(unittest.TestCase):
def test_validate_examples(self):
examples_dir = os.path.join(os.path.dirname(__file__), '../../examples')
examples = listdir(examples_dir)
self.assertEqual(len(examples), 13)
for example in examples:
with self.subTest(f"test_{example}"):
with open(examples_dir + "/" + example, "r") as swf_file:
workflow = Workflow.from_source(swf_file.read())
WorkflowValidator(workflow).validate()
def test_valid_wf(self):
wf_file = os.path.join(os.path.dirname(__file__), '../../examples', 'applicantrequest.json')
with open(wf_file, "r") as swf_file:
workflow = Workflow.from_source(swf_file.read())
WorkflowValidator(workflow).validate()
def test_invalid_wf(self):
wf_file = os.path.join(os.path.dirname(__file__), '../../examples', 'applicantrequest.json')
with open(wf_file, "r") as swf_file:
workflow = Workflow.from_source(swf_file.read())
workflow.specVersion = None
with self.assertRaises(ValidationError):
WorkflowValidator(Workflow(workflow)).validate()