Skip to content

Commit

Permalink
Merge pull request #117 from batk0/master
Browse files Browse the repository at this point in the history
Fix for variables containing 'in'
  • Loading branch information
m4dcoder authored Jan 29, 2019
2 parents 60a5e35 + f03f3f2 commit 5da6295
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
8 changes: 4 additions & 4 deletions orquesta/specs/native/v1/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ def render(self, in_ctx):
items_spec = self.get_items_spec()

items_expr = (
items_spec.items.strip() if 'in' not in items_spec.items
else items_spec.items[items_spec.items.index('in') + 2:].strip()
items_spec.items.strip() if ' in ' not in items_spec.items
else items_spec.items[items_spec.items.index(' in ') + 4:].strip()
)

items = expr.evaluate(items_expr, in_ctx)
Expand All @@ -193,8 +193,8 @@ def render(self, in_ctx):
raise TypeError('The value of "%s" is not type of list.' % items_expr)

item_keys = (
None if 'in' not in items_spec.items
else items_spec.items[:items_spec.items.index('in')].replace(' ', '').split(',')
None if ' in ' not in items_spec.items
else items_spec.items[:items_spec.items.index(' in ')].replace(' ', '').split(',')
)

for idx, item in enumerate(items):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,53 @@ def test_basic_list_rendering(self):
actual_tasks = conductor.get_next_tasks()
self.assert_task_list(actual_tasks, expected_tasks)

def test_basic_list_rendering_var_w_in(self):
wf_def = """
version: 1.0
vars:
- domains:
- fee
- fi
- fo
- fum
tasks:
task1:
with: <% ctx(domains) %>
action: core.echo message=<% item() %>
"""

spec = specs.WorkflowSpec(wf_def)
self.assertDictEqual(spec.inspect(), {})

conductor = conducting.WorkflowConductor(spec)
conductor.request_workflow_state(states.RUNNING)

next_task_name = 'task1'
next_task_ctx = {'domains': ['fee', 'fi', 'fo', 'fum']}
next_task_spec = conductor.spec.tasks.get_task(next_task_name)

next_task_action_specs = [
{'action': 'core.echo', 'input': {'message': 'fee'}, 'item_id': 0},
{'action': 'core.echo', 'input': {'message': 'fi'}, 'item_id': 1},
{'action': 'core.echo', 'input': {'message': 'fo'}, 'item_id': 2},
{'action': 'core.echo', 'input': {'message': 'fum'}, 'item_id': 3},
]

expected_task = self.format_task_item(
next_task_name,
next_task_ctx,
next_task_spec,
action_specs=next_task_action_specs,
items_count=len(next_task_ctx['domains']),
items_concurrency=None
)

expected_tasks = [expected_task]
actual_tasks = conductor.get_next_tasks()
self.assert_task_list(actual_tasks, expected_tasks)

def test_multiple_lists_rendering(self):
wf_def = """
version: 1.0
Expand Down

0 comments on commit 5da6295

Please sign in to comment.