Code Duplication    Length = 57-64 lines in 2 locations

tests/unit/test_main.py 2 locations

@@ 1432-1495 (lines=64) @@
1429
        assert 409 == response.status_code
1430
        assert "Can't update archived EVC" in response.json()["description"]
1431
1432
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1433
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
1434
    @patch("napps.kytos.mef_eline.main.Main._uni_from_dict")
1435
    @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
1436
    @patch("napps.kytos.mef_eline.models.evc.EVC._validate")
1437
    @patch("napps.kytos.mef_eline.main.EVC.as_dict")
1438
    async def test_update_circuit_invalid_json(
1439
        self,
1440
        evc_as_dict_mock,
1441
        validate_mock,
1442
        mongo_controller_upsert_mock,
1443
        uni_from_dict_mock,
1444
        sched_add_mock,
1445
        evc_deploy_mock,
1446
        event_loop
1447
    ):
1448
        """Test update a circuit circuit."""
1449
        self.napp.controller.loop = event_loop
1450
        validate_mock.return_value = True
1451
        mongo_controller_upsert_mock.return_value = True
1452
        sched_add_mock.return_value = True
1453
        evc_deploy_mock.return_value = True
1454
        uni1 = create_autospec(UNI)
1455
        uni2 = create_autospec(UNI)
1456
        uni1.interface = create_autospec(Interface)
1457
        uni2.interface = create_autospec(Interface)
1458
        uni1.interface.switch = "00:00:00:00:00:00:00:01"
1459
        uni2.interface.switch = "00:00:00:00:00:00:00:02"
1460
        uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2]
1461
1462
        payload1 = {
1463
            "name": "my evc1",
1464
            "uni_a": {
1465
                "interface_id": "00:00:00:00:00:00:00:01:1",
1466
                "tag": {"tag_type": 1, "value": 80},
1467
            },
1468
            "uni_z": {
1469
                "interface_id": "00:00:00:00:00:00:00:02:2",
1470
                "tag": {"tag_type": 1, "value": 1},
1471
            },
1472
            "dynamic_backup_path": True,
1473
        }
1474
1475
        payload2 = {
1476
            "dynamic_backup_path": False,
1477
        }
1478
1479
        evc_as_dict_mock.return_value = payload1
1480
        response = await self.api_client.post(
1481
            f"{self.base_endpoint}/v2/evc/",
1482
            json=payload1
1483
        )
1484
        assert 201 == response.status_code
1485
1486
        evc_as_dict_mock.return_value = payload2
1487
        current_data = response.json()
1488
        circuit_id = current_data["circuit_id"]
1489
        response = await self.api_client.patch(
1490
            f"{self.base_endpoint}/v2/evc/{circuit_id}",
1491
            json=payload2
1492
        )
1493
        current_data = response.json()
1494
        assert 400 == response.status_code
1495
        assert "must have a primary path or" in current_data["description"]
1496
1497
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1498
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
@@ 1660-1716 (lines=57) @@
1657
        with pytest.raises(ValueError):
1658
            self.napp._uni_from_dict(uni_dict)
1659
1660
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1661
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
1662
    @patch("napps.kytos.mef_eline.main.Main._uni_from_dict")
1663
    @patch("napps.kytos.mef_eline.models.evc.EVC._validate")
1664
    @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
1665
    async def test_update_evc_no_json_mime(
1666
        self,
1667
        mongo_controller_upsert_mock,
1668
        validate_mock,
1669
        uni_from_dict_mock,
1670
        sched_add_mock,
1671
        evc_deploy_mock,
1672
        event_loop
1673
    ):
1674
        """Test update a circuit with wrong mimetype."""
1675
        self.napp.controller.loop = event_loop
1676
        validate_mock.return_value = True
1677
        sched_add_mock.return_value = True
1678
        evc_deploy_mock.return_value = True
1679
        uni1 = create_autospec(UNI)
1680
        uni2 = create_autospec(UNI)
1681
        uni1.interface = create_autospec(Interface)
1682
        uni2.interface = create_autospec(Interface)
1683
        uni1.interface.switch = "00:00:00:00:00:00:00:01"
1684
        uni2.interface.switch = "00:00:00:00:00:00:00:02"
1685
        uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2]
1686
        mongo_controller_upsert_mock.return_value = True
1687
1688
        payload1 = {
1689
            "name": "my evc1",
1690
            "uni_a": {
1691
                "interface_id": "00:00:00:00:00:00:00:01:1",
1692
                "tag": {"tag_type": 1, "value": 80},
1693
            },
1694
            "uni_z": {
1695
                "interface_id": "00:00:00:00:00:00:00:02:2",
1696
                "tag": {"tag_type": 1, "value": 1},
1697
            },
1698
            "dynamic_backup_path": True,
1699
        }
1700
1701
        payload2 = {"dynamic_backup_path": False}
1702
1703
        response = await self.api_client.post(
1704
            f"{self.base_endpoint}/v2/evc/",
1705
            json=payload1,
1706
        )
1707
        assert 201 == response.status_code
1708
1709
        current_data = response.json()
1710
        circuit_id = current_data["circuit_id"]
1711
        response = await self.api_client.patch(
1712
            f"{self.base_endpoint}/v2/evc/{circuit_id}", data=payload2
1713
        )
1714
        current_data = response.json()
1715
        assert 415 == response.status_code
1716
        assert "application/json" in current_data["description"]
1717
1718
    async def test_delete_no_evc(self):
1719
        """Test delete when EVC does not exist."""