|
@@ 1498-1565 (lines=68) @@
|
| 1495 |
|
assert 409 == response.status_code |
| 1496 |
|
assert "Can't update archived EVC" in response.json()["description"] |
| 1497 |
|
|
| 1498 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC.deploy") |
| 1499 |
|
@patch("napps.kytos.mef_eline.scheduler.Scheduler.add") |
| 1500 |
|
@patch("napps.kytos.mef_eline.main.Main._uni_from_dict") |
| 1501 |
|
@patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc") |
| 1502 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC._validate") |
| 1503 |
|
@patch("napps.kytos.mef_eline.main.EVC.as_dict") |
| 1504 |
|
async def test_update_circuit_invalid_json( |
| 1505 |
|
self, |
| 1506 |
|
evc_as_dict_mock, |
| 1507 |
|
validate_mock, |
| 1508 |
|
mongo_controller_upsert_mock, |
| 1509 |
|
uni_from_dict_mock, |
| 1510 |
|
sched_add_mock, |
| 1511 |
|
evc_deploy_mock, |
| 1512 |
|
event_loop |
| 1513 |
|
): |
| 1514 |
|
"""Test update a circuit circuit.""" |
| 1515 |
|
self.napp.controller.loop = event_loop |
| 1516 |
|
validate_mock.return_value = True |
| 1517 |
|
mongo_controller_upsert_mock.return_value = True |
| 1518 |
|
sched_add_mock.return_value = True |
| 1519 |
|
evc_deploy_mock.return_value = True |
| 1520 |
|
uni1 = create_autospec(UNI) |
| 1521 |
|
uni2 = create_autospec(UNI) |
| 1522 |
|
uni1.interface = create_autospec(Interface) |
| 1523 |
|
uni2.interface = create_autospec(Interface) |
| 1524 |
|
uni1.interface.switch = MagicMock() |
| 1525 |
|
uni1.interface.switch.return_value = "00:00:00:00:00:00:00:01" |
| 1526 |
|
uni1.interface.switch.status = EntityStatus.UP |
| 1527 |
|
uni2.interface.switch = MagicMock() |
| 1528 |
|
uni2.interface.switch.return_value = "00:00:00:00:00:00:00:02" |
| 1529 |
|
uni2.interface.switch.status = EntityStatus.UP |
| 1530 |
|
uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2] |
| 1531 |
|
|
| 1532 |
|
payload1 = { |
| 1533 |
|
"name": "my evc1", |
| 1534 |
|
"uni_a": { |
| 1535 |
|
"interface_id": "00:00:00:00:00:00:00:01:1", |
| 1536 |
|
"tag": {"tag_type": 1, "value": 80}, |
| 1537 |
|
}, |
| 1538 |
|
"uni_z": { |
| 1539 |
|
"interface_id": "00:00:00:00:00:00:00:02:2", |
| 1540 |
|
"tag": {"tag_type": 1, "value": 1}, |
| 1541 |
|
}, |
| 1542 |
|
"dynamic_backup_path": True, |
| 1543 |
|
} |
| 1544 |
|
|
| 1545 |
|
payload2 = { |
| 1546 |
|
"dynamic_backup_path": False, |
| 1547 |
|
} |
| 1548 |
|
|
| 1549 |
|
evc_as_dict_mock.return_value = payload1 |
| 1550 |
|
response = await self.api_client.post( |
| 1551 |
|
f"{self.base_endpoint}/v2/evc/", |
| 1552 |
|
json=payload1 |
| 1553 |
|
) |
| 1554 |
|
assert 201 == response.status_code |
| 1555 |
|
|
| 1556 |
|
evc_as_dict_mock.return_value = payload2 |
| 1557 |
|
current_data = response.json() |
| 1558 |
|
circuit_id = current_data["circuit_id"] |
| 1559 |
|
response = await self.api_client.patch( |
| 1560 |
|
f"{self.base_endpoint}/v2/evc/{circuit_id}", |
| 1561 |
|
json=payload2 |
| 1562 |
|
) |
| 1563 |
|
current_data = response.json() |
| 1564 |
|
assert 400 == response.status_code |
| 1565 |
|
assert "must have a primary path or" in current_data["description"] |
| 1566 |
|
|
| 1567 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC.deploy") |
| 1568 |
|
@patch("napps.kytos.mef_eline.scheduler.Scheduler.add") |
|
@@ 1667-1727 (lines=61) @@
|
| 1664 |
|
with pytest.raises(ValueError): |
| 1665 |
|
self.napp._uni_from_dict(uni_dict) |
| 1666 |
|
|
| 1667 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC.deploy") |
| 1668 |
|
@patch("napps.kytos.mef_eline.scheduler.Scheduler.add") |
| 1669 |
|
@patch("napps.kytos.mef_eline.main.Main._uni_from_dict") |
| 1670 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC._validate") |
| 1671 |
|
@patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc") |
| 1672 |
|
async def test_update_evc_no_json_mime( |
| 1673 |
|
self, |
| 1674 |
|
mongo_controller_upsert_mock, |
| 1675 |
|
validate_mock, |
| 1676 |
|
uni_from_dict_mock, |
| 1677 |
|
sched_add_mock, |
| 1678 |
|
evc_deploy_mock, |
| 1679 |
|
event_loop |
| 1680 |
|
): |
| 1681 |
|
"""Test update a circuit with wrong mimetype.""" |
| 1682 |
|
self.napp.controller.loop = event_loop |
| 1683 |
|
validate_mock.return_value = True |
| 1684 |
|
sched_add_mock.return_value = True |
| 1685 |
|
evc_deploy_mock.return_value = True |
| 1686 |
|
uni1 = create_autospec(UNI) |
| 1687 |
|
uni2 = create_autospec(UNI) |
| 1688 |
|
uni1.interface = create_autospec(Interface) |
| 1689 |
|
uni2.interface = create_autospec(Interface) |
| 1690 |
|
uni1.interface.switch = MagicMock() |
| 1691 |
|
uni1.interface.switch.return_value = "00:00:00:00:00:00:00:01" |
| 1692 |
|
uni1.interface.switch.status = EntityStatus.UP |
| 1693 |
|
uni2.interface.switch = MagicMock() |
| 1694 |
|
uni2.interface.switch.return_value = "00:00:00:00:00:00:00:02" |
| 1695 |
|
uni2.interface.switch.status = EntityStatus.UP |
| 1696 |
|
uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2] |
| 1697 |
|
mongo_controller_upsert_mock.return_value = True |
| 1698 |
|
|
| 1699 |
|
payload1 = { |
| 1700 |
|
"name": "my evc1", |
| 1701 |
|
"uni_a": { |
| 1702 |
|
"interface_id": "00:00:00:00:00:00:00:01:1", |
| 1703 |
|
"tag": {"tag_type": 1, "value": 80}, |
| 1704 |
|
}, |
| 1705 |
|
"uni_z": { |
| 1706 |
|
"interface_id": "00:00:00:00:00:00:00:02:2", |
| 1707 |
|
"tag": {"tag_type": 1, "value": 1}, |
| 1708 |
|
}, |
| 1709 |
|
"dynamic_backup_path": True, |
| 1710 |
|
} |
| 1711 |
|
|
| 1712 |
|
payload2 = {"dynamic_backup_path": False} |
| 1713 |
|
|
| 1714 |
|
response = await self.api_client.post( |
| 1715 |
|
f"{self.base_endpoint}/v2/evc/", |
| 1716 |
|
json=payload1, |
| 1717 |
|
) |
| 1718 |
|
assert 201 == response.status_code |
| 1719 |
|
|
| 1720 |
|
current_data = response.json() |
| 1721 |
|
circuit_id = current_data["circuit_id"] |
| 1722 |
|
response = await self.api_client.patch( |
| 1723 |
|
f"{self.base_endpoint}/v2/evc/{circuit_id}", data=payload2 |
| 1724 |
|
) |
| 1725 |
|
current_data = response.json() |
| 1726 |
|
assert 415 == response.status_code |
| 1727 |
|
assert "application/json" in current_data["description"] |
| 1728 |
|
|
| 1729 |
|
async def test_delete_no_evc(self): |
| 1730 |
|
"""Test delete when EVC does not exist.""" |