|
@@ 1435-1498 (lines=64) @@
|
| 1432 |
|
assert 409 == response.status_code |
| 1433 |
|
assert "Can't update archived EVC" in response.json()["description"] |
| 1434 |
|
|
| 1435 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC.deploy") |
| 1436 |
|
@patch("napps.kytos.mef_eline.scheduler.Scheduler.add") |
| 1437 |
|
@patch("napps.kytos.mef_eline.main.Main._uni_from_dict") |
| 1438 |
|
@patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc") |
| 1439 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC._validate") |
| 1440 |
|
@patch("napps.kytos.mef_eline.main.EVC.as_dict") |
| 1441 |
|
async def test_update_circuit_invalid_json( |
| 1442 |
|
self, |
| 1443 |
|
evc_as_dict_mock, |
| 1444 |
|
validate_mock, |
| 1445 |
|
mongo_controller_upsert_mock, |
| 1446 |
|
uni_from_dict_mock, |
| 1447 |
|
sched_add_mock, |
| 1448 |
|
evc_deploy_mock, |
| 1449 |
|
event_loop |
| 1450 |
|
): |
| 1451 |
|
"""Test update a circuit circuit.""" |
| 1452 |
|
self.napp.controller.loop = event_loop |
| 1453 |
|
validate_mock.return_value = True |
| 1454 |
|
mongo_controller_upsert_mock.return_value = True |
| 1455 |
|
sched_add_mock.return_value = True |
| 1456 |
|
evc_deploy_mock.return_value = True |
| 1457 |
|
uni1 = create_autospec(UNI) |
| 1458 |
|
uni2 = create_autospec(UNI) |
| 1459 |
|
uni1.interface = create_autospec(Interface) |
| 1460 |
|
uni2.interface = create_autospec(Interface) |
| 1461 |
|
uni1.interface.switch = "00:00:00:00:00:00:00:01" |
| 1462 |
|
uni2.interface.switch = "00:00:00:00:00:00:00:02" |
| 1463 |
|
uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2] |
| 1464 |
|
|
| 1465 |
|
payload1 = { |
| 1466 |
|
"name": "my evc1", |
| 1467 |
|
"uni_a": { |
| 1468 |
|
"interface_id": "00:00:00:00:00:00:00:01:1", |
| 1469 |
|
"tag": {"tag_type": 1, "value": 80}, |
| 1470 |
|
}, |
| 1471 |
|
"uni_z": { |
| 1472 |
|
"interface_id": "00:00:00:00:00:00:00:02:2", |
| 1473 |
|
"tag": {"tag_type": 1, "value": 1}, |
| 1474 |
|
}, |
| 1475 |
|
"dynamic_backup_path": True, |
| 1476 |
|
} |
| 1477 |
|
|
| 1478 |
|
payload2 = { |
| 1479 |
|
"dynamic_backup_path": False, |
| 1480 |
|
} |
| 1481 |
|
|
| 1482 |
|
evc_as_dict_mock.return_value = payload1 |
| 1483 |
|
response = await self.api_client.post( |
| 1484 |
|
f"{self.base_endpoint}/v2/evc/", |
| 1485 |
|
json=payload1 |
| 1486 |
|
) |
| 1487 |
|
assert 201 == response.status_code |
| 1488 |
|
|
| 1489 |
|
evc_as_dict_mock.return_value = payload2 |
| 1490 |
|
current_data = response.json() |
| 1491 |
|
circuit_id = current_data["circuit_id"] |
| 1492 |
|
response = await self.api_client.patch( |
| 1493 |
|
f"{self.base_endpoint}/v2/evc/{circuit_id}", |
| 1494 |
|
json=payload2 |
| 1495 |
|
) |
| 1496 |
|
current_data = response.json() |
| 1497 |
|
assert 400 == response.status_code |
| 1498 |
|
assert "must have a primary path or" in current_data["description"] |
| 1499 |
|
|
| 1500 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC.deploy") |
| 1501 |
|
@patch("napps.kytos.mef_eline.scheduler.Scheduler.add") |
|
@@ 1663-1719 (lines=57) @@
|
| 1660 |
|
with pytest.raises(ValueError): |
| 1661 |
|
self.napp._uni_from_dict(uni_dict) |
| 1662 |
|
|
| 1663 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC.deploy") |
| 1664 |
|
@patch("napps.kytos.mef_eline.scheduler.Scheduler.add") |
| 1665 |
|
@patch("napps.kytos.mef_eline.main.Main._uni_from_dict") |
| 1666 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC._validate") |
| 1667 |
|
@patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc") |
| 1668 |
|
async def test_update_evc_no_json_mime( |
| 1669 |
|
self, |
| 1670 |
|
mongo_controller_upsert_mock, |
| 1671 |
|
validate_mock, |
| 1672 |
|
uni_from_dict_mock, |
| 1673 |
|
sched_add_mock, |
| 1674 |
|
evc_deploy_mock, |
| 1675 |
|
event_loop |
| 1676 |
|
): |
| 1677 |
|
"""Test update a circuit with wrong mimetype.""" |
| 1678 |
|
self.napp.controller.loop = event_loop |
| 1679 |
|
validate_mock.return_value = True |
| 1680 |
|
sched_add_mock.return_value = True |
| 1681 |
|
evc_deploy_mock.return_value = True |
| 1682 |
|
uni1 = create_autospec(UNI) |
| 1683 |
|
uni2 = create_autospec(UNI) |
| 1684 |
|
uni1.interface = create_autospec(Interface) |
| 1685 |
|
uni2.interface = create_autospec(Interface) |
| 1686 |
|
uni1.interface.switch = "00:00:00:00:00:00:00:01" |
| 1687 |
|
uni2.interface.switch = "00:00:00:00:00:00:00:02" |
| 1688 |
|
uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2] |
| 1689 |
|
mongo_controller_upsert_mock.return_value = True |
| 1690 |
|
|
| 1691 |
|
payload1 = { |
| 1692 |
|
"name": "my evc1", |
| 1693 |
|
"uni_a": { |
| 1694 |
|
"interface_id": "00:00:00:00:00:00:00:01:1", |
| 1695 |
|
"tag": {"tag_type": 1, "value": 80}, |
| 1696 |
|
}, |
| 1697 |
|
"uni_z": { |
| 1698 |
|
"interface_id": "00:00:00:00:00:00:00:02:2", |
| 1699 |
|
"tag": {"tag_type": 1, "value": 1}, |
| 1700 |
|
}, |
| 1701 |
|
"dynamic_backup_path": True, |
| 1702 |
|
} |
| 1703 |
|
|
| 1704 |
|
payload2 = {"dynamic_backup_path": False} |
| 1705 |
|
|
| 1706 |
|
response = await self.api_client.post( |
| 1707 |
|
f"{self.base_endpoint}/v2/evc/", |
| 1708 |
|
json=payload1, |
| 1709 |
|
) |
| 1710 |
|
assert 201 == response.status_code |
| 1711 |
|
|
| 1712 |
|
current_data = response.json() |
| 1713 |
|
circuit_id = current_data["circuit_id"] |
| 1714 |
|
response = await self.api_client.patch( |
| 1715 |
|
f"{self.base_endpoint}/v2/evc/{circuit_id}", data=payload2 |
| 1716 |
|
) |
| 1717 |
|
current_data = response.json() |
| 1718 |
|
assert 415 == response.status_code |
| 1719 |
|
assert "application/json" in current_data["description"] |
| 1720 |
|
|
| 1721 |
|
async def test_delete_no_evc(self): |
| 1722 |
|
"""Test delete when EVC does not exist.""" |