Code Duplication    Length = 60-68 lines in 2 locations

tests/unit/test_main.py 2 locations

@@ 1524-1591 (lines=68) @@
1521
        evc_deploy.assert_not_called()
1522
        self.assertEqual(405, response.status_code)
1523
1524
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1525
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
1526
    @patch("napps.kytos.mef_eline.main.Main._uni_from_dict")
1527
    @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
1528
    @patch("napps.kytos.mef_eline.models.evc.EVC._validate")
1529
    @patch("napps.kytos.mef_eline.main.EVC.as_dict")
1530
    def test_update_circuit_invalid_json(self, *args):
1531
        """Test update a circuit circuit."""
1532
        # pylint: disable=too-many-locals
1533
        (
1534
            evc_as_dict_mock,
1535
            validate_mock,
1536
            mongo_controller_upsert_mock,
1537
            uni_from_dict_mock,
1538
            sched_add_mock,
1539
            evc_deploy_mock,
1540
        ) = args
1541
1542
        validate_mock.return_value = True
1543
        mongo_controller_upsert_mock.return_value = True
1544
        sched_add_mock.return_value = True
1545
        evc_deploy_mock.return_value = True
1546
        uni1 = create_autospec(UNI)
1547
        uni2 = create_autospec(UNI)
1548
        uni1.interface = create_autospec(Interface)
1549
        uni2.interface = create_autospec(Interface)
1550
        uni1.interface.switch = "00:00:00:00:00:00:00:01"
1551
        uni2.interface.switch = "00:00:00:00:00:00:00:02"
1552
        uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2]
1553
1554
        api = self.get_app_test_client(self.napp)
1555
        payload1 = {
1556
            "name": "my evc1",
1557
            "uni_a": {
1558
                "interface_id": "00:00:00:00:00:00:00:01:1",
1559
                "tag": {"tag_type": 1, "value": 80},
1560
            },
1561
            "uni_z": {
1562
                "interface_id": "00:00:00:00:00:00:00:02:2",
1563
                "tag": {"tag_type": 1, "value": 1},
1564
            },
1565
            "dynamic_backup_path": True,
1566
        }
1567
1568
        payload2 = {
1569
            "dynamic_backup_path": False,
1570
        }
1571
1572
        evc_as_dict_mock.return_value = payload1
1573
        response = api.post(
1574
            f"{self.server_name_url}/v2/evc/",
1575
            data=json.dumps(payload1),
1576
            content_type="application/json",
1577
        )
1578
        self.assertEqual(201, response.status_code)
1579
1580
        evc_as_dict_mock.return_value = payload2
1581
        current_data = json.loads(response.data)
1582
        circuit_id = current_data["circuit_id"]
1583
        response = api.patch(
1584
            f"{self.server_name_url}/v2/evc/{circuit_id}",
1585
            data=payload2,
1586
            content_type="application/json",
1587
        )
1588
        current_data = json.loads(response.data)
1589
        expected_data = "The request body is not a well-formed JSON."
1590
        self.assertEqual(current_data["description"], expected_data)
1591
        self.assertEqual(400, response.status_code)
1592
1593
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1594
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
@@ 1683-1742 (lines=60) @@
1680
        with self.assertRaises(ValueError):
1681
            self.napp._uni_from_dict(link_dict)
1682
1683
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1684
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
1685
    @patch("napps.kytos.mef_eline.main.Main._uni_from_dict")
1686
    @patch("napps.kytos.mef_eline.models.evc.EVC._validate")
1687
    @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
1688
    def test_update_evc_no_json_mime(self, *args):
1689
        """Test update a circuit with wrong mimetype."""
1690
        # pylint: disable=too-many-locals
1691
        (
1692
            mongo_controller_upsert_mock,
1693
            validate_mock,
1694
            uni_from_dict_mock,
1695
            sched_add_mock,
1696
            evc_deploy_mock,
1697
        ) = args
1698
1699
        validate_mock.return_value = True
1700
        sched_add_mock.return_value = True
1701
        evc_deploy_mock.return_value = True
1702
        uni1 = create_autospec(UNI)
1703
        uni2 = create_autospec(UNI)
1704
        uni1.interface = create_autospec(Interface)
1705
        uni2.interface = create_autospec(Interface)
1706
        uni1.interface.switch = "00:00:00:00:00:00:00:01"
1707
        uni2.interface.switch = "00:00:00:00:00:00:00:02"
1708
        uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2]
1709
        mongo_controller_upsert_mock.return_value = True
1710
1711
        api = self.get_app_test_client(self.napp)
1712
        payload1 = {
1713
            "name": "my evc1",
1714
            "uni_a": {
1715
                "interface_id": "00:00:00:00:00:00:00:01:1",
1716
                "tag": {"tag_type": 1, "value": 80},
1717
            },
1718
            "uni_z": {
1719
                "interface_id": "00:00:00:00:00:00:00:02:2",
1720
                "tag": {"tag_type": 1, "value": 1},
1721
            },
1722
            "dynamic_backup_path": True,
1723
        }
1724
1725
        payload2 = {"dynamic_backup_path": False}
1726
1727
        response = api.post(
1728
            f"{self.server_name_url}/v2/evc/",
1729
            data=json.dumps(payload1),
1730
            content_type="application/json",
1731
        )
1732
        self.assertEqual(201, response.status_code)
1733
1734
        current_data = json.loads(response.data)
1735
        circuit_id = current_data["circuit_id"]
1736
        response = api.patch(
1737
            f"{self.server_name_url}/v2/evc/{circuit_id}", data=payload2
1738
        )
1739
        current_data = json.loads(response.data)
1740
        expected_data = "The request body mimetype is not application/json."
1741
        self.assertEqual(current_data["description"], expected_data)
1742
        self.assertEqual(415, response.status_code)
1743
1744
    def test_delete_no_evc(self):
1745
        """Test delete when EVC does not exist."""