Skip to content
This repository has been archived by the owner on Jun 12, 2020. It is now read-only.

Commit

Permalink
Merge 448a1ee into 349ca33
Browse files Browse the repository at this point in the history
  • Loading branch information
SvenWiltink authored and SvenWiltink committed Jan 7, 2016
2 parents 349ca33 + 448a1ee commit 97a11dc
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/CodeFlow/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def loadFromJson(json):
instance = Workflow()
instance.name = name
instance.states = states
instance.variables = {}

return instance

Expand Down Expand Up @@ -76,13 +77,17 @@ def handleState(self, state):
varNames = trigger['variableName']
varNames = varNames.split(';')

value = self.variables[varNames.pop(0)]
value = self.variables
ignoreValue = False

for varName in varNames:
value = value[varName]
if value is None:
if varName in value:
value = value.get(varName)
else:
ignoreValue = True
break

if value == requiredValue:
if ignoreValue == False and value == requiredValue:
if nextState is not None and nextState != trigger['next']:
raise RuntimeError("A workflow could transition to multiple states")
nextState = trigger['next']
Expand Down
36 changes: 36 additions & 0 deletions tests/resources/trigger_recursive_variable_none_workflow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name":"trigger",
"states": {

"start": {
"type": "empty",
"next": "triggerTest"
},

"triggerTest": {
"type": "trigger",
"next": "triggerfalse",
"triggers": [
{
"variableName": "recursive;variable;check",
"value": null,
"next": "triggertrue"
}
]
},

"triggertrue": {
"type": "run",
"package":"test_workflow",
"class":"TriggerTrueState",
"next": "finish"
},

"triggerfalse": {
"type": "run",
"package":"test_workflow",
"class":"TriggerFalseState",
"next": "finish"
}
}
}
22 changes: 22 additions & 0 deletions tests/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,25 @@ def test_trigger_recursive_variable(self):

assert TriggerTrueState.called is True
assert TriggerFalseState.called is False

def test_trigger_recursive_unset(self):
workflow = Workflow.loadFromFile('tests/resources/trigger_recursive_variable_workflow.json')
workflow.variables['recursive'] = {'variable': {}}

TriggerTrueState.called = False
TriggerFalseState.called = False
workflow.run()

assert TriggerTrueState.called is False
assert TriggerFalseState.called is True

def test_trigger_recursive_empty(self):
workflow = Workflow.loadFromFile('tests/resources/trigger_recursive_variable_none_workflow.json')
workflow.variables['recursive'] = {'variable': {'check': None}}

TriggerTrueState.called = False
TriggerFalseState.called = False
workflow.run()

assert TriggerTrueState.called is True
assert TriggerFalseState.called is False

0 comments on commit 97a11dc

Please sign in to comment.