|
@@ 627-691 (lines=65) @@
|
| 624 |
|
assert response.status_code == 400 |
| 625 |
|
assert expected_data in current_data["description"] |
| 626 |
|
|
| 627 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC._tag_lists_equal") |
| 628 |
|
@patch("napps.kytos.mef_eline.main.Main._use_uni_tags") |
| 629 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC.deploy") |
| 630 |
|
@patch("napps.kytos.mef_eline.scheduler.Scheduler.add") |
| 631 |
|
@patch("napps.kytos.mef_eline.main.Main._uni_from_dict") |
| 632 |
|
@patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc") |
| 633 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC._validate") |
| 634 |
|
@patch("napps.kytos.mef_eline.main.EVC.as_dict") |
| 635 |
|
async def test_create_circuit_already_enabled( |
| 636 |
|
self, |
| 637 |
|
evc_as_dict_mock, |
| 638 |
|
validate_mock, |
| 639 |
|
mongo_controller_upsert_mock, |
| 640 |
|
uni_from_dict_mock, |
| 641 |
|
sched_add_mock, |
| 642 |
|
evc_deploy_mock, |
| 643 |
|
mock_use_uni_tags, |
| 644 |
|
mock_tags_equal, |
| 645 |
|
event_loop |
| 646 |
|
): |
| 647 |
|
"""Test create an already created circuit.""" |
| 648 |
|
# pylint: disable=too-many-locals |
| 649 |
|
self.napp.controller.loop = event_loop |
| 650 |
|
validate_mock.return_value = True |
| 651 |
|
mongo_controller_upsert_mock.return_value = True |
| 652 |
|
sched_add_mock.return_value = True |
| 653 |
|
evc_deploy_mock.return_value = True |
| 654 |
|
mock_use_uni_tags.return_value = True |
| 655 |
|
mock_tags_equal.return_value = True |
| 656 |
|
uni1 = create_autospec(UNI) |
| 657 |
|
uni2 = create_autospec(UNI) |
| 658 |
|
uni1.interface = create_autospec(Interface) |
| 659 |
|
uni2.interface = create_autospec(Interface) |
| 660 |
|
uni1.interface.switch = "00:00:00:00:00:00:00:01" |
| 661 |
|
uni2.interface.switch = "00:00:00:00:00:00:00:02" |
| 662 |
|
uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2] |
| 663 |
|
|
| 664 |
|
payload = { |
| 665 |
|
"name": "my evc1", |
| 666 |
|
"uni_a": { |
| 667 |
|
"interface_id": "00:00:00:00:00:00:00:01:1", |
| 668 |
|
"tag": {"tag_type": 'vlan', "value": 80}, |
| 669 |
|
}, |
| 670 |
|
"uni_z": { |
| 671 |
|
"interface_id": "00:00:00:00:00:00:00:02:2", |
| 672 |
|
"tag": {"tag_type": 'vlan', "value": 1}, |
| 673 |
|
}, |
| 674 |
|
"dynamic_backup_path": True, |
| 675 |
|
} |
| 676 |
|
|
| 677 |
|
evc_as_dict_mock.return_value = payload |
| 678 |
|
response = await self.api_client.post( |
| 679 |
|
f"{self.base_endpoint}/v2/evc/", |
| 680 |
|
json=payload |
| 681 |
|
) |
| 682 |
|
assert 201 == response.status_code |
| 683 |
|
|
| 684 |
|
response = await self.api_client.post( |
| 685 |
|
f"{self.base_endpoint}/v2/evc/", |
| 686 |
|
json=payload |
| 687 |
|
) |
| 688 |
|
current_data = response.json() |
| 689 |
|
expected_data = "The EVC already exists." |
| 690 |
|
assert current_data["description"] == expected_data |
| 691 |
|
assert 409 == response.status_code |
| 692 |
|
|
| 693 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC._tag_lists_equal") |
| 694 |
|
@patch("napps.kytos.mef_eline.main.Main._uni_from_dict") |
|
@@ 1803-1865 (lines=63) @@
|
| 1800 |
|
with pytest.raises(ValueError): |
| 1801 |
|
self.napp._uni_from_dict(uni_dict) |
| 1802 |
|
|
| 1803 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC._tag_lists_equal") |
| 1804 |
|
@patch("napps.kytos.mef_eline.main.Main._use_uni_tags") |
| 1805 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC.deploy") |
| 1806 |
|
@patch("napps.kytos.mef_eline.scheduler.Scheduler.add") |
| 1807 |
|
@patch("napps.kytos.mef_eline.main.Main._uni_from_dict") |
| 1808 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC._validate") |
| 1809 |
|
@patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc") |
| 1810 |
|
async def test_update_evc_no_json_mime( |
| 1811 |
|
self, |
| 1812 |
|
mongo_controller_upsert_mock, |
| 1813 |
|
validate_mock, |
| 1814 |
|
uni_from_dict_mock, |
| 1815 |
|
sched_add_mock, |
| 1816 |
|
evc_deploy_mock, |
| 1817 |
|
mock_use_uni_tags, |
| 1818 |
|
mock_tags_equal, |
| 1819 |
|
event_loop |
| 1820 |
|
): |
| 1821 |
|
"""Test update a circuit with wrong mimetype.""" |
| 1822 |
|
self.napp.controller.loop = event_loop |
| 1823 |
|
validate_mock.return_value = True |
| 1824 |
|
sched_add_mock.return_value = True |
| 1825 |
|
evc_deploy_mock.return_value = True |
| 1826 |
|
mock_use_uni_tags.return_value = True |
| 1827 |
|
mock_tags_equal.return_value = True |
| 1828 |
|
uni1 = create_autospec(UNI) |
| 1829 |
|
uni2 = create_autospec(UNI) |
| 1830 |
|
uni1.interface = create_autospec(Interface) |
| 1831 |
|
uni2.interface = create_autospec(Interface) |
| 1832 |
|
uni1.interface.switch = "00:00:00:00:00:00:00:01" |
| 1833 |
|
uni2.interface.switch = "00:00:00:00:00:00:00:02" |
| 1834 |
|
uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2] |
| 1835 |
|
mongo_controller_upsert_mock.return_value = True |
| 1836 |
|
|
| 1837 |
|
payload1 = { |
| 1838 |
|
"name": "my evc1", |
| 1839 |
|
"uni_a": { |
| 1840 |
|
"interface_id": "00:00:00:00:00:00:00:01:1", |
| 1841 |
|
"tag": {"tag_type": 'vlan', "value": 80}, |
| 1842 |
|
}, |
| 1843 |
|
"uni_z": { |
| 1844 |
|
"interface_id": "00:00:00:00:00:00:00:02:2", |
| 1845 |
|
"tag": {"tag_type": 'vlan', "value": 1}, |
| 1846 |
|
}, |
| 1847 |
|
"dynamic_backup_path": True, |
| 1848 |
|
} |
| 1849 |
|
|
| 1850 |
|
payload2 = {"dynamic_backup_path": False} |
| 1851 |
|
|
| 1852 |
|
response = await self.api_client.post( |
| 1853 |
|
f"{self.base_endpoint}/v2/evc/", |
| 1854 |
|
json=payload1, |
| 1855 |
|
) |
| 1856 |
|
assert 201 == response.status_code |
| 1857 |
|
|
| 1858 |
|
current_data = response.json() |
| 1859 |
|
circuit_id = current_data["circuit_id"] |
| 1860 |
|
response = await self.api_client.patch( |
| 1861 |
|
f"{self.base_endpoint}/v2/evc/{circuit_id}", data=payload2 |
| 1862 |
|
) |
| 1863 |
|
current_data = response.json() |
| 1864 |
|
assert 415 == response.status_code |
| 1865 |
|
assert "application/json" in current_data["description"] |
| 1866 |
|
|
| 1867 |
|
async def test_delete_no_evc(self): |
| 1868 |
|
"""Test delete when EVC does not exist.""" |