Completed
Pull Request — master (#524)
by
unknown
06:33
created

VsphereBaseActionTestCase.setUp()   A

Complexity

Conditions 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
c 2
b 0
f 0
dl 0
loc 8
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
import json
17
18
from st2tests.base import BaseActionTestCase
19
20
21
class VsphereBaseActionTestCase(BaseActionTestCase):
22
    __test__ = False
23
24
    def setUp(self):
25
        super(VsphereBaseActionTestCase, self).setUp()
26
27
        self._blank_config = self.load_yaml('cfg_blank.yaml')
28
        self._old_config = self.load_yaml('cfg_old.yaml')
29
        self._new_config = self.load_yaml('cfg_new.yaml')
30
        self._old_config_partial = self.load_yaml('cfg_old_partial.yaml')
31
        self._new_config_partial = self.load_yaml('cfg_new_partial.yaml')
32
33
    def load_yaml(self, filename):
34
        return yaml.safe_load(self.get_fixture_content(filename))
35
36
    def load_json(self, filename):
37
        return json.loads(self.get_fixture_content(filename))
38
39
    @property
40
    def blank_config(self):
41
        return self._blank_config
42
43
    @property
44
    def old_config(self):
45
        return self._old_config
46
47
    @property
48
    def new_config(self):
49
        return self._new_config
50
51
    @property
52
    def new_config_partial(self):
53
        return self._new_config_partial
54
55
    @property
56
    def old_config_partial(self):
57
        return self._old_config_partial
58
59
    def test_run_config_blank(self):
60
        self.assertRaises(ValueError, self.action_cls, self.blank_config)
61
62
    def test_run_config_old(self):
63
        action = self.get_action_instance(self.old_config)
64
        self.assertIsInstance(action, self.action_cls)
65
66
    def test_run_config_new(self):
67
        action = self.get_action_instance(self.new_config)
68
        self.assertIsInstance(action, self.action_cls)
69
70
    def test_run_config_old_partial(self):
71
        self.assertRaises(KeyError, self.action_cls, self.old_config_partial)
72
73
    def test_run_config_new_partial(self):
74
        action = self.get_action_instance(self.new_config_partial)
75
        self.assertRaises(KeyError, action.establish_connection,
76
                          vsphere="default")
77