|
@@ 1354-1417 (lines=64) @@
|
| 1351 |
|
assert 409 == response.status_code |
| 1352 |
|
assert "Can't update archived EVC" in response.json()["description"] |
| 1353 |
|
|
| 1354 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC.deploy") |
| 1355 |
|
@patch("napps.kytos.mef_eline.scheduler.Scheduler.add") |
| 1356 |
|
@patch("napps.kytos.mef_eline.main.Main._uni_from_dict") |
| 1357 |
|
@patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc") |
| 1358 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC._validate") |
| 1359 |
|
@patch("napps.kytos.mef_eline.main.EVC.as_dict") |
| 1360 |
|
async def test_update_circuit_invalid_json(self, *args): |
| 1361 |
|
"""Test update a circuit circuit.""" |
| 1362 |
|
# pylint: disable=too-many-locals |
| 1363 |
|
( |
| 1364 |
|
evc_as_dict_mock, |
| 1365 |
|
validate_mock, |
| 1366 |
|
mongo_controller_upsert_mock, |
| 1367 |
|
uni_from_dict_mock, |
| 1368 |
|
sched_add_mock, |
| 1369 |
|
evc_deploy_mock, |
| 1370 |
|
) = args |
| 1371 |
|
|
| 1372 |
|
validate_mock.return_value = True |
| 1373 |
|
mongo_controller_upsert_mock.return_value = True |
| 1374 |
|
sched_add_mock.return_value = True |
| 1375 |
|
evc_deploy_mock.return_value = True |
| 1376 |
|
uni1 = create_autospec(UNI) |
| 1377 |
|
uni2 = create_autospec(UNI) |
| 1378 |
|
uni1.interface = create_autospec(Interface) |
| 1379 |
|
uni2.interface = create_autospec(Interface) |
| 1380 |
|
uni1.interface.switch = "00:00:00:00:00:00:00:01" |
| 1381 |
|
uni2.interface.switch = "00:00:00:00:00:00:00:02" |
| 1382 |
|
uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2] |
| 1383 |
|
|
| 1384 |
|
payload1 = { |
| 1385 |
|
"name": "my evc1", |
| 1386 |
|
"uni_a": { |
| 1387 |
|
"interface_id": "00:00:00:00:00:00:00:01:1", |
| 1388 |
|
"tag": {"tag_type": 1, "value": 80}, |
| 1389 |
|
}, |
| 1390 |
|
"uni_z": { |
| 1391 |
|
"interface_id": "00:00:00:00:00:00:00:02:2", |
| 1392 |
|
"tag": {"tag_type": 1, "value": 1}, |
| 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 = await self.api_client.post( |
| 1403 |
|
f"{self.base_endpoint}/v2/evc/", |
| 1404 |
|
json=payload1 |
| 1405 |
|
) |
| 1406 |
|
assert 201 == response.status_code |
| 1407 |
|
|
| 1408 |
|
evc_as_dict_mock.return_value = payload2 |
| 1409 |
|
current_data = response.json() |
| 1410 |
|
circuit_id = current_data["circuit_id"] |
| 1411 |
|
response = await self.api_client.patch( |
| 1412 |
|
f"{self.base_endpoint}/v2/evc/{circuit_id}", |
| 1413 |
|
json=payload2 |
| 1414 |
|
) |
| 1415 |
|
current_data = response.json() |
| 1416 |
|
assert 400 == response.status_code |
| 1417 |
|
assert "must have a primary path or" in current_data["description"] |
| 1418 |
|
|
| 1419 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC.deploy") |
| 1420 |
|
@patch("napps.kytos.mef_eline.scheduler.Scheduler.add") |
|
@@ 1515-1571 (lines=57) @@
|
| 1512 |
|
with pytest.raises(ValueError): |
| 1513 |
|
self.napp._uni_from_dict(uni_dict) |
| 1514 |
|
|
| 1515 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC.deploy") |
| 1516 |
|
@patch("napps.kytos.mef_eline.scheduler.Scheduler.add") |
| 1517 |
|
@patch("napps.kytos.mef_eline.main.Main._uni_from_dict") |
| 1518 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC._validate") |
| 1519 |
|
@patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc") |
| 1520 |
|
async def test_update_evc_no_json_mime(self, *args): |
| 1521 |
|
"""Test update a circuit with wrong mimetype.""" |
| 1522 |
|
# pylint: disable=too-many-locals |
| 1523 |
|
( |
| 1524 |
|
mongo_controller_upsert_mock, |
| 1525 |
|
validate_mock, |
| 1526 |
|
uni_from_dict_mock, |
| 1527 |
|
sched_add_mock, |
| 1528 |
|
evc_deploy_mock, |
| 1529 |
|
) = args |
| 1530 |
|
|
| 1531 |
|
validate_mock.return_value = True |
| 1532 |
|
sched_add_mock.return_value = True |
| 1533 |
|
evc_deploy_mock.return_value = True |
| 1534 |
|
uni1 = create_autospec(UNI) |
| 1535 |
|
uni2 = create_autospec(UNI) |
| 1536 |
|
uni1.interface = create_autospec(Interface) |
| 1537 |
|
uni2.interface = create_autospec(Interface) |
| 1538 |
|
uni1.interface.switch = "00:00:00:00:00:00:00:01" |
| 1539 |
|
uni2.interface.switch = "00:00:00:00:00:00:00:02" |
| 1540 |
|
uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2] |
| 1541 |
|
mongo_controller_upsert_mock.return_value = True |
| 1542 |
|
|
| 1543 |
|
payload1 = { |
| 1544 |
|
"name": "my evc1", |
| 1545 |
|
"uni_a": { |
| 1546 |
|
"interface_id": "00:00:00:00:00:00:00:01:1", |
| 1547 |
|
"tag": {"tag_type": 1, "value": 80}, |
| 1548 |
|
}, |
| 1549 |
|
"uni_z": { |
| 1550 |
|
"interface_id": "00:00:00:00:00:00:00:02:2", |
| 1551 |
|
"tag": {"tag_type": 1, "value": 1}, |
| 1552 |
|
}, |
| 1553 |
|
"dynamic_backup_path": True, |
| 1554 |
|
} |
| 1555 |
|
|
| 1556 |
|
payload2 = {"dynamic_backup_path": False} |
| 1557 |
|
|
| 1558 |
|
response = await self.api_client.post( |
| 1559 |
|
f"{self.base_endpoint}/v2/evc/", |
| 1560 |
|
json=payload1, |
| 1561 |
|
) |
| 1562 |
|
assert 201 == response.status_code |
| 1563 |
|
|
| 1564 |
|
current_data = response.json() |
| 1565 |
|
circuit_id = current_data["circuit_id"] |
| 1566 |
|
response = await self.api_client.patch( |
| 1567 |
|
f"{self.base_endpoint}/v2/evc/{circuit_id}", data=payload2 |
| 1568 |
|
) |
| 1569 |
|
current_data = response.json() |
| 1570 |
|
assert 415 == response.status_code |
| 1571 |
|
assert "application/json" in current_data["description"] |
| 1572 |
|
|
| 1573 |
|
async def test_delete_no_evc(self): |
| 1574 |
|
"""Test delete when EVC does not exist.""" |