forked from openmsa/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_order_command_execute.py
More file actions
195 lines (146 loc) · 5.5 KB
/
test_order_command_execute.py
File metadata and controls
195 lines (146 loc) · 5.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
"""
Test Order Command
"""
import json
from unittest.mock import patch
import pytest
from util import order_fixture # pylint: disable=unused-import
# pylint: disable=redefined-outer-name
@patch('msa_sdk.device.Device.read')
def test_command_execute(_, order_fixture):
"""
Test Command execute
"""
local_path = '/ordercommand/execute/21594/UPDATE'
with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post:
order = order_fixture
order.command_execute('UPDATE', {"subnet": "mySubnet"}, 50)
assert order.path == local_path
mock_call_post.assert_called_once_with({"subnet": "mySubnet"}, 50)
def test_command_execute_fail(order_fixture):
"""
Test Command execute fail parameters type
"""
order = order_fixture
with pytest.raises(TypeError):
order.command_execute('UPDATE', 123, 50)
@patch('msa_sdk.device.Device.read')
def test_command_generate_configuration(_, order_fixture):
"""
Test command generate configuration
"""
local_path = '/ordercommand/get/configuration/21594/UPDATE'
with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post:
order = order_fixture
order.command_generate_configuration('UPDATE',
{"subnet": "mySubnet"})
assert order.path == local_path
mock_call_post.assert_called_once_with({"subnet": "mySubnet"})
@patch('msa_sdk.device.Device.read')
def test_command_synchronize(_, order_fixture):
"""
Test command syncronize
"""
local_path = '/ordercommand/synchronize/21594'
with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post:
order = order_fixture
order.command_synchronize(50)
assert order.path == local_path
mock_call_post.assert_called_once_with(timeout=50)
@patch('msa_sdk.device.Device.read')
def test_command_synchronize_one_or_more(_, order_fixture):
"""
Test syncronize one or more
"""
local_path = '/ordercommand/microservice/synchronize/21594'
with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post:
order = order_fixture
l_mservices = ["CommandDefinition/microservices/interface.xml",
"CommandDefinition/microservices/routes.xml"]
order.command_synchronizeOneOrMoreObjectsFromDevice(l_mservices, 50)
assert order.path == local_path
params = {"microServiceUris": l_mservices}
mock_call_post.assert_called_once_with(params, timeout=50)
@patch('msa_sdk.device.Device.read')
def test_command_call(_, order_fixture):
"""
Test command call
"""
local_path = '/ordercommand/call/21594/UPDATE/1'
with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post:
order = order_fixture
order.command_call('UPDATE', 1,
{"subnet": "mySubnet"}, 300)
assert order.path == local_path
mock_call_post.assert_called_once_with({"subnet": "mySubnet"}, 300)
@patch('msa_sdk.device.Device.read')
def test_command_objects_all(_, order_fixture):
"""
Get all microservices attached to a device
"""
local_path = '/ordercommand/objects/21594'
return_body = [
'accesslist',
'addressObject',
'address_holder'
]
with patch('requests.get') as mock_call_get:
mock_call_get.return_value.text = return_body
order = order_fixture
order.command_objects_all()
assert order.path == local_path
assert order.content == return_body
@patch('msa_sdk.device.Device.read')
def test_command_objects_instances(_, order_fixture):
"""
Get microservices instance by microservice name
"""
local_path = '/ordercommand/objects/21594/accesslist'
return_body = json.dumps([
'2000 line 1',
'2000 line 2',
'FROM-inside line 1'
])
with patch('requests.get') as mock_call_get:
mock_call_get.return_value.text = return_body
order = order_fixture
order.command_objects_instances('accesslist')
assert order.path == local_path
assert order.content == return_body
@patch('msa_sdk.device.Device.read')
def test_command_objects_instances_by_id(_, order_fixture):
"""
Get microservices instance by microservice object ID
"""
local_path = '/ordercommand/objects/21594/accesslist/2000'
return_body = json.dumps({
"accesslist": {
"2000": {
"_order": "1000",
"destip": "8.8.8.0",
"destmask": "255.255.255.0",
"object_id": "2000 line 1",
"options": "log informational interval 300 ",
"protocol": "ip",
"right": "permit",
"sourceip": "10.101.32.0",
"sourcemask": "255.255.255.0"
}
}
})
with patch('requests.get') as mock_call_get:
mock_call_get.return_value.text = return_body
order = order_fixture
order.command_objects_instances_by_id('accesslist', '2000')
assert order.path == local_path
assert order.content == return_body
def test_command_get_deployment_settings_id(order_fixture):
"""
Get deployment settings ID for the device.
"""
response = ('{"ConfigProfileByDevice" : 276}')
with patch('msa_sdk.msa_api.MSA_API._call_get') as mock_call_get:
order = order_fixture
order._content = response
assert order.command_get_deployment_settings_id() == 276
mock_call_get.assert_called_once_with()