|
@@ 1264-1324 (lines=61) @@
|
| 1261 |
|
evc_deploy.assert_not_called() |
| 1262 |
|
self.assertEqual(405, response.status_code) |
| 1263 |
|
|
| 1264 |
|
@patch('napps.kytos.mef_eline.scheduler.Scheduler.add') |
| 1265 |
|
@patch('napps.kytos.mef_eline.main.Main._uni_from_dict') |
| 1266 |
|
@patch('napps.kytos.mef_eline.storehouse.StoreHouse.save_evc') |
| 1267 |
|
@patch('napps.kytos.mef_eline.models.EVC._validate') |
| 1268 |
|
@patch('napps.kytos.mef_eline.main.EVC.as_dict') |
| 1269 |
|
def test_update_circuit_invalid_json(self, *args): |
| 1270 |
|
"""Test update a circuit circuit.""" |
| 1271 |
|
# pylint: disable=too-many-locals |
| 1272 |
|
(evc_as_dict_mock, validate_mock, save_evc_mock, |
| 1273 |
|
uni_from_dict_mock, sched_add_mock) = args |
| 1274 |
|
|
| 1275 |
|
validate_mock.return_value = True |
| 1276 |
|
save_evc_mock.return_value = True |
| 1277 |
|
sched_add_mock.return_value = True |
| 1278 |
|
uni1 = create_autospec(UNI) |
| 1279 |
|
uni2 = create_autospec(UNI) |
| 1280 |
|
uni1.interface = create_autospec(Interface) |
| 1281 |
|
uni2.interface = create_autospec(Interface) |
| 1282 |
|
uni1.interface.switch = '00:00:00:00:00:00:00:01' |
| 1283 |
|
uni2.interface.switch = '00:00:00:00:00:00:00:02' |
| 1284 |
|
uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2] |
| 1285 |
|
|
| 1286 |
|
api = self.get_app_test_client(self.napp) |
| 1287 |
|
payload1 = { |
| 1288 |
|
"name": "my evc1", |
| 1289 |
|
"uni_a": { |
| 1290 |
|
"interface_id": "00:00:00:00:00:00:00:01:1", |
| 1291 |
|
"tag": { |
| 1292 |
|
"tag_type": 1, |
| 1293 |
|
"value": 80 |
| 1294 |
|
} |
| 1295 |
|
}, |
| 1296 |
|
"uni_z": { |
| 1297 |
|
"interface_id": "00:00:00:00:00:00:00:02:2", |
| 1298 |
|
"tag": { |
| 1299 |
|
"tag_type": 1, |
| 1300 |
|
"value": 1 |
| 1301 |
|
} |
| 1302 |
|
} |
| 1303 |
|
} |
| 1304 |
|
|
| 1305 |
|
payload2 = { |
| 1306 |
|
"dynamic_backup_path": True, |
| 1307 |
|
} |
| 1308 |
|
|
| 1309 |
|
evc_as_dict_mock.return_value = payload1 |
| 1310 |
|
response = api.post(f'{self.server_name_url}/v2/evc/', |
| 1311 |
|
data=json.dumps(payload1), |
| 1312 |
|
content_type='application/json') |
| 1313 |
|
self.assertEqual(201, response.status_code) |
| 1314 |
|
|
| 1315 |
|
evc_as_dict_mock.return_value = payload2 |
| 1316 |
|
current_data = json.loads(response.data) |
| 1317 |
|
circuit_id = current_data['circuit_id'] |
| 1318 |
|
response = api.patch(f'{self.server_name_url}/v2/evc/{circuit_id}', |
| 1319 |
|
data=payload2, |
| 1320 |
|
content_type='application/json') |
| 1321 |
|
current_data = json.loads(response.data) |
| 1322 |
|
expected_data = 'The request body is not a well-formed JSON.' |
| 1323 |
|
self.assertEqual(current_data['description'], expected_data) |
| 1324 |
|
self.assertEqual(400, response.status_code) |
| 1325 |
|
|
| 1326 |
|
@patch('napps.kytos.mef_eline.scheduler.Scheduler.add') |
| 1327 |
|
@patch('napps.kytos.mef_eline.main.Main._uni_from_dict') |
|
@@ 1326-1385 (lines=60) @@
|
| 1323 |
|
self.assertEqual(current_data['description'], expected_data) |
| 1324 |
|
self.assertEqual(400, response.status_code) |
| 1325 |
|
|
| 1326 |
|
@patch('napps.kytos.mef_eline.scheduler.Scheduler.add') |
| 1327 |
|
@patch('napps.kytos.mef_eline.main.Main._uni_from_dict') |
| 1328 |
|
@patch('napps.kytos.mef_eline.storehouse.StoreHouse.save_evc') |
| 1329 |
|
@patch('napps.kytos.mef_eline.models.EVC._validate') |
| 1330 |
|
@patch('napps.kytos.mef_eline.main.EVC.as_dict') |
| 1331 |
|
def test_update_evc_no_json_mime(self, *args): |
| 1332 |
|
"""Test update a circuit with wrong mimetype.""" |
| 1333 |
|
# pylint: disable=too-many-locals |
| 1334 |
|
(evc_as_dict_mock, validate_mock, save_evc_mock, |
| 1335 |
|
uni_from_dict_mock, sched_add_mock) = args |
| 1336 |
|
|
| 1337 |
|
validate_mock.return_value = True |
| 1338 |
|
save_evc_mock.return_value = True |
| 1339 |
|
sched_add_mock.return_value = True |
| 1340 |
|
uni1 = create_autospec(UNI) |
| 1341 |
|
uni2 = create_autospec(UNI) |
| 1342 |
|
uni1.interface = create_autospec(Interface) |
| 1343 |
|
uni2.interface = create_autospec(Interface) |
| 1344 |
|
uni1.interface.switch = '00:00:00:00:00:00:00:01' |
| 1345 |
|
uni2.interface.switch = '00:00:00:00:00:00:00:02' |
| 1346 |
|
uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2] |
| 1347 |
|
|
| 1348 |
|
api = self.get_app_test_client(self.napp) |
| 1349 |
|
payload1 = { |
| 1350 |
|
"name": "my evc1", |
| 1351 |
|
"uni_a": { |
| 1352 |
|
"interface_id": "00:00:00:00:00:00:00:01:1", |
| 1353 |
|
"tag": { |
| 1354 |
|
"tag_type": 1, |
| 1355 |
|
"value": 80 |
| 1356 |
|
} |
| 1357 |
|
}, |
| 1358 |
|
"uni_z": { |
| 1359 |
|
"interface_id": "00:00:00:00:00:00:00:02:2", |
| 1360 |
|
"tag": { |
| 1361 |
|
"tag_type": 1, |
| 1362 |
|
"value": 1 |
| 1363 |
|
} |
| 1364 |
|
} |
| 1365 |
|
} |
| 1366 |
|
|
| 1367 |
|
payload2 = { |
| 1368 |
|
"dynamic_backup_path": True |
| 1369 |
|
} |
| 1370 |
|
|
| 1371 |
|
evc_as_dict_mock.return_value = payload1 |
| 1372 |
|
response = api.post(f'{self.server_name_url}/v2/evc/', |
| 1373 |
|
data=json.dumps(payload1), |
| 1374 |
|
content_type='application/json') |
| 1375 |
|
self.assertEqual(201, response.status_code) |
| 1376 |
|
|
| 1377 |
|
evc_as_dict_mock.return_value = payload2 |
| 1378 |
|
current_data = json.loads(response.data) |
| 1379 |
|
circuit_id = current_data['circuit_id'] |
| 1380 |
|
response = api.patch(f'{self.server_name_url}/v2/evc/{circuit_id}', |
| 1381 |
|
data=payload2) |
| 1382 |
|
current_data = json.loads(response.data) |
| 1383 |
|
expected_data = 'The request body mimetype is not application/json.' |
| 1384 |
|
self.assertEqual(current_data['description'], expected_data) |
| 1385 |
|
self.assertEqual(415, response.status_code) |
| 1386 |
|
|
| 1387 |
|
def test_delete_no_evc(self): |
| 1388 |
|
"""Test delete when EVC does not exist.""" |