Skip to content

Commit

Permalink
added max hops testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
kanza-latif committed Jan 15, 2025
1 parent 6aedd67 commit 6c4327a
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions tests/test_config_stp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -264,29 +260,27 @@ 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
mock_context.return_value = MagicMock()
# 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


Expand Down

0 comments on commit 6c4327a

Please sign in to comment.