test - fix delete keys

This commit is contained in:
Ishaan Jaff 2025-07-02 22:23:03 -07:00
parent 42cd05dee8
commit 282ce1a859

View file

@ -116,9 +116,36 @@ def test_keys_generate_error_handling(mock_keys_client, cli_runner):
def test_keys_delete_error_handling(mock_keys_client, cli_runner):
mock_keys_client.return_value.delete.side_effect = Exception("API Error")
import requests
# Mock a connection error that would normally happen in CI
mock_keys_client.return_value.delete.side_effect = requests.exceptions.ConnectionError(
"Connection error"
)
result = cli_runner.invoke(cli, ["keys", "delete", "--keys", "abc123"])
assert result.exit_code != 0
# Check that the exception is properly propagated
assert result.exception is not None
assert "API Error" in str(result.exception)
# The ConnectionError should propagate since it's not caught by HTTPError handler
assert "Connection error" in str(result.exception)
def test_keys_delete_http_error_handling(mock_keys_client, cli_runner):
from unittest.mock import Mock
import requests
# Create a mock response object for HTTPError
mock_response = Mock()
mock_response.status_code = 400
mock_response.json.return_value = {"error": "Bad request"}
# Mock an HTTPError which should be caught by the delete command
http_error = requests.exceptions.HTTPError("HTTP Error")
http_error.response = mock_response
mock_keys_client.return_value.delete.side_effect = http_error
result = cli_runner.invoke(cli, ["keys", "delete", "--keys", "abc123"])
assert result.exit_code != 0
# HTTPError should be caught and converted to click.Abort
assert isinstance(result.exception, SystemExit) # click.Abort raises SystemExit