@@ 1557-1628 (lines=72) @@ | ||
1554 | assert 200 == response.status_code |
|
1555 | evc_deploy.assert_called_once() |
|
1556 | ||
1557 | @patch("napps.kytos.mef_eline.main.Main._check_no_tag_duplication") |
|
1558 | @patch("napps.kytos.mef_eline.models.evc.EVC._tag_lists_equal") |
|
1559 | @patch("napps.kytos.mef_eline.main.Main._use_uni_tags") |
|
1560 | @patch("napps.kytos.mef_eline.models.evc.EVC.deploy") |
|
1561 | @patch("napps.kytos.mef_eline.scheduler.Scheduler.add") |
|
1562 | @patch("napps.kytos.mef_eline.main.Main._uni_from_dict") |
|
1563 | @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc") |
|
1564 | @patch("napps.kytos.mef_eline.models.evc.EVC._validate") |
|
1565 | @patch("napps.kytos.mef_eline.main.EVC.as_dict") |
|
1566 | async def test_update_circuit_invalid_json( |
|
1567 | self, |
|
1568 | evc_as_dict_mock, |
|
1569 | validate_mock, |
|
1570 | mongo_controller_upsert_mock, |
|
1571 | uni_from_dict_mock, |
|
1572 | sched_add_mock, |
|
1573 | evc_deploy_mock, |
|
1574 | mock_use_uni_tags, |
|
1575 | mock_tags_equal, |
|
1576 | mock_check_duplicate |
|
1577 | ): |
|
1578 | """Test update a circuit circuit.""" |
|
1579 | self.napp.controller.loop = asyncio.get_running_loop() |
|
1580 | validate_mock.return_value = True |
|
1581 | mongo_controller_upsert_mock.return_value = True |
|
1582 | sched_add_mock.return_value = True |
|
1583 | evc_deploy_mock.return_value = True |
|
1584 | mock_use_uni_tags.return_value = True |
|
1585 | mock_tags_equal.return_value = True |
|
1586 | mock_check_duplicate.return_value = True |
|
1587 | uni1 = create_autospec(UNI) |
|
1588 | uni2 = create_autospec(UNI) |
|
1589 | uni1.interface = create_autospec(Interface) |
|
1590 | uni2.interface = create_autospec(Interface) |
|
1591 | uni1.interface.switch = "00:00:00:00:00:00:00:01" |
|
1592 | uni2.interface.switch = "00:00:00:00:00:00:00:02" |
|
1593 | uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2] |
|
1594 | ||
1595 | payload1 = { |
|
1596 | "name": "my evc1", |
|
1597 | "uni_a": { |
|
1598 | "interface_id": "00:00:00:00:00:00:00:01:1", |
|
1599 | "tag": {"tag_type": 'vlan', "value": 80}, |
|
1600 | }, |
|
1601 | "uni_z": { |
|
1602 | "interface_id": "00:00:00:00:00:00:00:02:2", |
|
1603 | "tag": {"tag_type": 'vlan', "value": 1}, |
|
1604 | }, |
|
1605 | "dynamic_backup_path": True, |
|
1606 | } |
|
1607 | ||
1608 | payload2 = { |
|
1609 | "dynamic_backup_path": False, |
|
1610 | } |
|
1611 | ||
1612 | evc_as_dict_mock.return_value = payload1 |
|
1613 | response = await self.api_client.post( |
|
1614 | f"{self.base_endpoint}/v2/evc/", |
|
1615 | json=payload1 |
|
1616 | ) |
|
1617 | assert 201 == response.status_code |
|
1618 | ||
1619 | evc_as_dict_mock.return_value = payload2 |
|
1620 | current_data = response.json() |
|
1621 | circuit_id = current_data["circuit_id"] |
|
1622 | response = await self.api_client.patch( |
|
1623 | f"{self.base_endpoint}/v2/evc/{circuit_id}", |
|
1624 | json=payload2 |
|
1625 | ) |
|
1626 | current_data = response.json() |
|
1627 | assert 400 == response.status_code |
|
1628 | assert "must have a primary path or" in current_data["description"] |
|
1629 | ||
1630 | @patch("napps.kytos.mef_eline.main.Main._check_no_tag_duplication") |
|
1631 | @patch("napps.kytos.mef_eline.models.evc.EVC._tag_lists_equal") |
|
@@ 1754-1818 (lines=65) @@ | ||
1751 | with pytest.raises(ValueError): |
|
1752 | self.napp._uni_from_dict(uni_dict) |
|
1753 | ||
1754 | @patch("napps.kytos.mef_eline.main.Main._check_no_tag_duplication") |
|
1755 | @patch("napps.kytos.mef_eline.models.evc.EVC._tag_lists_equal") |
|
1756 | @patch("napps.kytos.mef_eline.main.Main._use_uni_tags") |
|
1757 | @patch("napps.kytos.mef_eline.models.evc.EVC.deploy") |
|
1758 | @patch("napps.kytos.mef_eline.scheduler.Scheduler.add") |
|
1759 | @patch("napps.kytos.mef_eline.main.Main._uni_from_dict") |
|
1760 | @patch("napps.kytos.mef_eline.models.evc.EVC._validate") |
|
1761 | @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc") |
|
1762 | async def test_update_evc_no_json_mime( |
|
1763 | self, |
|
1764 | mongo_controller_upsert_mock, |
|
1765 | validate_mock, |
|
1766 | uni_from_dict_mock, |
|
1767 | sched_add_mock, |
|
1768 | evc_deploy_mock, |
|
1769 | mock_use_uni_tags, |
|
1770 | mock_tags_equal, |
|
1771 | mock_check_duplicate |
|
1772 | ): |
|
1773 | """Test update a circuit with wrong mimetype.""" |
|
1774 | self.napp.controller.loop = asyncio.get_running_loop() |
|
1775 | validate_mock.return_value = True |
|
1776 | sched_add_mock.return_value = True |
|
1777 | evc_deploy_mock.return_value = True |
|
1778 | mock_use_uni_tags.return_value = True |
|
1779 | mock_tags_equal.return_value = True |
|
1780 | mock_check_duplicate.return_value = True |
|
1781 | uni1 = create_autospec(UNI) |
|
1782 | uni2 = create_autospec(UNI) |
|
1783 | uni1.interface = create_autospec(Interface) |
|
1784 | uni2.interface = create_autospec(Interface) |
|
1785 | uni1.interface.switch = "00:00:00:00:00:00:00:01" |
|
1786 | uni2.interface.switch = "00:00:00:00:00:00:00:02" |
|
1787 | uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2] |
|
1788 | mongo_controller_upsert_mock.return_value = True |
|
1789 | ||
1790 | payload1 = { |
|
1791 | "name": "my evc1", |
|
1792 | "uni_a": { |
|
1793 | "interface_id": "00:00:00:00:00:00:00:01:1", |
|
1794 | "tag": {"tag_type": 'vlan', "value": 80}, |
|
1795 | }, |
|
1796 | "uni_z": { |
|
1797 | "interface_id": "00:00:00:00:00:00:00:02:2", |
|
1798 | "tag": {"tag_type": 'vlan', "value": 1}, |
|
1799 | }, |
|
1800 | "dynamic_backup_path": True, |
|
1801 | } |
|
1802 | ||
1803 | payload2 = {"dynamic_backup_path": False} |
|
1804 | ||
1805 | response = await self.api_client.post( |
|
1806 | f"{self.base_endpoint}/v2/evc/", |
|
1807 | json=payload1, |
|
1808 | ) |
|
1809 | assert 201 == response.status_code |
|
1810 | ||
1811 | current_data = response.json() |
|
1812 | circuit_id = current_data["circuit_id"] |
|
1813 | response = await self.api_client.patch( |
|
1814 | f"{self.base_endpoint}/v2/evc/{circuit_id}", data=payload2 |
|
1815 | ) |
|
1816 | current_data = response.json() |
|
1817 | assert 415 == response.status_code |
|
1818 | assert "application/json" in current_data["description"] |
|
1819 | ||
1820 | async def test_delete_no_evc(self): |
|
1821 | """Test delete when EVC does not exist.""" |