Code Duplication    Length = 65-72 lines in 2 locations

tests/unit/test_main.py 2 locations

@@ 1453-1524 (lines=72) @@
1450
        assert 200 == response.status_code
1451
        evc_deploy.assert_called_once()
1452
1453
    @patch("napps.kytos.mef_eline.main.Main._check_no_tag_duplication")
1454
    @patch("napps.kytos.mef_eline.models.evc.EVC._tag_lists_equal")
1455
    @patch("napps.kytos.mef_eline.main.Main._use_uni_tags")
1456
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1457
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
1458
    @patch("napps.kytos.mef_eline.main.Main._uni_from_dict")
1459
    @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
1460
    @patch("napps.kytos.mef_eline.models.evc.EVC._validate")
1461
    @patch("napps.kytos.mef_eline.main.EVC.as_dict")
1462
    async def test_update_circuit_invalid_json(
1463
        self,
1464
        evc_as_dict_mock,
1465
        validate_mock,
1466
        mongo_controller_upsert_mock,
1467
        uni_from_dict_mock,
1468
        sched_add_mock,
1469
        evc_deploy_mock,
1470
        mock_use_uni_tags,
1471
        mock_tags_equal,
1472
        mock_check_duplicate
1473
    ):
1474
        """Test update a circuit circuit."""
1475
        self.napp.controller.loop = asyncio.get_running_loop()
1476
        validate_mock.return_value = True
1477
        mongo_controller_upsert_mock.return_value = True
1478
        sched_add_mock.return_value = True
1479
        evc_deploy_mock.return_value = True
1480
        mock_use_uni_tags.return_value = True
1481
        mock_tags_equal.return_value = True
1482
        mock_check_duplicate.return_value = True
1483
        uni1 = create_autospec(UNI)
1484
        uni2 = create_autospec(UNI)
1485
        uni1.interface = create_autospec(Interface)
1486
        uni2.interface = create_autospec(Interface)
1487
        uni1.interface.switch = "00:00:00:00:00:00:00:01"
1488
        uni2.interface.switch = "00:00:00:00:00:00:00:02"
1489
        uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2]
1490
1491
        payload1 = {
1492
            "name": "my evc1",
1493
            "uni_a": {
1494
                "interface_id": "00:00:00:00:00:00:00:01:1",
1495
                "tag": {"tag_type": 'vlan', "value": 80},
1496
            },
1497
            "uni_z": {
1498
                "interface_id": "00:00:00:00:00:00:00:02:2",
1499
                "tag": {"tag_type": 'vlan', "value": 1},
1500
            },
1501
            "dynamic_backup_path": True,
1502
        }
1503
1504
        payload2 = {
1505
            "dynamic_backup_path": False,
1506
        }
1507
1508
        evc_as_dict_mock.return_value = payload1
1509
        response = await self.api_client.post(
1510
            f"{self.base_endpoint}/v2/evc/",
1511
            json=payload1
1512
        )
1513
        assert 201 == response.status_code
1514
1515
        evc_as_dict_mock.return_value = payload2
1516
        current_data = response.json()
1517
        circuit_id = current_data["circuit_id"]
1518
        response = await self.api_client.patch(
1519
            f"{self.base_endpoint}/v2/evc/{circuit_id}",
1520
            json=payload2
1521
        )
1522
        current_data = response.json()
1523
        assert 400 == response.status_code
1524
        assert "must have a primary path or" in current_data["description"]
1525
1526
    @patch("napps.kytos.mef_eline.main.Main._check_no_tag_duplication")
1527
    @patch("napps.kytos.mef_eline.models.evc.EVC._tag_lists_equal")
@@ 1650-1714 (lines=65) @@
1647
        with pytest.raises(ValueError):
1648
            self.napp._uni_from_dict(uni_dict)
1649
1650
    @patch("napps.kytos.mef_eline.main.Main._check_no_tag_duplication")
1651
    @patch("napps.kytos.mef_eline.models.evc.EVC._tag_lists_equal")
1652
    @patch("napps.kytos.mef_eline.main.Main._use_uni_tags")
1653
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1654
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
1655
    @patch("napps.kytos.mef_eline.main.Main._uni_from_dict")
1656
    @patch("napps.kytos.mef_eline.models.evc.EVC._validate")
1657
    @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
1658
    async def test_update_evc_no_json_mime(
1659
        self,
1660
        mongo_controller_upsert_mock,
1661
        validate_mock,
1662
        uni_from_dict_mock,
1663
        sched_add_mock,
1664
        evc_deploy_mock,
1665
        mock_use_uni_tags,
1666
        mock_tags_equal,
1667
        mock_check_duplicate
1668
    ):
1669
        """Test update a circuit with wrong mimetype."""
1670
        self.napp.controller.loop = asyncio.get_running_loop()
1671
        validate_mock.return_value = True
1672
        sched_add_mock.return_value = True
1673
        evc_deploy_mock.return_value = True
1674
        mock_use_uni_tags.return_value = True
1675
        mock_tags_equal.return_value = True
1676
        mock_check_duplicate.return_value = True
1677
        uni1 = create_autospec(UNI)
1678
        uni2 = create_autospec(UNI)
1679
        uni1.interface = create_autospec(Interface)
1680
        uni2.interface = create_autospec(Interface)
1681
        uni1.interface.switch = "00:00:00:00:00:00:00:01"
1682
        uni2.interface.switch = "00:00:00:00:00:00:00:02"
1683
        uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2]
1684
        mongo_controller_upsert_mock.return_value = True
1685
1686
        payload1 = {
1687
            "name": "my evc1",
1688
            "uni_a": {
1689
                "interface_id": "00:00:00:00:00:00:00:01:1",
1690
                "tag": {"tag_type": 'vlan', "value": 80},
1691
            },
1692
            "uni_z": {
1693
                "interface_id": "00:00:00:00:00:00:00:02:2",
1694
                "tag": {"tag_type": 'vlan', "value": 1},
1695
            },
1696
            "dynamic_backup_path": True,
1697
        }
1698
1699
        payload2 = {"dynamic_backup_path": False}
1700
1701
        response = await self.api_client.post(
1702
            f"{self.base_endpoint}/v2/evc/",
1703
            json=payload1,
1704
        )
1705
        assert 201 == response.status_code
1706
1707
        current_data = response.json()
1708
        circuit_id = current_data["circuit_id"]
1709
        response = await self.api_client.patch(
1710
            f"{self.base_endpoint}/v2/evc/{circuit_id}", data=payload2
1711
        )
1712
        current_data = response.json()
1713
        assert 415 == response.status_code
1714
        assert "application/json" in current_data["description"]
1715
1716
    async def test_delete_no_evc(self):
1717
        """Test delete when EVC does not exist."""