-
-
Notifications
You must be signed in to change notification settings - Fork 745
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
134 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Licensed to the StackStorm, Inc ('StackStorm') under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You 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. | ||
|
||
import eventlet | ||
import unittest2 | ||
|
||
from st2client import client as st2 | ||
from st2client import models | ||
|
||
|
||
class TestWorkflowExecution(unittest2.TestCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
cls.st2client = st2.Client(base_url='http://localhost') | ||
|
||
def _execute_workflow(self, action, parameters=None): | ||
if parameters is None: | ||
parameters = {} | ||
|
||
execution = models.LiveAction(action=action, parameters=parameters) | ||
execution = self.st2client.liveactions.create(execution) | ||
self.assertIsNotNone(execution.id) | ||
self.assertEqual(execution.action['ref'], action) | ||
self.assertIn(execution.status, ['scheduled', 'running']) | ||
|
||
return execution | ||
|
||
def _wait_for_completion(self, execution, wait=300): | ||
for i in range(wait): | ||
eventlet.sleep(3) | ||
execution = self.st2client.liveactions.get_by_id(execution.id) | ||
if execution.status in ['succeeded', 'failed']: | ||
break | ||
|
||
return execution | ||
|
||
def _assert_success(self, execution): | ||
self.assertEqual(execution.status, 'succeeded') | ||
tasks = execution.result['tasks'] | ||
for task in tasks: | ||
self.assertIn('state', task) | ||
self.assertEqual(task['state'], 'SUCCESS') | ||
|
||
def _assert_failure(self, execution): | ||
self.assertEqual(execution.status, 'failed') | ||
tasks = execution.result['tasks'] | ||
for task in tasks: | ||
self.assertIn('state', task) | ||
self.assertEqual(task['state'], 'ERROR') |
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,53 @@ | ||
# Licensed to the StackStorm, Inc ('StackStorm') under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You 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 integration.mistral import base | ||
|
||
|
||
class ExamplesTest(base.TestWorkflowExecution): | ||
|
||
def test_workbook_multiple_subflows(self): | ||
execution = self._execute_workflow('examples.mistral-workbook-multiple-subflows') | ||
execution = self._wait_for_completion(execution) | ||
self.assertEqual(execution.status, 'succeeded') | ||
|
||
def test_handle_error(self): | ||
execution = self._execute_workflow('examples.mistral-handle-error') | ||
execution = self._wait_for_completion(execution) | ||
self.assertEqual(execution.status, 'failed') | ||
tasks = {t['name']: t for t in execution.result['tasks']} | ||
self.assertEqual(tasks['task1']['state'], 'ERROR') | ||
self.assertEqual(tasks['notify_on_error']['state'], 'SUCCESS') | ||
|
||
def test_handle_retry(self): | ||
execution = self._execute_workflow('examples.mistral-handle-retry') | ||
execution = self._wait_for_completion(execution) | ||
self.assertEqual(execution.status, 'succeeded') | ||
|
||
def test_repeat(self): | ||
inputs = {'cmd': 'echo "Yo!"'} | ||
execution = self._execute_workflow('examples.mistral-repeat', parameters=inputs) | ||
execution = self._wait_for_completion(execution) | ||
self.assertEqual(execution.status, 'succeeded') | ||
self.assertEqual(len(execution.result['result']), 3) | ||
self.assertListEqual(execution.result['result'], ['Yo!\n', 'Yo!\n', 'Yo!\n']) | ||
|
||
def test_repeat_with_items(self): | ||
inputs = {'cmds': ['echo "a"', 'echo "b"', 'echo "c"']} | ||
execution = self._execute_workflow('examples.mistral-repeat-with-items', parameters=inputs) | ||
execution = self._wait_for_completion(execution) | ||
self.assertEqual(execution.status, 'succeeded') | ||
self.assertEqual(len(execution.result['result']), 3) | ||
self.assertListEqual(sorted(execution.result['result']), ['a\n', 'b\n', 'c\n']) |
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