1
|
|
|
# Licensed to the StackStorm, Inc ('StackStorm') under one or more |
2
|
|
|
# contributor license agreements. See the NOTICE file distributed with |
3
|
|
|
# this work for additional information regarding copyright ownership. |
4
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0 |
5
|
|
|
# (the "License"); you may not use this file except in compliance with |
6
|
|
|
# the License. You may obtain a copy of the License at |
7
|
|
|
# |
8
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
9
|
|
|
# |
10
|
|
|
# Unless required by applicable law or agreed to in writing, software |
11
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
12
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13
|
|
|
# See the License for the specific language governing permissions and |
14
|
|
|
# limitations under the License. |
15
|
|
|
|
16
|
|
|
import mock |
17
|
|
|
|
18
|
|
|
from st2actions.container.service import RunnerContainerService |
19
|
|
|
from st2common.constants.action import LIVEACTION_STATUS_SUCCEEDED |
20
|
|
|
from st2common.services import action as action_service |
21
|
|
|
from st2common.util import action_db as action_db_util |
22
|
|
|
from st2tests import DbTestCase |
23
|
|
|
from st2tests.fixturesloader import FixturesLoader |
24
|
|
|
import action_chain_runner as acr |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
class DummyActionExecution(object): |
28
|
|
|
def __init__(self, status=LIVEACTION_STATUS_SUCCEEDED, result=''): |
29
|
|
|
self.id = None |
30
|
|
|
self.status = status |
31
|
|
|
self.result = result |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
FIXTURES_PACK = 'generic' |
35
|
|
|
|
36
|
|
|
TEST_MODELS = { |
37
|
|
|
'actions': ['a1.yaml', 'a2.yaml'], |
38
|
|
|
'runners': ['testrunner1.yaml'] |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
MODELS = FixturesLoader().load_models(fixtures_pack=FIXTURES_PACK, |
42
|
|
|
fixtures_dict=TEST_MODELS) |
43
|
|
|
ACTION_1 = MODELS['actions']['a1.yaml'] |
44
|
|
|
ACTION_2 = MODELS['actions']['a2.yaml'] |
45
|
|
|
RUNNER = MODELS['runners']['testrunner1.yaml'] |
46
|
|
|
|
47
|
|
|
CHAIN_1_PATH = FixturesLoader().get_fixture_file_path_abs( |
48
|
|
|
FIXTURES_PACK, 'actionchains', 'chain_with_notifications.yaml') |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
@mock.patch.object(action_db_util, 'get_runnertype_by_name', |
52
|
|
|
mock.MagicMock(return_value=RUNNER)) |
53
|
|
|
class TestActionChainNotifications(DbTestCase): |
54
|
|
|
|
55
|
|
|
@mock.patch.object(action_db_util, 'get_action_by_ref', |
56
|
|
|
mock.MagicMock(return_value=ACTION_1)) |
57
|
|
|
@mock.patch.object(action_service, 'request', return_value=(DummyActionExecution(), None)) |
58
|
|
|
def test_chain_runner_success_path(self, request): |
59
|
|
|
chain_runner = acr.get_runner() |
60
|
|
|
chain_runner.entry_point = CHAIN_1_PATH |
61
|
|
|
chain_runner.action = ACTION_1 |
62
|
|
|
chain_runner.container_service = RunnerContainerService() |
63
|
|
|
chain_runner.pre_run() |
64
|
|
|
chain_runner.run({}) |
65
|
|
|
self.assertNotEqual(chain_runner.chain_holder.actionchain, None) |
66
|
|
|
self.assertEqual(request.call_count, 2) |
67
|
|
|
first_call_args = request.call_args_list[0][0] |
68
|
|
|
liveaction_db = first_call_args[0] |
69
|
|
|
self.assertTrue(liveaction_db.notify, 'Notify property expected.') |
70
|
|
|
|
71
|
|
|
second_call_args = request.call_args_list[1][0] |
72
|
|
|
liveaction_db = second_call_args[0] |
73
|
|
|
self.assertFalse(liveaction_db.notify, 'Notify property not expected.') |
74
|
|
|
|