Code Duplication    Length = 66-73 lines in 2 locations

tests/unit/test_main.py 2 locations

@@ 1432-1504 (lines=73) @@
1429
        assert 200 == response.status_code
1430
        evc_deploy.assert_called_once()
1431
1432
    @patch("napps.kytos.mef_eline.main.Main._check_no_tag_duplication")
1433
    @patch("napps.kytos.mef_eline.models.evc.EVC._tag_lists_equal")
1434
    @patch("napps.kytos.mef_eline.main.Main._use_uni_tags")
1435
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1436
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
1437
    @patch("napps.kytos.mef_eline.main.Main._uni_from_dict")
1438
    @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
1439
    @patch("napps.kytos.mef_eline.models.evc.EVC._validate")
1440
    @patch("napps.kytos.mef_eline.main.EVC.as_dict")
1441
    async def test_update_circuit_invalid_json(
1442
        self,
1443
        evc_as_dict_mock,
1444
        validate_mock,
1445
        mongo_controller_upsert_mock,
1446
        uni_from_dict_mock,
1447
        sched_add_mock,
1448
        evc_deploy_mock,
1449
        mock_use_uni_tags,
1450
        mock_tags_equal,
1451
        mock_check_duplicate,
1452
        event_loop
1453
    ):
1454
        """Test update a circuit circuit."""
1455
        self.napp.controller.loop = event_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")
@@ 1684-1749 (lines=66) @@
1681
        with pytest.raises(ValueError):
1682
            self.napp._uni_from_dict(uni_dict)
1683
1684
    @patch("napps.kytos.mef_eline.main.Main._check_no_tag_duplication")
1685
    @patch("napps.kytos.mef_eline.models.evc.EVC._tag_lists_equal")
1686
    @patch("napps.kytos.mef_eline.main.Main._use_uni_tags")
1687
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1688
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
1689
    @patch("napps.kytos.mef_eline.main.Main._uni_from_dict")
1690
    @patch("napps.kytos.mef_eline.models.evc.EVC._validate")
1691
    @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
1692
    async def test_update_evc_no_json_mime(
1693
        self,
1694
        mongo_controller_upsert_mock,
1695
        validate_mock,
1696
        uni_from_dict_mock,
1697
        sched_add_mock,
1698
        evc_deploy_mock,
1699
        mock_use_uni_tags,
1700
        mock_tags_equal,
1701
        mock_check_duplicate,
1702
        event_loop
1703
    ):
1704
        """Test update a circuit with wrong mimetype."""
1705
        self.napp.controller.loop = event_loop
1706
        validate_mock.return_value = True
1707
        sched_add_mock.return_value = True
1708
        evc_deploy_mock.return_value = True
1709
        mock_use_uni_tags.return_value = True
1710
        mock_tags_equal.return_value = True
1711
        mock_check_duplicate.return_value = True
1712
        uni1 = create_autospec(UNI)
1713
        uni2 = create_autospec(UNI)
1714
        uni1.interface = create_autospec(Interface)
1715
        uni2.interface = create_autospec(Interface)
1716
        uni1.interface.switch = "00:00:00:00:00:00:00:01"
1717
        uni2.interface.switch = "00:00:00:00:00:00:00:02"
1718
        uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2]
1719
        mongo_controller_upsert_mock.return_value = True
1720
1721
        payload1 = {
1722
            "name": "my evc1",
1723
            "uni_a": {
1724
                "interface_id": "00:00:00:00:00:00:00:01:1",
1725
                "tag": {"tag_type": 'vlan', "value": 80},
1726
            },
1727
            "uni_z": {
1728
                "interface_id": "00:00:00:00:00:00:00:02:2",
1729
                "tag": {"tag_type": 'vlan', "value": 1},
1730
            },
1731
            "dynamic_backup_path": True,
1732
        }
1733
1734
        payload2 = {"dynamic_backup_path": False}
1735
1736
        response = await self.api_client.post(
1737
            f"{self.base_endpoint}/v2/evc/",
1738
            json=payload1,
1739
        )
1740
        assert 201 == response.status_code
1741
1742
        current_data = response.json()
1743
        circuit_id = current_data["circuit_id"]
1744
        response = await self.api_client.patch(
1745
            f"{self.base_endpoint}/v2/evc/{circuit_id}", data=payload2
1746
        )
1747
        current_data = response.json()
1748
        assert 415 == response.status_code
1749
        assert "application/json" in current_data["description"]
1750
1751
    async def test_delete_no_evc(self):
1752
        """Test delete when EVC does not exist."""