Code Duplication    Length = 65-72 lines in 2 locations

tests/unit/test_main.py 2 locations

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