Code Duplication    Length = 65-72 lines in 2 locations

tests/unit/test_main.py 2 locations

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