Code Duplication    Length = 57-64 lines in 2 locations

tests/unit/test_main.py 2 locations

@@ 1398-1461 (lines=64) @@
1395
        assert 409 == response.status_code
1396
        assert "Can't update archived EVC" in response.json()["description"]
1397
1398
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1399
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
1400
    @patch("napps.kytos.mef_eline.main.Main._uni_from_dict")
1401
    @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
1402
    @patch("napps.kytos.mef_eline.models.evc.EVC._validate")
1403
    @patch("napps.kytos.mef_eline.main.EVC.as_dict")
1404
    async def test_update_circuit_invalid_json(
1405
        self,
1406
        evc_as_dict_mock,
1407
        validate_mock,
1408
        mongo_controller_upsert_mock,
1409
        uni_from_dict_mock,
1410
        sched_add_mock,
1411
        evc_deploy_mock,
1412
        event_loop
1413
    ):
1414
        """Test update a circuit circuit."""
1415
        self.napp.controller.loop = event_loop
1416
        validate_mock.return_value = True
1417
        mongo_controller_upsert_mock.return_value = True
1418
        sched_add_mock.return_value = True
1419
        evc_deploy_mock.return_value = True
1420
        uni1 = create_autospec(UNI)
1421
        uni2 = create_autospec(UNI)
1422
        uni1.interface = create_autospec(Interface)
1423
        uni2.interface = create_autospec(Interface)
1424
        uni1.interface.switch = "00:00:00:00:00:00:00:01"
1425
        uni2.interface.switch = "00:00:00:00:00:00:00:02"
1426
        uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2]
1427
1428
        payload1 = {
1429
            "name": "my evc1",
1430
            "uni_a": {
1431
                "interface_id": "00:00:00:00:00:00:00:01:1",
1432
                "tag": {"tag_type": 1, "value": 80},
1433
            },
1434
            "uni_z": {
1435
                "interface_id": "00:00:00:00:00:00:00:02:2",
1436
                "tag": {"tag_type": 1, "value": 1},
1437
            },
1438
            "dynamic_backup_path": True,
1439
        }
1440
1441
        payload2 = {
1442
            "dynamic_backup_path": False,
1443
        }
1444
1445
        evc_as_dict_mock.return_value = payload1
1446
        response = await self.api_client.post(
1447
            f"{self.base_endpoint}/v2/evc/",
1448
            json=payload1
1449
        )
1450
        assert 201 == response.status_code
1451
1452
        evc_as_dict_mock.return_value = payload2
1453
        current_data = response.json()
1454
        circuit_id = current_data["circuit_id"]
1455
        response = await self.api_client.patch(
1456
            f"{self.base_endpoint}/v2/evc/{circuit_id}",
1457
            json=payload2
1458
        )
1459
        current_data = response.json()
1460
        assert 400 == response.status_code
1461
        assert "must have a primary path or" in current_data["description"]
1462
1463
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1464
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
@@ 1559-1615 (lines=57) @@
1556
        with pytest.raises(ValueError):
1557
            self.napp._uni_from_dict(uni_dict)
1558
1559
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1560
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
1561
    @patch("napps.kytos.mef_eline.main.Main._uni_from_dict")
1562
    @patch("napps.kytos.mef_eline.models.evc.EVC._validate")
1563
    @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
1564
    async def test_update_evc_no_json_mime(
1565
        self,
1566
        mongo_controller_upsert_mock,
1567
        validate_mock,
1568
        uni_from_dict_mock,
1569
        sched_add_mock,
1570
        evc_deploy_mock,
1571
        event_loop
1572
    ):
1573
        """Test update a circuit with wrong mimetype."""
1574
        self.napp.controller.loop = event_loop
1575
        validate_mock.return_value = True
1576
        sched_add_mock.return_value = True
1577
        evc_deploy_mock.return_value = True
1578
        uni1 = create_autospec(UNI)
1579
        uni2 = create_autospec(UNI)
1580
        uni1.interface = create_autospec(Interface)
1581
        uni2.interface = create_autospec(Interface)
1582
        uni1.interface.switch = "00:00:00:00:00:00:00:01"
1583
        uni2.interface.switch = "00:00:00:00:00:00:00:02"
1584
        uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2]
1585
        mongo_controller_upsert_mock.return_value = True
1586
1587
        payload1 = {
1588
            "name": "my evc1",
1589
            "uni_a": {
1590
                "interface_id": "00:00:00:00:00:00:00:01:1",
1591
                "tag": {"tag_type": 1, "value": 80},
1592
            },
1593
            "uni_z": {
1594
                "interface_id": "00:00:00:00:00:00:00:02:2",
1595
                "tag": {"tag_type": 1, "value": 1},
1596
            },
1597
            "dynamic_backup_path": True,
1598
        }
1599
1600
        payload2 = {"dynamic_backup_path": False}
1601
1602
        response = await self.api_client.post(
1603
            f"{self.base_endpoint}/v2/evc/",
1604
            json=payload1,
1605
        )
1606
        assert 201 == response.status_code
1607
1608
        current_data = response.json()
1609
        circuit_id = current_data["circuit_id"]
1610
        response = await self.api_client.patch(
1611
            f"{self.base_endpoint}/v2/evc/{circuit_id}", data=payload2
1612
        )
1613
        current_data = response.json()
1614
        assert 415 == response.status_code
1615
        assert "application/json" in current_data["description"]
1616
1617
    async def test_delete_no_evc(self):
1618
        """Test delete when EVC does not exist."""