Code Duplication    Length = 58-62 lines in 2 locations

tests/unit/models/test_link_protection.py 2 locations

@@ 455-516 (lines=62) @@
452
        deploy_to_path_mocked.assert_called_once_with(evc.primary_path, None)
453
        assert current_handle_link_up
454
455
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.deploy")
456
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.deploy_to_path")
457
    @patch("napps.kytos.mef_eline.models.evc.EVC._install_flows")
458
    @patch("napps.kytos.mef_eline.models.path.Path.status", EntityStatus.UP)
459
    async def test_handle_link_up_case_3(
460
        self,
461
        _install_flows_mocked,
462
        deploy_to_path_mocked,
463
        deploy_mocked,
464
    ):
465
        """Test if it is deployed after the backup is up."""
466
        deploy_mocked.return_value = True
467
        deploy_to_path_mocked.return_value = True
468
        primary_path = [
469
            get_link_mocked(
470
                endpoint_a_port=9,
471
                endpoint_b_port=10,
472
                metadata={"s_vlan": 5},
473
                status=EntityStatus.DOWN,
474
            ),
475
            get_link_mocked(
476
                endpoint_a_port=11,
477
                endpoint_b_port=12,
478
                metadata={"s_vlan": 6},
479
                status=EntityStatus.UP,
480
            ),
481
        ]
482
        backup_path = [
483
            get_link_mocked(
484
                endpoint_a_port=9,
485
                endpoint_b_port=14,
486
                metadata={"s_vlan": 5},
487
                status=EntityStatus.DOWN,
488
            ),
489
            get_link_mocked(
490
                endpoint_a_port=15,
491
                endpoint_b_port=12,
492
                metadata={"s_vlan": 6},
493
                status=EntityStatus.UP,
494
            ),
495
        ]
496
        attributes = {
497
            "controller": get_controller_mock(),
498
            "name": "circuit_11",
499
            "uni_a": get_uni_mocked(is_valid=True),
500
            "uni_z": get_uni_mocked(is_valid=True),
501
            "primary_path": primary_path,
502
            "backup_path": backup_path,
503
            "enabled": True,
504
            "dynamic_backup_path": True,
505
        }
506
507
        evc = EVC(**attributes)
508
509
        evc.current_path = Path([])
510
        deploy_to_path_mocked.reset_mock()
511
        current_handle_link_up = evc.handle_link_up(backup_path[0])
512
513
        assert deploy_mocked.call_count == 0
514
        assert deploy_to_path_mocked.call_count == 1
515
        deploy_to_path_mocked.assert_called_once_with(evc.backup_path, None)
516
        assert current_handle_link_up
517
518
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.deploy_to_path")
519
    @patch("napps.kytos.mef_eline.models.evc.EVC._install_flows")
@@ 396-453 (lines=58) @@
393
        assert deploy_to_mocked.call_count == 0
394
        assert current_handle_link_up
395
396
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.deploy")
397
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.deploy_to_path")
398
    @patch("napps.kytos.mef_eline.models.path.Path.status", EntityStatus.UP)
399
    async def test_handle_link_up_case_2(
400
        self,
401
        deploy_to_path_mocked,
402
        deploy_mocked
403
    ):
404
        """Test if it is changing from backup_path to primary_path."""
405
        deploy_mocked.return_value = True
406
        deploy_to_path_mocked.return_value = True
407
        primary_path = [
408
            get_link_mocked(
409
                endpoint_a_port=9,
410
                endpoint_b_port=10,
411
                metadata={"s_vlan": 5},
412
                status=EntityStatus.UP,
413
            ),
414
            get_link_mocked(
415
                endpoint_a_port=11,
416
                endpoint_b_port=12,
417
                metadata={"s_vlan": 6},
418
                status=EntityStatus.UP,
419
            ),
420
        ]
421
        backup_path = [
422
            get_link_mocked(
423
                endpoint_a_port=9,
424
                endpoint_b_port=14,
425
                metadata={"s_vlan": 5},
426
                status=EntityStatus.UP,
427
            ),
428
            get_link_mocked(
429
                endpoint_a_port=15,
430
                endpoint_b_port=12,
431
                metadata={"s_vlan": 6},
432
                status=EntityStatus.UP,
433
            ),
434
        ]
435
        attributes = {
436
            "controller": get_controller_mock(),
437
            "name": "circuit_10",
438
            "uni_a": get_uni_mocked(is_valid=True),
439
            "uni_z": get_uni_mocked(is_valid=True),
440
            "primary_path": primary_path,
441
            "backup_path": backup_path,
442
            "enabled": True,
443
            "dynamic_backup_path": True,
444
        }
445
446
        evc = EVC(**attributes)
447
        evc.current_path = evc.backup_path
448
        deploy_to_path_mocked.reset_mock()
449
        current_handle_link_up = evc.handle_link_up(primary_path[0])
450
        assert deploy_mocked.call_count == 0
451
        assert deploy_to_path_mocked.call_count == 1
452
        deploy_to_path_mocked.assert_called_once_with(evc.primary_path, None)
453
        assert current_handle_link_up
454
455
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.deploy")
456
    @patch("napps.kytos.mef_eline.models.evc.EVCDeploy.deploy_to_path")