Code Duplication    Length = 60-68 lines in 2 locations

tests/unit/test_main.py 2 locations

@@ 1546-1613 (lines=68) @@
1543
        evc_deploy.assert_not_called()
1544
        self.assertEqual(405, response.status_code)
1545
1546
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1547
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
1548
    @patch("napps.kytos.mef_eline.main.Main._uni_from_dict")
1549
    @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
1550
    @patch("napps.kytos.mef_eline.models.evc.EVC._validate")
1551
    @patch("napps.kytos.mef_eline.main.EVC.as_dict")
1552
    def test_update_circuit_invalid_json(self, *args):
1553
        """Test update a circuit circuit."""
1554
        # pylint: disable=too-many-locals
1555
        (
1556
            evc_as_dict_mock,
1557
            validate_mock,
1558
            mongo_controller_upsert_mock,
1559
            uni_from_dict_mock,
1560
            sched_add_mock,
1561
            evc_deploy_mock,
1562
        ) = args
1563
1564
        validate_mock.return_value = True
1565
        mongo_controller_upsert_mock.return_value = True
1566
        sched_add_mock.return_value = True
1567
        evc_deploy_mock.return_value = True
1568
        uni1 = create_autospec(UNI)
1569
        uni2 = create_autospec(UNI)
1570
        uni1.interface = create_autospec(Interface)
1571
        uni2.interface = create_autospec(Interface)
1572
        uni1.interface.switch = "00:00:00:00:00:00:00:01"
1573
        uni2.interface.switch = "00:00:00:00:00:00:00:02"
1574
        uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2]
1575
1576
        api = self.get_app_test_client(self.napp)
1577
        payload1 = {
1578
            "name": "my evc1",
1579
            "uni_a": {
1580
                "interface_id": "00:00:00:00:00:00:00:01:1",
1581
                "tag": {"tag_type": 1, "value": 80},
1582
            },
1583
            "uni_z": {
1584
                "interface_id": "00:00:00:00:00:00:00:02:2",
1585
                "tag": {"tag_type": 1, "value": 1},
1586
            },
1587
            "dynamic_backup_path": True,
1588
        }
1589
1590
        payload2 = {
1591
            "dynamic_backup_path": False,
1592
        }
1593
1594
        evc_as_dict_mock.return_value = payload1
1595
        response = api.post(
1596
            f"{self.server_name_url}/v2/evc/",
1597
            data=json.dumps(payload1),
1598
            content_type="application/json",
1599
        )
1600
        self.assertEqual(201, response.status_code)
1601
1602
        evc_as_dict_mock.return_value = payload2
1603
        current_data = json.loads(response.data)
1604
        circuit_id = current_data["circuit_id"]
1605
        response = api.patch(
1606
            f"{self.server_name_url}/v2/evc/{circuit_id}",
1607
            data=payload2,
1608
            content_type="application/json",
1609
        )
1610
        current_data = json.loads(response.data)
1611
        expected_data = "The request body is not a well-formed JSON."
1612
        self.assertEqual(current_data["description"], expected_data)
1613
        self.assertEqual(400, response.status_code)
1614
1615
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1616
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
@@ 1714-1773 (lines=60) @@
1711
        with self.assertRaises(ValueError):
1712
            self.napp._uni_from_dict(uni_dict)
1713
1714
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1715
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
1716
    @patch("napps.kytos.mef_eline.main.Main._uni_from_dict")
1717
    @patch("napps.kytos.mef_eline.models.evc.EVC._validate")
1718
    @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
1719
    def test_update_evc_no_json_mime(self, *args):
1720
        """Test update a circuit with wrong mimetype."""
1721
        # pylint: disable=too-many-locals
1722
        (
1723
            mongo_controller_upsert_mock,
1724
            validate_mock,
1725
            uni_from_dict_mock,
1726
            sched_add_mock,
1727
            evc_deploy_mock,
1728
        ) = args
1729
1730
        validate_mock.return_value = True
1731
        sched_add_mock.return_value = True
1732
        evc_deploy_mock.return_value = True
1733
        uni1 = create_autospec(UNI)
1734
        uni2 = create_autospec(UNI)
1735
        uni1.interface = create_autospec(Interface)
1736
        uni2.interface = create_autospec(Interface)
1737
        uni1.interface.switch = "00:00:00:00:00:00:00:01"
1738
        uni2.interface.switch = "00:00:00:00:00:00:00:02"
1739
        uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2]
1740
        mongo_controller_upsert_mock.return_value = True
1741
1742
        api = self.get_app_test_client(self.napp)
1743
        payload1 = {
1744
            "name": "my evc1",
1745
            "uni_a": {
1746
                "interface_id": "00:00:00:00:00:00:00:01:1",
1747
                "tag": {"tag_type": 1, "value": 80},
1748
            },
1749
            "uni_z": {
1750
                "interface_id": "00:00:00:00:00:00:00:02:2",
1751
                "tag": {"tag_type": 1, "value": 1},
1752
            },
1753
            "dynamic_backup_path": True,
1754
        }
1755
1756
        payload2 = {"dynamic_backup_path": False}
1757
1758
        response = api.post(
1759
            f"{self.server_name_url}/v2/evc/",
1760
            data=json.dumps(payload1),
1761
            content_type="application/json",
1762
        )
1763
        self.assertEqual(201, response.status_code)
1764
1765
        current_data = json.loads(response.data)
1766
        circuit_id = current_data["circuit_id"]
1767
        response = api.patch(
1768
            f"{self.server_name_url}/v2/evc/{circuit_id}", data=payload2
1769
        )
1770
        current_data = json.loads(response.data)
1771
        expected_data = "The request body mimetype is not application/json."
1772
        self.assertEqual(current_data["description"], expected_data)
1773
        self.assertEqual(415, response.status_code)
1774
1775
    def test_delete_no_evc(self):
1776
        """Test delete when EVC does not exist."""