Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from StackStorm/fix-app-ctx
Fix vars and input that references app context
- Loading branch information
Showing
4 changed files
with
132 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
orquesta/tests/unit/conducting/test_workflow_conductor_context.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from orquesta import conducting | ||
from orquesta import events | ||
from orquesta.specs import native as specs | ||
from orquesta import states | ||
from orquesta.tests.unit import base | ||
|
||
|
||
class WorkflowConductorContextTest(base.WorkflowConductorTest): | ||
|
||
def test_bad_app_ctx_references(self): | ||
wf_def = """ | ||
version: 1.0 | ||
input: | ||
- a: <% ctx().x %> | ||
vars: | ||
- b: <% ctx().y %> | ||
output: | ||
- x: <% ctx().a %> | ||
- y: <% ctx().b %> | ||
- z: <% ctx().z %> | ||
tasks: | ||
task1: | ||
action: core.noop | ||
""" | ||
|
||
expected_errors = [ | ||
{ | ||
'type': 'error', | ||
'message': ( | ||
'YaqlEvaluationException: Unable to resolve key \'x\' in ' | ||
'expression \'<% ctx().x %>\' from context.' | ||
) | ||
}, | ||
{ | ||
'type': 'error', | ||
'message': ( | ||
'YaqlEvaluationException: Unable to resolve key \'y\' in ' | ||
'expression \'<% ctx().y %>\' from context.' | ||
) | ||
} | ||
] | ||
|
||
spec = specs.WorkflowSpec(wf_def) | ||
|
||
# Run the workflow. | ||
conductor = conducting.WorkflowConductor(spec) | ||
conductor.request_workflow_state(states.RUNNING) | ||
|
||
# Check workflow status and result. | ||
self.assertEqual(conductor.get_workflow_state(), states.FAILED) | ||
self.assertListEqual(conductor.errors, expected_errors) | ||
self.assertIsNone(conductor.get_workflow_output()) | ||
|
||
def test_app_ctx_references(self): | ||
app_ctx = { | ||
'x': 'foobar', | ||
'y': 'fubar', | ||
'z': 'phobar' | ||
} | ||
|
||
wf_def = """ | ||
version: 1.0 | ||
input: | ||
- a: <% ctx().x %> | ||
vars: | ||
- b: <% ctx().y %> | ||
output: | ||
- x: <% ctx().a %> | ||
- y: <% ctx().b %> | ||
- z: <% ctx().z %> | ||
tasks: | ||
task1: | ||
action: core.noop | ||
""" | ||
|
||
expected_output = app_ctx | ||
expected_errors = [] | ||
|
||
spec = specs.WorkflowSpec(wf_def) | ||
self.assertDictEqual(spec.inspect(app_ctx=app_ctx), {}) | ||
|
||
# Run the workflow. | ||
conductor = conducting.WorkflowConductor(spec, context=app_ctx) | ||
conductor.request_workflow_state(states.RUNNING) | ||
self.assertEqual(conductor.get_workflow_state(), states.RUNNING) | ||
self.assertListEqual(conductor.errors, expected_errors) | ||
|
||
# Complete tasks | ||
task_name = 'task1' | ||
conductor.update_task_flow(task_name, events.ActionExecutionEvent(states.RUNNING)) | ||
conductor.update_task_flow(task_name, events.ActionExecutionEvent(states.SUCCEEDED)) | ||
|
||
# Check workflow status and output. | ||
self.assertEqual(conductor.get_workflow_state(), states.SUCCEEDED) | ||
self.assertListEqual(conductor.errors, expected_errors) | ||
self.assertDictEqual(conductor.get_workflow_output(), expected_output) |