Skip to content

Commit 31a4071

Browse files
committed
updated test cases
1 parent 85947d4 commit 31a4071

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

tests/test_config_stp.py

+19-23
Original file line numberDiff line numberDiff line change
@@ -564,30 +564,27 @@ def test_stp_global_max_hops_invalid_mode(mock_db):
564564

565565

566566
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()
583575
runner = CliRunner()
576+
577+
# Invoke the command with a valid max_age
584578
result = runner.invoke(stp_global_max_age, ['25'], obj=mock_db)
585579

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})
591588

592589

593590
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):
596593

597594
with patch('config.stp.check_if_global_stp_enabled'), \
598595
patch('config.stp.get_global_stp_mode', return_value='invalid_mode'):
599-
596+
600597
runner = CliRunner()
601598
result = runner.invoke(stp_global_max_age, ['30'], obj=mock_db)
602599

@@ -605,4 +602,3 @@ def test_stp_global_max_age_invalid_mode(mock_db, mock_ctx):
605602

606603
# Verify fail was called with the correct error message
607604
mock_ctx.fail.assert_called_once_with("Invalid STP mode configuration, no mode is enabled")
608-

0 commit comments

Comments
 (0)