|
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
|
|
|
|
|
15
|
|
|
import yaml |
|
16
|
|
|
from mock import Mock # , MagicMock |
|
17
|
|
|
|
|
18
|
|
|
from st2tests.base import BaseActionTestCase |
|
19
|
|
|
|
|
20
|
|
|
from orion_health import OrionHealth |
|
21
|
|
|
|
|
22
|
|
|
__all__ = [ |
|
23
|
|
|
'OrionHealthTestCase' |
|
24
|
|
|
] |
|
25
|
|
|
|
|
26
|
|
|
MOCK_CONFIG_BLANK = yaml.safe_load(open( |
|
27
|
|
|
'packs/orion/tests/fixture/blank.yaml').read()) |
|
28
|
|
|
MOCK_CONFIG_FULL = yaml.safe_load(open( |
|
29
|
|
|
'packs/orion/tests/fixture/full.yaml').read()) |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
class OrionHealthTestCase(BaseActionTestCase): |
|
33
|
|
|
action_cls = OrionHealth |
|
34
|
|
|
|
|
35
|
|
|
def test_run_no_config(self): |
|
36
|
|
|
self.assertRaises(ValueError, OrionHealth, MOCK_CONFIG_BLANK) |
|
37
|
|
|
|
|
38
|
|
|
def test_run_is_instance(self): |
|
39
|
|
|
action = self.get_action_instance(MOCK_CONFIG_FULL) |
|
40
|
|
|
self.assertIsInstance(action, OrionHealth) |
|
41
|
|
|
|
|
42
|
|
|
def test_run_connect_fail(self): |
|
43
|
|
|
action = self.get_action_instance(MOCK_CONFIG_FULL) |
|
44
|
|
|
action.connect = Mock(side_effect=ValueError( |
|
45
|
|
|
'Orion host details not in the config.yaml')) |
|
46
|
|
|
|
|
47
|
|
|
self.assertRaises(ValueError, action.run, "orion") |
|
48
|
|
|
|