Code Duplication    Length = 60-68 lines in 2 locations

tests/unit/test_main.py 2 locations

@@ 1581-1648 (lines=68) @@
1578
        evc_deploy.assert_not_called()
1579
        self.assertEqual(405, response.status_code)
1580
1581
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1582
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
1583
    @patch("napps.kytos.mef_eline.main.Main._uni_from_dict")
1584
    @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
1585
    @patch("napps.kytos.mef_eline.models.evc.EVC._validate")
1586
    @patch("napps.kytos.mef_eline.main.EVC.as_dict")
1587
    def test_update_circuit_invalid_json(self, *args):
1588
        """Test update a circuit circuit."""
1589
        # pylint: disable=too-many-locals
1590
        (
1591
            evc_as_dict_mock,
1592
            validate_mock,
1593
            mongo_controller_upsert_mock,
1594
            uni_from_dict_mock,
1595
            sched_add_mock,
1596
            evc_deploy_mock,
1597
        ) = args
1598
1599
        validate_mock.return_value = True
1600
        mongo_controller_upsert_mock.return_value = True
1601
        sched_add_mock.return_value = True
1602
        evc_deploy_mock.return_value = True
1603
        uni1 = create_autospec(UNI)
1604
        uni2 = create_autospec(UNI)
1605
        uni1.interface = create_autospec(Interface)
1606
        uni2.interface = create_autospec(Interface)
1607
        uni1.interface.switch = "00:00:00:00:00:00:00:01"
1608
        uni2.interface.switch = "00:00:00:00:00:00:00:02"
1609
        uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2]
1610
1611
        api = self.get_app_test_client(self.napp)
1612
        payload1 = {
1613
            "name": "my evc1",
1614
            "uni_a": {
1615
                "interface_id": "00:00:00:00:00:00:00:01:1",
1616
                "tag": {"tag_type": 1, "value": 80},
1617
            },
1618
            "uni_z": {
1619
                "interface_id": "00:00:00:00:00:00:00:02:2",
1620
                "tag": {"tag_type": 1, "value": 1},
1621
            },
1622
            "dynamic_backup_path": True,
1623
        }
1624
1625
        payload2 = {
1626
            "dynamic_backup_path": False,
1627
        }
1628
1629
        evc_as_dict_mock.return_value = payload1
1630
        response = api.post(
1631
            f"{self.server_name_url}/v2/evc/",
1632
            data=json.dumps(payload1),
1633
            content_type="application/json",
1634
        )
1635
        self.assertEqual(201, response.status_code)
1636
1637
        evc_as_dict_mock.return_value = payload2
1638
        current_data = json.loads(response.data)
1639
        circuit_id = current_data["circuit_id"]
1640
        response = api.patch(
1641
            f"{self.server_name_url}/v2/evc/{circuit_id}",
1642
            data=payload2,
1643
            content_type="application/json",
1644
        )
1645
        current_data = json.loads(response.data)
1646
        expected_data = "The request body is not a well-formed JSON."
1647
        self.assertEqual(current_data["description"], expected_data)
1648
        self.assertEqual(400, response.status_code)
1649
1650
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1651
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
@@ 1749-1808 (lines=60) @@
1746
        with self.assertRaises(ValueError):
1747
            self.napp._uni_from_dict(uni_dict)
1748
1749
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1750
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
1751
    @patch("napps.kytos.mef_eline.main.Main._uni_from_dict")
1752
    @patch("napps.kytos.mef_eline.models.evc.EVC._validate")
1753
    @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
1754
    def test_update_evc_no_json_mime(self, *args):
1755
        """Test update a circuit with wrong mimetype."""
1756
        # pylint: disable=too-many-locals
1757
        (
1758
            mongo_controller_upsert_mock,
1759
            validate_mock,
1760
            uni_from_dict_mock,
1761
            sched_add_mock,
1762
            evc_deploy_mock,
1763
        ) = args
1764
1765
        validate_mock.return_value = True
1766
        sched_add_mock.return_value = True
1767
        evc_deploy_mock.return_value = True
1768
        uni1 = create_autospec(UNI)
1769
        uni2 = create_autospec(UNI)
1770
        uni1.interface = create_autospec(Interface)
1771
        uni2.interface = create_autospec(Interface)
1772
        uni1.interface.switch = "00:00:00:00:00:00:00:01"
1773
        uni2.interface.switch = "00:00:00:00:00:00:00:02"
1774
        uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2]
1775
        mongo_controller_upsert_mock.return_value = True
1776
1777
        api = self.get_app_test_client(self.napp)
1778
        payload1 = {
1779
            "name": "my evc1",
1780
            "uni_a": {
1781
                "interface_id": "00:00:00:00:00:00:00:01:1",
1782
                "tag": {"tag_type": 1, "value": 80},
1783
            },
1784
            "uni_z": {
1785
                "interface_id": "00:00:00:00:00:00:00:02:2",
1786
                "tag": {"tag_type": 1, "value": 1},
1787
            },
1788
            "dynamic_backup_path": True,
1789
        }
1790
1791
        payload2 = {"dynamic_backup_path": False}
1792
1793
        response = api.post(
1794
            f"{self.server_name_url}/v2/evc/",
1795
            data=json.dumps(payload1),
1796
            content_type="application/json",
1797
        )
1798
        self.assertEqual(201, response.status_code)
1799
1800
        current_data = json.loads(response.data)
1801
        circuit_id = current_data["circuit_id"]
1802
        response = api.patch(
1803
            f"{self.server_name_url}/v2/evc/{circuit_id}", data=payload2
1804
        )
1805
        current_data = json.loads(response.data)
1806
        expected_data = "The request body mimetype is not application/json."
1807
        self.assertEqual(current_data["description"], expected_data)
1808
        self.assertEqual(415, response.status_code)
1809
1810
    def test_delete_no_evc(self):
1811
        """Test delete when EVC does not exist."""