Code Duplication    Length = 66-73 lines in 2 locations

tests/unit/test_main.py 2 locations

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