Code Duplication    Length = 65-72 lines in 2 locations

tests/unit/test_main.py 2 locations

@@ 1450-1521 (lines=72) @@
1447
        assert 200 == response.status_code
1448
        evc_deploy.assert_called_once()
1449
1450
    @patch("napps.kytos.mef_eline.main.Main._check_no_tag_duplication")
1451
    @patch("napps.kytos.mef_eline.models.evc.EVC._tag_lists_equal")
1452
    @patch("napps.kytos.mef_eline.main.Main._use_uni_tags")
1453
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1454
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
1455
    @patch("napps.kytos.mef_eline.main.Main._uni_from_dict")
1456
    @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
1457
    @patch("napps.kytos.mef_eline.models.evc.EVC._validate")
1458
    @patch("napps.kytos.mef_eline.main.EVC.as_dict")
1459
    async def test_update_circuit_invalid_json(
1460
        self,
1461
        evc_as_dict_mock,
1462
        validate_mock,
1463
        mongo_controller_upsert_mock,
1464
        uni_from_dict_mock,
1465
        sched_add_mock,
1466
        evc_deploy_mock,
1467
        mock_use_uni_tags,
1468
        mock_tags_equal,
1469
        mock_check_duplicate
1470
    ):
1471
        """Test update a circuit circuit."""
1472
        self.napp.controller.loop = asyncio.get_running_loop()
1473
        validate_mock.return_value = True
1474
        mongo_controller_upsert_mock.return_value = True
1475
        sched_add_mock.return_value = True
1476
        evc_deploy_mock.return_value = True
1477
        mock_use_uni_tags.return_value = True
1478
        mock_tags_equal.return_value = True
1479
        mock_check_duplicate.return_value = True
1480
        uni1 = create_autospec(UNI)
1481
        uni2 = create_autospec(UNI)
1482
        uni1.interface = create_autospec(Interface)
1483
        uni2.interface = create_autospec(Interface)
1484
        uni1.interface.switch = "00:00:00:00:00:00:00:01"
1485
        uni2.interface.switch = "00:00:00:00:00:00:00:02"
1486
        uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2]
1487
1488
        payload1 = {
1489
            "name": "my evc1",
1490
            "uni_a": {
1491
                "interface_id": "00:00:00:00:00:00:00:01:1",
1492
                "tag": {"tag_type": 'vlan', "value": 80},
1493
            },
1494
            "uni_z": {
1495
                "interface_id": "00:00:00:00:00:00:00:02:2",
1496
                "tag": {"tag_type": 'vlan', "value": 1},
1497
            },
1498
            "dynamic_backup_path": True,
1499
        }
1500
1501
        payload2 = {
1502
            "dynamic_backup_path": False,
1503
        }
1504
1505
        evc_as_dict_mock.return_value = payload1
1506
        response = await self.api_client.post(
1507
            f"{self.base_endpoint}/v2/evc/",
1508
            json=payload1
1509
        )
1510
        assert 201 == response.status_code
1511
1512
        evc_as_dict_mock.return_value = payload2
1513
        current_data = response.json()
1514
        circuit_id = current_data["circuit_id"]
1515
        response = await self.api_client.patch(
1516
            f"{self.base_endpoint}/v2/evc/{circuit_id}",
1517
            json=payload2
1518
        )
1519
        current_data = response.json()
1520
        assert 400 == response.status_code
1521
        assert "must have a primary path or" in current_data["description"]
1522
1523
    @patch("napps.kytos.mef_eline.main.Main._check_no_tag_duplication")
1524
    @patch("napps.kytos.mef_eline.models.evc.EVC._tag_lists_equal")
@@ 1719-1783 (lines=65) @@
1716
        with pytest.raises(ValueError):
1717
            self.napp._uni_from_dict(uni_dict)
1718
1719
    @patch("napps.kytos.mef_eline.main.Main._check_no_tag_duplication")
1720
    @patch("napps.kytos.mef_eline.models.evc.EVC._tag_lists_equal")
1721
    @patch("napps.kytos.mef_eline.main.Main._use_uni_tags")
1722
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1723
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
1724
    @patch("napps.kytos.mef_eline.main.Main._uni_from_dict")
1725
    @patch("napps.kytos.mef_eline.models.evc.EVC._validate")
1726
    @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
1727
    async def test_update_evc_no_json_mime(
1728
        self,
1729
        mongo_controller_upsert_mock,
1730
        validate_mock,
1731
        uni_from_dict_mock,
1732
        sched_add_mock,
1733
        evc_deploy_mock,
1734
        mock_use_uni_tags,
1735
        mock_tags_equal,
1736
        mock_check_duplicate
1737
    ):
1738
        """Test update a circuit with wrong mimetype."""
1739
        self.napp.controller.loop = asyncio.get_running_loop()
1740
        validate_mock.return_value = True
1741
        sched_add_mock.return_value = True
1742
        evc_deploy_mock.return_value = True
1743
        mock_use_uni_tags.return_value = True
1744
        mock_tags_equal.return_value = True
1745
        mock_check_duplicate.return_value = True
1746
        uni1 = create_autospec(UNI)
1747
        uni2 = create_autospec(UNI)
1748
        uni1.interface = create_autospec(Interface)
1749
        uni2.interface = create_autospec(Interface)
1750
        uni1.interface.switch = "00:00:00:00:00:00:00:01"
1751
        uni2.interface.switch = "00:00:00:00:00:00:00:02"
1752
        uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2]
1753
        mongo_controller_upsert_mock.return_value = True
1754
1755
        payload1 = {
1756
            "name": "my evc1",
1757
            "uni_a": {
1758
                "interface_id": "00:00:00:00:00:00:00:01:1",
1759
                "tag": {"tag_type": 'vlan', "value": 80},
1760
            },
1761
            "uni_z": {
1762
                "interface_id": "00:00:00:00:00:00:00:02:2",
1763
                "tag": {"tag_type": 'vlan', "value": 1},
1764
            },
1765
            "dynamic_backup_path": True,
1766
        }
1767
1768
        payload2 = {"dynamic_backup_path": False}
1769
1770
        response = await self.api_client.post(
1771
            f"{self.base_endpoint}/v2/evc/",
1772
            json=payload1,
1773
        )
1774
        assert 201 == response.status_code
1775
1776
        current_data = response.json()
1777
        circuit_id = current_data["circuit_id"]
1778
        response = await self.api_client.patch(
1779
            f"{self.base_endpoint}/v2/evc/{circuit_id}", data=payload2
1780
        )
1781
        current_data = response.json()
1782
        assert 415 == response.status_code
1783
        assert "application/json" in current_data["description"]
1784
1785
    async def test_delete_no_evc(self):
1786
        """Test delete when EVC does not exist."""