Completed
Pull Request — master (#487)
by
unknown
02:56
created

test_run_node_not_exist()   A

Complexity

Conditions 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
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 update_node_custom_properties import UpdateNodeCustomProperties
21
22
__all__ = [
23
    'UpdateNodeCustomProperties'
24
]
25
26
27
class UpdateNodeCustomPropertiesTestCase(BaseActionTestCase):
28
    action_cls = UpdateNodeCustomProperties
29
30
    def test_run_no_config(self):
31
        self.assertRaises(ValueError,
32
                          UpdateNodeCustomProperties,
33
                          yaml.safe_load(
34
                              self.get_fixture_content('blank.yaml')))
35
36
    def test_run_is_instance(self):
37
        action = self.get_action_instance(yaml.safe_load(
38
            self.get_fixture_content('full.yaml')))
39
40
        self.assertIsInstance(action, UpdateNodeCustomProperties)
41
42
    def test_run_connect_fail(self):
43
        action = self.get_action_instance(yaml.safe_load(
44
            self.get_fixture_content('full.yaml')))
45
46
        action.connect = Mock(side_effect=ValueError(
47
            'Orion host details not in the config.yaml'))
48
49
        self.assertRaises(ValueError,
50
                          action.run,
51
                          "orion",
52
                          "router1",
53
                          "City",
54
                          "Austin")
55
56
    def test_run_node_not_exist(self):
57
        query_data = [{'results': []}]
58
59
        action = self.get_action_instance(yaml.safe_load(
60
            self.get_fixture_content('full.yaml')))
61
62
        action.connect = MagicMock(return_value=True)
63
        action.query = MagicMock(side_effect=query_data)
64
65
        self.assertRaises(ValueError,
66
                          action.run,
67
                          "router1",
68
                          "orion",
69
                          "City",
70
                          "Austin")
71
72
    def test_run_update(self):
73
        query_data = []
74
        query_data.append(yaml.safe_load(
75
            self.get_fixture_content("orion_npm_results.yaml")))
76
        query_data.append(yaml.safe_load(
77
            self.get_fixture_content("orion_ncm_results.yaml")))
78
79
        read_data = {"City": None}
80
81
        action = self.get_action_instance(yaml.safe_load(
82
            self.get_fixture_content('full.yaml')))
83
84
        action.connect = MagicMock(return_value=True)
85
        action.query = MagicMock(side_effect=query_data)
86
        action.update = Mock(return_value="None")
87
        action.read = Mock(return_value=read_data)
88
89
        result = action.run("router1",
90
                             "orion",
91
                             "City",
92
                             "Austin")
93
94
        self.assertTrue(result)
95
96
    def test_run_custom_property_not_exist(self):
97
        query_data = []
98
        query_data.append(yaml.safe_load(
99
            self.get_fixture_content("orion_npm_results.yaml")))
100
        query_data.append(yaml.safe_load(
101
            self.get_fixture_content("orion_ncm_results.yaml")))
102
103
        read_data = {"City": None}
104
105
        action = self.get_action_instance(yaml.safe_load(
106
            self.get_fixture_content('full.yaml')))
107
108
        action.connect = MagicMock(return_value=True)
109
        action.query = MagicMock(side_effect=query_data)
110
        action.update = Mock(return_value="fake")
111
        action.read = Mock(return_value=read_data)
112
113
        self.assertRaises(ValueError,
114
                          action.run,
115
                          "router1",
116
                          "orion",
117
                          "Cities",
118
                          "Austin")
119