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

OrionBaseActionTestCase   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 74
rs 10
wmc 12

12 Methods

Rating   Name   Duplication   Size   Complexity  
A test_run_no_config() 0 4 1
A query_no_results() 0 3 1
A setup_query_blank_results() 0 9 1
A load_yaml() 0 2 1
A full_config() 0 3 1
A query_ncm_node() 0 3 1
A blank_config() 0 3 1
A setUp() 0 7 1
A setup_node_exists() 0 13 1
A test_run_is_instance() 0 3 1
A setup_connect_fail() 0 7 1
A query_npm_node() 0 3 1
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 MagicMock
17
18
from st2tests.base import BaseActionTestCase
19
20
21
class OrionBaseActionTestCase(BaseActionTestCase):
22
    __test__ = False
23
24
    def setUp(self):
25
        super(OrionBaseActionTestCase, self).setUp()
26
27
        self._blank_config = self.load_yaml('blank.yaml')
28
        self._full_config = self.load_yaml('full.yaml')
29
        self._query_npm_node = self.load_yaml('orion_npm_results.yaml')
30
        self._query_ncm_node = self.load_yaml('orion_ncm_results.yaml')
31
32
    def load_yaml(self, filename):
33
        return yaml.safe_load(self.get_fixture_content(filename))
34
35
    @property
36
    def blank_config(self):
37
        return self._blank_config
38
39
    @property
40
    def full_config(self):
41
        return self._full_config
42
43
    @property
44
    def query_npm_node(self):
45
        return self._query_npm_node
46
47
    @property
48
    def query_ncm_node(self):
49
        return self._query_ncm_node
50
51
    @property
52
    def query_no_results(self):
53
        return {'results': []}
54
55
    def setup_connect_fail(self):
56
        action = self.get_action_instance(config=self.full_config)
57
58
        action.connect = MagicMock(side_effect=ValueError(
59
            'Orion host details not in the config.yaml'))
60
61
        return action
62
63
    def setup_query_blank_results(self):
64
        query_data = [self.query_no_results]
65
66
        action = self.get_action_instance(config=self.full_config)
67
68
        action.connect = MagicMock(return_value=True)
69
        action.query = MagicMock(side_effect=query_data)
70
71
        return action
72
73
    def setup_node_exists(self):
74
        query_data = []
75
        query_data.append(self.query_npm_node)
76
        query_data.append(self.query_ncm_node)
77
78
        action = self.get_action_instance(config=self.full_config)
79
80
        action.connect = MagicMock(return_value=True)
81
        action.query = MagicMock(side_effect=query_data)
82
        action.invoke = MagicMock(return_value=None)
83
        action.update = MagicMock(return_value=None)
84
85
        return action
86
87
    def test_run_no_config(self):
88
        self.assertRaises(ValueError,
89
                          self.action_cls,
90
                          self.blank_config)
91
92
    def test_run_is_instance(self):
93
        action = self.get_action_instance(self.full_config)
94
        self.assertIsInstance(action, self.action_cls)
95