Code Duplication    Length = 65-72 lines in 2 locations

tests/unit/test_main.py 2 locations

@@ 1435-1506 (lines=72) @@
1432
        assert 200 == response.status_code
1433
        evc_deploy.assert_called_once()
1434
1435
    @patch("napps.kytos.mef_eline.main.Main._check_no_tag_duplication")
1436
    @patch("napps.kytos.mef_eline.models.evc.EVC._tag_lists_equal")
1437
    @patch("napps.kytos.mef_eline.main.Main._use_uni_tags")
1438
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1439
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
1440
    @patch("napps.kytos.mef_eline.main.Main._uni_from_dict")
1441
    @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
1442
    @patch("napps.kytos.mef_eline.models.evc.EVC._validate")
1443
    @patch("napps.kytos.mef_eline.main.EVC.as_dict")
1444
    async def test_update_circuit_invalid_json(
1445
        self,
1446
        evc_as_dict_mock,
1447
        validate_mock,
1448
        mongo_controller_upsert_mock,
1449
        uni_from_dict_mock,
1450
        sched_add_mock,
1451
        evc_deploy_mock,
1452
        mock_use_uni_tags,
1453
        mock_tags_equal,
1454
        mock_check_duplicate
1455
    ):
1456
        """Test update a circuit circuit."""
1457
        self.napp.controller.loop = asyncio.get_running_loop()
1458
        validate_mock.return_value = True
1459
        mongo_controller_upsert_mock.return_value = True
1460
        sched_add_mock.return_value = True
1461
        evc_deploy_mock.return_value = True
1462
        mock_use_uni_tags.return_value = True
1463
        mock_tags_equal.return_value = True
1464
        mock_check_duplicate.return_value = True
1465
        uni1 = create_autospec(UNI)
1466
        uni2 = create_autospec(UNI)
1467
        uni1.interface = create_autospec(Interface)
1468
        uni2.interface = create_autospec(Interface)
1469
        uni1.interface.switch = "00:00:00:00:00:00:00:01"
1470
        uni2.interface.switch = "00:00:00:00:00:00:00:02"
1471
        uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2]
1472
1473
        payload1 = {
1474
            "name": "my evc1",
1475
            "uni_a": {
1476
                "interface_id": "00:00:00:00:00:00:00:01:1",
1477
                "tag": {"tag_type": 'vlan', "value": 80},
1478
            },
1479
            "uni_z": {
1480
                "interface_id": "00:00:00:00:00:00:00:02:2",
1481
                "tag": {"tag_type": 'vlan', "value": 1},
1482
            },
1483
            "dynamic_backup_path": True,
1484
        }
1485
1486
        payload2 = {
1487
            "dynamic_backup_path": False,
1488
        }
1489
1490
        evc_as_dict_mock.return_value = payload1
1491
        response = await self.api_client.post(
1492
            f"{self.base_endpoint}/v2/evc/",
1493
            json=payload1
1494
        )
1495
        assert 201 == response.status_code
1496
1497
        evc_as_dict_mock.return_value = payload2
1498
        current_data = response.json()
1499
        circuit_id = current_data["circuit_id"]
1500
        response = await self.api_client.patch(
1501
            f"{self.base_endpoint}/v2/evc/{circuit_id}",
1502
            json=payload2
1503
        )
1504
        current_data = response.json()
1505
        assert 400 == response.status_code
1506
        assert "must have a primary path or" in current_data["description"]
1507
1508
    @patch("napps.kytos.mef_eline.main.Main._check_no_tag_duplication")
1509
    @patch("napps.kytos.mef_eline.models.evc.EVC._tag_lists_equal")
@@ 1684-1748 (lines=65) @@
1681
        with pytest.raises(ValueError):
1682
            self.napp._uni_from_dict(uni_dict)
1683
1684
    @patch("napps.kytos.mef_eline.main.Main._check_no_tag_duplication")
1685
    @patch("napps.kytos.mef_eline.models.evc.EVC._tag_lists_equal")
1686
    @patch("napps.kytos.mef_eline.main.Main._use_uni_tags")
1687
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1688
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
1689
    @patch("napps.kytos.mef_eline.main.Main._uni_from_dict")
1690
    @patch("napps.kytos.mef_eline.models.evc.EVC._validate")
1691
    @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
1692
    async def test_update_evc_no_json_mime(
1693
        self,
1694
        mongo_controller_upsert_mock,
1695
        validate_mock,
1696
        uni_from_dict_mock,
1697
        sched_add_mock,
1698
        evc_deploy_mock,
1699
        mock_use_uni_tags,
1700
        mock_tags_equal,
1701
        mock_check_duplicate
1702
    ):
1703
        """Test update a circuit with wrong mimetype."""
1704
        self.napp.controller.loop = asyncio.get_running_loop()
1705
        validate_mock.return_value = True
1706
        sched_add_mock.return_value = True
1707
        evc_deploy_mock.return_value = True
1708
        mock_use_uni_tags.return_value = True
1709
        mock_tags_equal.return_value = True
1710
        mock_check_duplicate.return_value = True
1711
        uni1 = create_autospec(UNI)
1712
        uni2 = create_autospec(UNI)
1713
        uni1.interface = create_autospec(Interface)
1714
        uni2.interface = create_autospec(Interface)
1715
        uni1.interface.switch = "00:00:00:00:00:00:00:01"
1716
        uni2.interface.switch = "00:00:00:00:00:00:00:02"
1717
        uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2]
1718
        mongo_controller_upsert_mock.return_value = True
1719
1720
        payload1 = {
1721
            "name": "my evc1",
1722
            "uni_a": {
1723
                "interface_id": "00:00:00:00:00:00:00:01:1",
1724
                "tag": {"tag_type": 'vlan', "value": 80},
1725
            },
1726
            "uni_z": {
1727
                "interface_id": "00:00:00:00:00:00:00:02:2",
1728
                "tag": {"tag_type": 'vlan', "value": 1},
1729
            },
1730
            "dynamic_backup_path": True,
1731
        }
1732
1733
        payload2 = {"dynamic_backup_path": False}
1734
1735
        response = await self.api_client.post(
1736
            f"{self.base_endpoint}/v2/evc/",
1737
            json=payload1,
1738
        )
1739
        assert 201 == response.status_code
1740
1741
        current_data = response.json()
1742
        circuit_id = current_data["circuit_id"]
1743
        response = await self.api_client.patch(
1744
            f"{self.base_endpoint}/v2/evc/{circuit_id}", data=payload2
1745
        )
1746
        current_data = response.json()
1747
        assert 415 == response.status_code
1748
        assert "application/json" in current_data["description"]
1749
1750
    async def test_delete_no_evc(self):
1751
        """Test delete when EVC does not exist."""