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

NcmConfigDownloadTestCase   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 63
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A test_run_connect_fail() 0 7 1
B test_run_ncm_download_complete() 0 43 1
A test_run_ncm_node_not_found() 0 7 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
from mock import MagicMock
16
17
from orion_base_action_test_case import OrionBaseActionTestCase
18
19
from ncm_config_download import NcmConfigDownload
20
21
__all__ = [
22
    'NcmConfigDownloadTestCase'
23
]
24
25
26
class NcmConfigDownloadTestCase(OrionBaseActionTestCase):
27
    __test__ = True
28
    action_cls = NcmConfigDownload
29
30
    def test_run_connect_fail(self):
31
        action = self.setup_connect_fail()
32
        self.assertRaises(ValueError,
33
                          action.run,
34
                          "router1",
35
                          "orion",
36
                          ["running", "startup"])
37
38
    def test_run_ncm_node_not_found(self):
39
        action = self.setup_query_blank_results()
40
        self.assertRaises(Exception,
41
                          action.run,
42
                          "router1",
43
                          "orion",
44
                          ["running", "startup"])
45
46
    def test_run_ncm_download_complete(self):
47
        expected = {'running': {'DeviceOutput': None,
48
                                'ErrorMessage': None,
49
                                'RequestedReboot': False,
50
                                'RequestedScript': None,
51
                                'UserName': 'hubot',
52
                                'status': 'Complete'},
53
                    'startup': {'DeviceOutput': None,
54
                                'ErrorMessage': None,
55
                                'RequestedReboot': False,
56
                                'RequestedScript': None,
57
                                'UserName': 'hubot',
58
                                'status': 'Complete'},
59
                    }
60
61
        query_data = []
62
        query_data.append(self.query_npm_node)
63
        query_data.append(self.query_ncm_node)
64
        query_data.append({'results': [{"Status": 2,
65
                                        "UserName": "hubot",
66
                                        "DeviceOutput": None,
67
                                        "ErrorMessage": None,
68
                                        "RequestedScript": None,
69
                                        "RequestedReboot": False}]})
70
        query_data.append({'results': [{"Status": 2,
71
                                        "UserName": "hubot",
72
                                        "DeviceOutput": None,
73
                                        "ErrorMessage": None,
74
                                        "RequestedScript": None,
75
                                        "RequestedReboot": False}]})
76
        invoke_data = ["1234567890"]
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=invoke_data)
83
84
        result = action.run("router1",
85
                            "orion",
86
                            ["running", "startup"])
87
88
        self.assertEqual(result, expected)
89