Skip to content

Commit

Permalink
removed errors from test cases for get global stp mode and is valid s…
Browse files Browse the repository at this point in the history
…tp global parameters
  • Loading branch information
kanza-latif committed Jan 2, 2025
1 parent b5c7e65 commit d882f9a
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions tests/test_config_stp.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def test_check_if_global_stp_enabled():
# Create mock objects for db and ctx
mock_db = MagicMock()
mock_ctx = MagicMock()

# Case 1: Global STP is enabled
with patch('path_to_your_module.is_global_stp_enabled', return_value=True):
check_if_global_stp_enabled(mock_db, mock_ctx)
Expand All @@ -255,26 +255,28 @@ def test_is_valid_stp_global_parameters():
# Create mock objects for db and ctx
mock_db = MagicMock()
mock_ctx = MagicMock()

# Mock STP global entry in db
mock_db.get_entry.return_value = {
"forward_delay": "15",
"max_age": "20",
"hello_time": "2",
}

# Patch validate_params to control its behavior
with patch('path_to_your_module.validate_params') as mock_validate_params:
mock_validate_params.return_value = True # Simulate valid parameters
# Call the function
result = is_valid_stp_global_parameters(mock_ctx, mock_db, "forward_delay", "15")

# Call the function with valid parameters
is_valid_stp_global_parameters(mock_ctx, mock_db, "forward_delay", "15")
mock_validate_params.assert_called_once_with("15", "20", "2")
mock_ctx.fail.assert_not_called() # Fail should not be called when parameters are valid
mock_ctx.fail.assert_not_called() # fail should not be called for valid parameters

# Simulate invalid parameters
mock_validate_params.return_value = False

# Case with invalid parameters
mock_validate_params.return_value = False # Simulate invalid parameters
result = is_valid_stp_global_parameters(mock_ctx, mock_db, "forward_delay", "15")
# Call the function with invalid parameters
is_valid_stp_global_parameters(mock_ctx, mock_db, "forward_delay", "15")
mock_ctx.fail.assert_called_once_with("2*(forward_delay-1) >= max_age >= 2*(hello_time +1 ) not met")


Expand Down Expand Up @@ -336,4 +338,3 @@ def test_get_global_stp_max_age():

assert result == 20
mock_db.get_entry.assert_called_once_with('STP', 'GLOBAL')

0 comments on commit d882f9a

Please sign in to comment.