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")
@@ 1658-1714 (lines=57) @@
1655
        with pytest.raises(ValueError):
1656
            self.napp._uni_from_dict(uni_dict)
1657
1658
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1659
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
1660
    @patch("napps.kytos.mef_eline.main.Main._uni_from_dict")
1661
    @patch("napps.kytos.mef_eline.models.evc.EVC._validate")
1662
    @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
1663
    async def test_update_evc_no_json_mime(
1664
        self,
1665
        mongo_controller_upsert_mock,
1666
        validate_mock,
1667
        uni_from_dict_mock,
1668
        sched_add_mock,
1669
        evc_deploy_mock,
1670
        event_loop
1671
    ):
1672
        """Test update a circuit with wrong mimetype."""
1673
        self.napp.controller.loop = event_loop
1674
        validate_mock.return_value = True
1675
        sched_add_mock.return_value = True
1676
        evc_deploy_mock.return_value = True
1677
        uni1 = create_autospec(UNI)
1678
        uni2 = create_autospec(UNI)
1679
        uni1.interface = create_autospec(Interface)
1680
        uni2.interface = create_autospec(Interface)
1681
        uni1.interface.switch = "00:00:00:00:00:00:00:01"
1682
        uni2.interface.switch = "00:00:00:00:00:00:00:02"
1683
        uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2]
1684
        mongo_controller_upsert_mock.return_value = True
1685
1686
        payload1 = {
1687
            "name": "my evc1",
1688
            "uni_a": {
1689
                "interface_id": "00:00:00:00:00:00:00:01:1",
1690
                "tag": {"tag_type": 1, "value": 80},
1691
            },
1692
            "uni_z": {
1693
                "interface_id": "00:00:00:00:00:00:00:02:2",
1694
                "tag": {"tag_type": 1, "value": 1},
1695
            },
1696
            "dynamic_backup_path": True,
1697
        }
1698
1699
        payload2 = {"dynamic_backup_path": False}
1700
1701
        response = await self.api_client.post(
1702
            f"{self.base_endpoint}/v2/evc/",
1703
            json=payload1,
1704
        )
1705
        assert 201 == response.status_code
1706
1707
        current_data = response.json()
1708
        circuit_id = current_data["circuit_id"]
1709
        response = await self.api_client.patch(
1710
            f"{self.base_endpoint}/v2/evc/{circuit_id}", data=payload2
1711
        )
1712
        current_data = response.json()
1713
        assert 415 == response.status_code
1714
        assert "application/json" in current_data["description"]
1715
1716
    async def test_delete_no_evc(self):
1717
        """Test delete when EVC does not exist."""