@@ -564,30 +564,27 @@ def test_stp_global_max_hops_invalid_mode(mock_db):
564
564
565
565
566
566
def test_stp_global_max_age_mst_mode (mock_db ):
567
- """Test the stp_global_max_age function for MST mode configuration."""
568
- # Mock context object and ensure correct context behavior
569
- mock_ctx = click .Context (click .Command ('max_age' ))
570
-
571
- # Patch helper functions and required calls
572
- with patch ('config.stp.check_if_global_stp_enabled' ) as mock_check_if_enabled , \
573
- patch ('config.stp.is_valid_max_age' ) as mock_is_valid_max_age , \
574
- patch ('config.stp.get_global_stp_mode' , return_value = 'mst' ), \
575
- patch ('config.stp.update_stp_vlan_parameter' ) as mock_update_stp_vlan , \
576
- patch ('config.stp.is_valid_stp_global_parameters' ):
577
-
578
- # Set return values for mocks
579
- mock_check_if_enabled .return_value = None
580
- mock_is_valid_max_age .return_value = None
581
-
582
- # Initialize CLI runner for test execution
567
+ """Test for MST mode configuration."""
568
+
569
+ with patch ('config.stp.check_if_global_stp_enabled' ), \
570
+ patch ('config.stp.is_valid_max_age' ) as is_valid_max_age , \
571
+ patch ('config.stp.get_global_stp_mode' , return_value = 'mst' ):
572
+
573
+ # Mock the context to check for fail calls
574
+ mock_ctx = MagicMock ()
583
575
runner = CliRunner ()
576
+
577
+ # Invoke the command with a valid max_age
584
578
result = runner .invoke (stp_global_max_age , ['25' ], obj = mock_db )
585
579
586
- # Assertions
587
- assert result .exit_code == 0 # Ensure function exits successfully
588
- mock_check_if_enabled .assert_called_once_with (mock_db .cfgdb , click .get_current_context ())
589
- mock_is_valid_max_age .assert_called_once_with (click .get_current_context (), 25 )
590
- mock_update_stp_vlan .assert_not_called () # Not called in MST mode
580
+ # Check for successful execution
581
+ assert result .exit_code == 0
582
+
583
+ # Check that is_valid_max_age was called with the correct arguments
584
+ is_valid_max_age .assert_called_once_with (mock_ctx , 25 )
585
+
586
+ # Check that db.mod_entry was called with the correct arguments
587
+ mock_db .cfgdb .mod_entry .assert_called_once_with ('STP_MST' , "GLOBAL" , {'max_age' : 25 })
591
588
592
589
593
590
def test_stp_global_max_age_invalid_mode (mock_db , mock_ctx ):
@@ -596,7 +593,7 @@ def test_stp_global_max_age_invalid_mode(mock_db, mock_ctx):
596
593
597
594
with patch ('config.stp.check_if_global_stp_enabled' ), \
598
595
patch ('config.stp.get_global_stp_mode' , return_value = 'invalid_mode' ):
599
-
596
+
600
597
runner = CliRunner ()
601
598
result = runner .invoke (stp_global_max_age , ['30' ], obj = mock_db )
602
599
@@ -605,4 +602,3 @@ def test_stp_global_max_age_invalid_mode(mock_db, mock_ctx):
605
602
606
603
# Verify fail was called with the correct error message
607
604
mock_ctx .fail .assert_called_once_with ("Invalid STP mode configuration, no mode is enabled" )
608
-
0 commit comments