|
@@ 96-119 (lines=24) @@
|
| 93 |
|
urls = get_napp_urls(self.napp) |
| 94 |
|
self.assertEqual(expected_urls, urls) |
| 95 |
|
|
| 96 |
|
def test_enable_switch(self): |
| 97 |
|
"""Test enable_swicth.""" |
| 98 |
|
dpid = "00:00:00:00:00:00:00:01" |
| 99 |
|
mock_switch = get_switch_mock(dpid) |
| 100 |
|
msg_success = "Operation successful" |
| 101 |
|
msg_fail = "Switch not found" |
| 102 |
|
self.napp.controller.switches = {"00:00:00:00:00:00:00:01": |
| 103 |
|
mock_switch} |
| 104 |
|
api = get_test_client(self.napp.controller, self.napp) |
| 105 |
|
|
| 106 |
|
url = f'{self.server_name_url}/v3/switches/{dpid}/enable' |
| 107 |
|
response = api.post(url) |
| 108 |
|
self.assertEqual(response.status_code, 201, response.data) |
| 109 |
|
self.assertEqual(msg_success, json.loads(response.data)) |
| 110 |
|
self.assertEqual(mock_switch.enable.call_count, 1) |
| 111 |
|
|
| 112 |
|
# fail case |
| 113 |
|
mock_switch.enable.call_count = 0 |
| 114 |
|
dpid = "00:00:00:00:00:00:00:02" |
| 115 |
|
url = f'{self.server_name_url}/v3/switches/{dpid}/enable' |
| 116 |
|
response = api.post(url) |
| 117 |
|
self.assertEqual(response.status_code, 404, response.data) |
| 118 |
|
self.assertEqual(msg_fail, json.loads(response.data)) |
| 119 |
|
self.assertEqual(mock_switch.enable.call_count, 0) |
| 120 |
|
|
| 121 |
|
def test_disable_switch(self): |
| 122 |
|
"""Test disable_swicth.""" |
|
@@ 121-143 (lines=23) @@
|
| 118 |
|
self.assertEqual(msg_fail, json.loads(response.data)) |
| 119 |
|
self.assertEqual(mock_switch.enable.call_count, 0) |
| 120 |
|
|
| 121 |
|
def test_disable_switch(self): |
| 122 |
|
"""Test disable_swicth.""" |
| 123 |
|
dpid = "00:00:00:00:00:00:00:01" |
| 124 |
|
mock_switch = get_switch_mock(dpid) |
| 125 |
|
msg_success = "Operation successful" |
| 126 |
|
msg_fail = "Switch not found" |
| 127 |
|
self.napp.controller.switches = {dpid: mock_switch} |
| 128 |
|
api = get_test_client(self.napp.controller, self.napp) |
| 129 |
|
|
| 130 |
|
url = f'{self.server_name_url}/v3/switches/{dpid}/disable' |
| 131 |
|
response = api.post(url) |
| 132 |
|
self.assertEqual(response.status_code, 201, response.data) |
| 133 |
|
self.assertEqual(msg_success, json.loads(response.data)) |
| 134 |
|
self.assertEqual(mock_switch.disable.call_count, 1) |
| 135 |
|
|
| 136 |
|
# fail case |
| 137 |
|
mock_switch.disable.call_count = 0 |
| 138 |
|
dpid = "00:00:00:00:00:00:00:02" |
| 139 |
|
url = f'{self.server_name_url}/v3/switches/{dpid}/disable' |
| 140 |
|
response = api.post(url) |
| 141 |
|
self.assertEqual(response.status_code, 404, response.data) |
| 142 |
|
self.assertEqual(msg_fail, json.loads(response.data)) |
| 143 |
|
self.assertEqual(mock_switch.disable.call_count, 0) |
| 144 |
|
|
| 145 |
|
def test_get_switch_metadata(self): |
| 146 |
|
"""Test get_switch_metadata.""" |