Code Duplication    Length = 57-64 lines in 2 locations

tests/unit/test_main.py 2 locations

@@ 1369-1432 (lines=64) @@
1366
        assert 409 == response.status_code
1367
        assert "Can't update archived EVC" in response.json()["description"]
1368
1369
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1370
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
1371
    @patch("napps.kytos.mef_eline.main.Main._uni_from_dict")
1372
    @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
1373
    @patch("napps.kytos.mef_eline.models.evc.EVC._validate")
1374
    @patch("napps.kytos.mef_eline.main.EVC.as_dict")
1375
    async def test_update_circuit_invalid_json(
1376
        self,
1377
        evc_as_dict_mock,
1378
        validate_mock,
1379
        mongo_controller_upsert_mock,
1380
        uni_from_dict_mock,
1381
        sched_add_mock,
1382
        evc_deploy_mock,
1383
        event_loop
1384
    ):
1385
        """Test update a circuit circuit."""
1386
        self.napp.controller.loop = event_loop
1387
        validate_mock.return_value = True
1388
        mongo_controller_upsert_mock.return_value = True
1389
        sched_add_mock.return_value = True
1390
        evc_deploy_mock.return_value = True
1391
        uni1 = create_autospec(UNI)
1392
        uni2 = create_autospec(UNI)
1393
        uni1.interface = create_autospec(Interface)
1394
        uni2.interface = create_autospec(Interface)
1395
        uni1.interface.switch = "00:00:00:00:00:00:00:01"
1396
        uni2.interface.switch = "00:00:00:00:00:00:00:02"
1397
        uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2]
1398
1399
        payload1 = {
1400
            "name": "my evc1",
1401
            "uni_a": {
1402
                "interface_id": "00:00:00:00:00:00:00:01:1",
1403
                "tag": {"tag_type": 1, "value": 80},
1404
            },
1405
            "uni_z": {
1406
                "interface_id": "00:00:00:00:00:00:00:02:2",
1407
                "tag": {"tag_type": 1, "value": 1},
1408
            },
1409
            "dynamic_backup_path": True,
1410
        }
1411
1412
        payload2 = {
1413
            "dynamic_backup_path": False,
1414
        }
1415
1416
        evc_as_dict_mock.return_value = payload1
1417
        response = await self.api_client.post(
1418
            f"{self.base_endpoint}/v2/evc/",
1419
            json=payload1
1420
        )
1421
        assert 201 == response.status_code
1422
1423
        evc_as_dict_mock.return_value = payload2
1424
        current_data = response.json()
1425
        circuit_id = current_data["circuit_id"]
1426
        response = await self.api_client.patch(
1427
            f"{self.base_endpoint}/v2/evc/{circuit_id}",
1428
            json=payload2
1429
        )
1430
        current_data = response.json()
1431
        assert 400 == response.status_code
1432
        assert "must have a primary path or" in current_data["description"]
1433
1434
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1435
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
@@ 1530-1586 (lines=57) @@
1527
        with pytest.raises(ValueError):
1528
            self.napp._uni_from_dict(uni_dict)
1529
1530
    @patch("napps.kytos.mef_eline.models.evc.EVC.deploy")
1531
    @patch("napps.kytos.mef_eline.scheduler.Scheduler.add")
1532
    @patch("napps.kytos.mef_eline.main.Main._uni_from_dict")
1533
    @patch("napps.kytos.mef_eline.models.evc.EVC._validate")
1534
    @patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
1535
    async def test_update_evc_no_json_mime(
1536
        self,
1537
        mongo_controller_upsert_mock,
1538
        validate_mock,
1539
        uni_from_dict_mock,
1540
        sched_add_mock,
1541
        evc_deploy_mock,
1542
        event_loop
1543
    ):
1544
        """Test update a circuit with wrong mimetype."""
1545
        self.napp.controller.loop = event_loop
1546
        validate_mock.return_value = True
1547
        sched_add_mock.return_value = True
1548
        evc_deploy_mock.return_value = True
1549
        uni1 = create_autospec(UNI)
1550
        uni2 = create_autospec(UNI)
1551
        uni1.interface = create_autospec(Interface)
1552
        uni2.interface = create_autospec(Interface)
1553
        uni1.interface.switch = "00:00:00:00:00:00:00:01"
1554
        uni2.interface.switch = "00:00:00:00:00:00:00:02"
1555
        uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2]
1556
        mongo_controller_upsert_mock.return_value = True
1557
1558
        payload1 = {
1559
            "name": "my evc1",
1560
            "uni_a": {
1561
                "interface_id": "00:00:00:00:00:00:00:01:1",
1562
                "tag": {"tag_type": 1, "value": 80},
1563
            },
1564
            "uni_z": {
1565
                "interface_id": "00:00:00:00:00:00:00:02:2",
1566
                "tag": {"tag_type": 1, "value": 1},
1567
            },
1568
            "dynamic_backup_path": True,
1569
        }
1570
1571
        payload2 = {"dynamic_backup_path": False}
1572
1573
        response = await self.api_client.post(
1574
            f"{self.base_endpoint}/v2/evc/",
1575
            json=payload1,
1576
        )
1577
        assert 201 == response.status_code
1578
1579
        current_data = response.json()
1580
        circuit_id = current_data["circuit_id"]
1581
        response = await self.api_client.patch(
1582
            f"{self.base_endpoint}/v2/evc/{circuit_id}", data=payload2
1583
        )
1584
        current_data = response.json()
1585
        assert 415 == response.status_code
1586
        assert "application/json" in current_data["description"]
1587
1588
    async def test_delete_no_evc(self):
1589
        """Test delete when EVC does not exist."""