|
@@ 1547-1614 (lines=68) @@
|
| 1544 |
|
evc_deploy.assert_not_called() |
| 1545 |
|
self.assertEqual(405, response.status_code) |
| 1546 |
|
|
| 1547 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC.deploy") |
| 1548 |
|
@patch("napps.kytos.mef_eline.scheduler.Scheduler.add") |
| 1549 |
|
@patch("napps.kytos.mef_eline.main.Main._uni_from_dict") |
| 1550 |
|
@patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc") |
| 1551 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC._validate") |
| 1552 |
|
@patch("napps.kytos.mef_eline.main.EVC.as_dict") |
| 1553 |
|
def test_update_circuit_invalid_json(self, *args): |
| 1554 |
|
"""Test update a circuit circuit.""" |
| 1555 |
|
# pylint: disable=too-many-locals |
| 1556 |
|
( |
| 1557 |
|
evc_as_dict_mock, |
| 1558 |
|
validate_mock, |
| 1559 |
|
mongo_controller_upsert_mock, |
| 1560 |
|
uni_from_dict_mock, |
| 1561 |
|
sched_add_mock, |
| 1562 |
|
evc_deploy_mock, |
| 1563 |
|
) = args |
| 1564 |
|
|
| 1565 |
|
validate_mock.return_value = True |
| 1566 |
|
mongo_controller_upsert_mock.return_value = True |
| 1567 |
|
sched_add_mock.return_value = True |
| 1568 |
|
evc_deploy_mock.return_value = True |
| 1569 |
|
uni1 = create_autospec(UNI) |
| 1570 |
|
uni2 = create_autospec(UNI) |
| 1571 |
|
uni1.interface = create_autospec(Interface) |
| 1572 |
|
uni2.interface = create_autospec(Interface) |
| 1573 |
|
uni1.interface.switch = "00:00:00:00:00:00:00:01" |
| 1574 |
|
uni2.interface.switch = "00:00:00:00:00:00:00:02" |
| 1575 |
|
uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2] |
| 1576 |
|
|
| 1577 |
|
api = self.get_app_test_client(self.napp) |
| 1578 |
|
payload1 = { |
| 1579 |
|
"name": "my evc1", |
| 1580 |
|
"uni_a": { |
| 1581 |
|
"interface_id": "00:00:00:00:00:00:00:01:1", |
| 1582 |
|
"tag": {"tag_type": 1, "value": 80}, |
| 1583 |
|
}, |
| 1584 |
|
"uni_z": { |
| 1585 |
|
"interface_id": "00:00:00:00:00:00:00:02:2", |
| 1586 |
|
"tag": {"tag_type": 1, "value": 1}, |
| 1587 |
|
}, |
| 1588 |
|
"dynamic_backup_path": True, |
| 1589 |
|
} |
| 1590 |
|
|
| 1591 |
|
payload2 = { |
| 1592 |
|
"dynamic_backup_path": False, |
| 1593 |
|
} |
| 1594 |
|
|
| 1595 |
|
evc_as_dict_mock.return_value = payload1 |
| 1596 |
|
response = api.post( |
| 1597 |
|
f"{self.server_name_url}/v2/evc/", |
| 1598 |
|
data=json.dumps(payload1), |
| 1599 |
|
content_type="application/json", |
| 1600 |
|
) |
| 1601 |
|
self.assertEqual(201, response.status_code) |
| 1602 |
|
|
| 1603 |
|
evc_as_dict_mock.return_value = payload2 |
| 1604 |
|
current_data = json.loads(response.data) |
| 1605 |
|
circuit_id = current_data["circuit_id"] |
| 1606 |
|
response = api.patch( |
| 1607 |
|
f"{self.server_name_url}/v2/evc/{circuit_id}", |
| 1608 |
|
data=payload2, |
| 1609 |
|
content_type="application/json", |
| 1610 |
|
) |
| 1611 |
|
current_data = json.loads(response.data) |
| 1612 |
|
expected_data = "The request body is not a well-formed JSON." |
| 1613 |
|
self.assertEqual(current_data["description"], expected_data) |
| 1614 |
|
self.assertEqual(400, response.status_code) |
| 1615 |
|
|
| 1616 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC.deploy") |
| 1617 |
|
@patch("napps.kytos.mef_eline.scheduler.Scheduler.add") |
|
@@ 1715-1774 (lines=60) @@
|
| 1712 |
|
with self.assertRaises(ValueError): |
| 1713 |
|
self.napp._uni_from_dict(uni_dict) |
| 1714 |
|
|
| 1715 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC.deploy") |
| 1716 |
|
@patch("napps.kytos.mef_eline.scheduler.Scheduler.add") |
| 1717 |
|
@patch("napps.kytos.mef_eline.main.Main._uni_from_dict") |
| 1718 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC._validate") |
| 1719 |
|
@patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc") |
| 1720 |
|
def test_update_evc_no_json_mime(self, *args): |
| 1721 |
|
"""Test update a circuit with wrong mimetype.""" |
| 1722 |
|
# pylint: disable=too-many-locals |
| 1723 |
|
( |
| 1724 |
|
mongo_controller_upsert_mock, |
| 1725 |
|
validate_mock, |
| 1726 |
|
uni_from_dict_mock, |
| 1727 |
|
sched_add_mock, |
| 1728 |
|
evc_deploy_mock, |
| 1729 |
|
) = args |
| 1730 |
|
|
| 1731 |
|
validate_mock.return_value = True |
| 1732 |
|
sched_add_mock.return_value = True |
| 1733 |
|
evc_deploy_mock.return_value = True |
| 1734 |
|
uni1 = create_autospec(UNI) |
| 1735 |
|
uni2 = create_autospec(UNI) |
| 1736 |
|
uni1.interface = create_autospec(Interface) |
| 1737 |
|
uni2.interface = create_autospec(Interface) |
| 1738 |
|
uni1.interface.switch = "00:00:00:00:00:00:00:01" |
| 1739 |
|
uni2.interface.switch = "00:00:00:00:00:00:00:02" |
| 1740 |
|
uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2] |
| 1741 |
|
mongo_controller_upsert_mock.return_value = True |
| 1742 |
|
|
| 1743 |
|
api = self.get_app_test_client(self.napp) |
| 1744 |
|
payload1 = { |
| 1745 |
|
"name": "my evc1", |
| 1746 |
|
"uni_a": { |
| 1747 |
|
"interface_id": "00:00:00:00:00:00:00:01:1", |
| 1748 |
|
"tag": {"tag_type": 1, "value": 80}, |
| 1749 |
|
}, |
| 1750 |
|
"uni_z": { |
| 1751 |
|
"interface_id": "00:00:00:00:00:00:00:02:2", |
| 1752 |
|
"tag": {"tag_type": 1, "value": 1}, |
| 1753 |
|
}, |
| 1754 |
|
"dynamic_backup_path": True, |
| 1755 |
|
} |
| 1756 |
|
|
| 1757 |
|
payload2 = {"dynamic_backup_path": False} |
| 1758 |
|
|
| 1759 |
|
response = api.post( |
| 1760 |
|
f"{self.server_name_url}/v2/evc/", |
| 1761 |
|
data=json.dumps(payload1), |
| 1762 |
|
content_type="application/json", |
| 1763 |
|
) |
| 1764 |
|
self.assertEqual(201, response.status_code) |
| 1765 |
|
|
| 1766 |
|
current_data = json.loads(response.data) |
| 1767 |
|
circuit_id = current_data["circuit_id"] |
| 1768 |
|
response = api.patch( |
| 1769 |
|
f"{self.server_name_url}/v2/evc/{circuit_id}", data=payload2 |
| 1770 |
|
) |
| 1771 |
|
current_data = json.loads(response.data) |
| 1772 |
|
expected_data = "The request body mimetype is not application/json." |
| 1773 |
|
self.assertEqual(current_data["description"], expected_data) |
| 1774 |
|
self.assertEqual(415, response.status_code) |
| 1775 |
|
|
| 1776 |
|
def test_delete_no_evc(self): |
| 1777 |
|
"""Test delete when EVC does not exist.""" |