|
@@ 176-201 (lines=26) @@
|
| 173 |
|
self.assertEqual(mock_switch.disable.call_count, 1) |
| 174 |
|
self.assertEqual(mock_interface.disable.call_count, 1) |
| 175 |
|
|
| 176 |
|
@patch('napps.kytos.topology.main.Main.save_status_on_storehouse') |
| 177 |
|
def test_enable_switch(self, mock_save_status): |
| 178 |
|
"""Test enable_swicth.""" |
| 179 |
|
dpid = "00:00:00:00:00:00:00:01" |
| 180 |
|
mock_switch = get_switch_mock(dpid) |
| 181 |
|
msg_success = "Operation successful" |
| 182 |
|
msg_fail = "Switch not found" |
| 183 |
|
self.napp.controller.switches = {"00:00:00:00:00:00:00:01": |
| 184 |
|
mock_switch} |
| 185 |
|
api = get_test_client(self.napp.controller, self.napp) |
| 186 |
|
|
| 187 |
|
url = f'{self.server_name_url}/v3/switches/{dpid}/enable' |
| 188 |
|
response = api.post(url) |
| 189 |
|
self.assertEqual(response.status_code, 201, response.data) |
| 190 |
|
self.assertEqual(msg_success, json.loads(response.data)) |
| 191 |
|
self.assertEqual(mock_switch.enable.call_count, 1) |
| 192 |
|
mock_save_status.assert_called() |
| 193 |
|
|
| 194 |
|
# fail case |
| 195 |
|
mock_switch.enable.call_count = 0 |
| 196 |
|
dpid = "00:00:00:00:00:00:00:02" |
| 197 |
|
url = f'{self.server_name_url}/v3/switches/{dpid}/enable' |
| 198 |
|
response = api.post(url) |
| 199 |
|
self.assertEqual(response.status_code, 404, response.data) |
| 200 |
|
self.assertEqual(msg_fail, json.loads(response.data)) |
| 201 |
|
self.assertEqual(mock_switch.enable.call_count, 0) |
| 202 |
|
|
| 203 |
|
@patch('napps.kytos.topology.main.Main.save_status_on_storehouse') |
| 204 |
|
def test_disable_switch(self, mock_save_status): |
|
@@ 203-227 (lines=25) @@
|
| 200 |
|
self.assertEqual(msg_fail, json.loads(response.data)) |
| 201 |
|
self.assertEqual(mock_switch.enable.call_count, 0) |
| 202 |
|
|
| 203 |
|
@patch('napps.kytos.topology.main.Main.save_status_on_storehouse') |
| 204 |
|
def test_disable_switch(self, mock_save_status): |
| 205 |
|
"""Test disable_swicth.""" |
| 206 |
|
dpid = "00:00:00:00:00:00:00:01" |
| 207 |
|
mock_switch = get_switch_mock(dpid) |
| 208 |
|
msg_success = "Operation successful" |
| 209 |
|
msg_fail = "Switch not found" |
| 210 |
|
self.napp.controller.switches = {dpid: mock_switch} |
| 211 |
|
api = get_test_client(self.napp.controller, self.napp) |
| 212 |
|
|
| 213 |
|
url = f'{self.server_name_url}/v3/switches/{dpid}/disable' |
| 214 |
|
response = api.post(url) |
| 215 |
|
self.assertEqual(response.status_code, 201, response.data) |
| 216 |
|
self.assertEqual(msg_success, json.loads(response.data)) |
| 217 |
|
self.assertEqual(mock_switch.disable.call_count, 1) |
| 218 |
|
mock_save_status.assert_called() |
| 219 |
|
|
| 220 |
|
# fail case |
| 221 |
|
mock_switch.disable.call_count = 0 |
| 222 |
|
dpid = "00:00:00:00:00:00:00:02" |
| 223 |
|
url = f'{self.server_name_url}/v3/switches/{dpid}/disable' |
| 224 |
|
response = api.post(url) |
| 225 |
|
self.assertEqual(response.status_code, 404, response.data) |
| 226 |
|
self.assertEqual(msg_fail, json.loads(response.data)) |
| 227 |
|
self.assertEqual(mock_switch.disable.call_count, 0) |
| 228 |
|
|
| 229 |
|
def test_get_switch_metadata(self): |
| 230 |
|
"""Test get_switch_metadata.""" |