|
@@ 1353-1416 (lines=64) @@
|
| 1350 |
|
evc_deploy.assert_not_called() |
| 1351 |
|
self.assertEqual(405, response.status_code) |
| 1352 |
|
|
| 1353 |
|
@patch('napps.kytos.mef_eline.models.EVC.deploy') |
| 1354 |
|
@patch('napps.kytos.mef_eline.scheduler.Scheduler.add') |
| 1355 |
|
@patch('napps.kytos.mef_eline.main.Main._uni_from_dict') |
| 1356 |
|
@patch('napps.kytos.mef_eline.storehouse.StoreHouse.save_evc') |
| 1357 |
|
@patch('napps.kytos.mef_eline.models.EVC._validate') |
| 1358 |
|
@patch('napps.kytos.mef_eline.main.EVC.as_dict') |
| 1359 |
|
def test_update_circuit_invalid_json(self, *args): |
| 1360 |
|
"""Test update a circuit circuit.""" |
| 1361 |
|
# pylint: disable=too-many-locals |
| 1362 |
|
(evc_as_dict_mock, validate_mock, save_evc_mock, |
| 1363 |
|
uni_from_dict_mock, sched_add_mock, evc_deploy_mock) = args |
| 1364 |
|
|
| 1365 |
|
validate_mock.return_value = True |
| 1366 |
|
save_evc_mock.return_value = True |
| 1367 |
|
sched_add_mock.return_value = True |
| 1368 |
|
evc_deploy_mock.return_value = True |
| 1369 |
|
uni1 = create_autospec(UNI) |
| 1370 |
|
uni2 = create_autospec(UNI) |
| 1371 |
|
uni1.interface = create_autospec(Interface) |
| 1372 |
|
uni2.interface = create_autospec(Interface) |
| 1373 |
|
uni1.interface.switch = '00:00:00:00:00:00:00:01' |
| 1374 |
|
uni2.interface.switch = '00:00:00:00:00:00:00:02' |
| 1375 |
|
uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2] |
| 1376 |
|
|
| 1377 |
|
api = self.get_app_test_client(self.napp) |
| 1378 |
|
payload1 = { |
| 1379 |
|
"name": "my evc1", |
| 1380 |
|
"uni_a": { |
| 1381 |
|
"interface_id": "00:00:00:00:00:00:00:01:1", |
| 1382 |
|
"tag": { |
| 1383 |
|
"tag_type": 1, |
| 1384 |
|
"value": 80 |
| 1385 |
|
} |
| 1386 |
|
}, |
| 1387 |
|
"uni_z": { |
| 1388 |
|
"interface_id": "00:00:00:00:00:00:00:02:2", |
| 1389 |
|
"tag": { |
| 1390 |
|
"tag_type": 1, |
| 1391 |
|
"value": 1 |
| 1392 |
|
} |
| 1393 |
|
}, |
| 1394 |
|
"dynamic_backup_path": True |
| 1395 |
|
} |
| 1396 |
|
|
| 1397 |
|
payload2 = { |
| 1398 |
|
"dynamic_backup_path": False, |
| 1399 |
|
} |
| 1400 |
|
|
| 1401 |
|
evc_as_dict_mock.return_value = payload1 |
| 1402 |
|
response = api.post(f'{self.server_name_url}/v2/evc/', |
| 1403 |
|
data=json.dumps(payload1), |
| 1404 |
|
content_type='application/json') |
| 1405 |
|
self.assertEqual(201, response.status_code) |
| 1406 |
|
|
| 1407 |
|
evc_as_dict_mock.return_value = payload2 |
| 1408 |
|
current_data = json.loads(response.data) |
| 1409 |
|
circuit_id = current_data['circuit_id'] |
| 1410 |
|
response = api.patch(f'{self.server_name_url}/v2/evc/{circuit_id}', |
| 1411 |
|
data=payload2, |
| 1412 |
|
content_type='application/json') |
| 1413 |
|
current_data = json.loads(response.data) |
| 1414 |
|
expected_data = 'The request body is not a well-formed JSON.' |
| 1415 |
|
self.assertEqual(current_data['description'], expected_data) |
| 1416 |
|
self.assertEqual(400, response.status_code) |
| 1417 |
|
|
| 1418 |
|
@patch('napps.kytos.mef_eline.models.EVC.deploy') |
| 1419 |
|
@patch('napps.kytos.mef_eline.scheduler.Scheduler.add') |
|
@@ 1418-1480 (lines=63) @@
|
| 1415 |
|
self.assertEqual(current_data['description'], expected_data) |
| 1416 |
|
self.assertEqual(400, response.status_code) |
| 1417 |
|
|
| 1418 |
|
@patch('napps.kytos.mef_eline.models.EVC.deploy') |
| 1419 |
|
@patch('napps.kytos.mef_eline.scheduler.Scheduler.add') |
| 1420 |
|
@patch('napps.kytos.mef_eline.main.Main._uni_from_dict') |
| 1421 |
|
@patch('napps.kytos.mef_eline.storehouse.StoreHouse.save_evc') |
| 1422 |
|
@patch('napps.kytos.mef_eline.models.EVC._validate') |
| 1423 |
|
@patch('napps.kytos.mef_eline.main.EVC.as_dict') |
| 1424 |
|
def test_update_evc_no_json_mime(self, *args): |
| 1425 |
|
"""Test update a circuit with wrong mimetype.""" |
| 1426 |
|
# pylint: disable=too-many-locals |
| 1427 |
|
(evc_as_dict_mock, validate_mock, save_evc_mock, |
| 1428 |
|
uni_from_dict_mock, sched_add_mock, evc_deploy_mock) = args |
| 1429 |
|
|
| 1430 |
|
validate_mock.return_value = True |
| 1431 |
|
save_evc_mock.return_value = True |
| 1432 |
|
sched_add_mock.return_value = True |
| 1433 |
|
evc_deploy_mock.return_value = True |
| 1434 |
|
uni1 = create_autospec(UNI) |
| 1435 |
|
uni2 = create_autospec(UNI) |
| 1436 |
|
uni1.interface = create_autospec(Interface) |
| 1437 |
|
uni2.interface = create_autospec(Interface) |
| 1438 |
|
uni1.interface.switch = '00:00:00:00:00:00:00:01' |
| 1439 |
|
uni2.interface.switch = '00:00:00:00:00:00:00:02' |
| 1440 |
|
uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2] |
| 1441 |
|
|
| 1442 |
|
api = self.get_app_test_client(self.napp) |
| 1443 |
|
payload1 = { |
| 1444 |
|
"name": "my evc1", |
| 1445 |
|
"uni_a": { |
| 1446 |
|
"interface_id": "00:00:00:00:00:00:00:01:1", |
| 1447 |
|
"tag": { |
| 1448 |
|
"tag_type": 1, |
| 1449 |
|
"value": 80 |
| 1450 |
|
} |
| 1451 |
|
}, |
| 1452 |
|
"uni_z": { |
| 1453 |
|
"interface_id": "00:00:00:00:00:00:00:02:2", |
| 1454 |
|
"tag": { |
| 1455 |
|
"tag_type": 1, |
| 1456 |
|
"value": 1 |
| 1457 |
|
} |
| 1458 |
|
}, |
| 1459 |
|
"dynamic_backup_path": True |
| 1460 |
|
} |
| 1461 |
|
|
| 1462 |
|
payload2 = { |
| 1463 |
|
"dynamic_backup_path": False |
| 1464 |
|
} |
| 1465 |
|
|
| 1466 |
|
evc_as_dict_mock.return_value = payload1 |
| 1467 |
|
response = api.post(f'{self.server_name_url}/v2/evc/', |
| 1468 |
|
data=json.dumps(payload1), |
| 1469 |
|
content_type='application/json') |
| 1470 |
|
self.assertEqual(201, response.status_code) |
| 1471 |
|
|
| 1472 |
|
evc_as_dict_mock.return_value = payload2 |
| 1473 |
|
current_data = json.loads(response.data) |
| 1474 |
|
circuit_id = current_data['circuit_id'] |
| 1475 |
|
response = api.patch(f'{self.server_name_url}/v2/evc/{circuit_id}', |
| 1476 |
|
data=payload2) |
| 1477 |
|
current_data = json.loads(response.data) |
| 1478 |
|
expected_data = 'The request body mimetype is not application/json.' |
| 1479 |
|
self.assertEqual(current_data['description'], expected_data) |
| 1480 |
|
self.assertEqual(415, response.status_code) |
| 1481 |
|
|
| 1482 |
|
def test_delete_no_evc(self): |
| 1483 |
|
"""Test delete when EVC does not exist.""" |