diff --git a/tests/test_config_stp.py b/tests/test_config_stp.py index 39c5e2f5b5..3e7a323720 100644 --- a/tests/test_config_stp.py +++ b/tests/test_config_stp.py @@ -214,7 +214,6 @@ def setup_method(self): self.valid_interface = "Ethernet0" self.invalid_interface = "InvalidInterface" - @patch('click.get_current_context') def test_successful_enable_edgeport(self, mock_context, mock_db, cli_runner): # Arrange @@ -224,13 +223,12 @@ def test_successful_enable_edgeport(self, mock_context, mock_db, cli_runner): result = stp_interface_edgeport_enable(mock_db, self.valid_interface) # Assert mock_db.mod_entry.assert_called_once_with( - 'STP_PORT', - self.valid_interface, + 'STP_PORT', + self.valid_interface, {'edgeport': 'true'} ) assert result is None # Assuming successful execution returns None - @patch('click.get_current_context') def test_invalid_interface(self, mock_context, mock_db, cli_runner): # Arrange @@ -240,7 +238,6 @@ def test_invalid_interface(self, mock_context, mock_db, cli_runner): with pytest.raises(click.ClickException, match=r"Interface .* is not valid"): stp_interface_edgeport_enable(mock_db, self.invalid_interface) - @patch('click.get_current_context') def test_stp_not_enabled(self, mock_context, mock_db, cli_runner): # Arrange @@ -253,7 +250,6 @@ def test_stp_not_enabled(self, mock_context, mock_db, cli_runner): with pytest.raises(click.ClickException, match=r"STP is not enabled for interface .*"): stp_interface_edgeport_enable(mock_db, self.valid_interface) - @patch('click.get_current_context') def test_database_error(self, mock_context, mock_db, cli_runner): # Arrange @@ -264,14 +260,12 @@ def test_database_error(self, mock_context, mock_db, cli_runner): with pytest.raises(Exception, match="Database error"): stp_interface_edgeport_enable(mock_db, self.valid_interface) - def test_missing_interface_argument(self, cli_runner): # Test CLI command without required interface argument result = cli_runner.invoke(stp_interface_edgeport_enable, ['enable']) assert result.exit_code != 0 assert "Missing argument" in result.output - @patch('click.get_current_context') def test_empty_interface_name(self, mock_context, mock_db, cli_runner): # Arrange @@ -279,14 +273,14 @@ def test_empty_interface_name(self, mock_context, mock_db, cli_runner): # Act & Assert with pytest.raises(click.ClickException): stp_interface_edgeport_enable(mock_db, "") - + # Integration test example def test_integration_enable_edgeport(mock_db, cli_runner): # This test would require more setup of the actual database # and would test the entire flow from CLI to database modification - result = cli_runner.invoke(stp_interface_edgeport_enable, - ['enable', 'Ethernet0']) + result = cli_runner.invoke(stp_interface_edgeport_enable, + ['enable', 'Ethernet0']) assert result.exit_code == 0