37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
import pytest
|
|
from unittest.mock import patch, MagicMock
|
|
from src.api_hook_client import ApiHookClient
|
|
|
|
def test_api_ask_client_method() -> None:
|
|
"""Tests the request_confirmation method in ApiHookClient."""
|
|
client = ApiHookClient()
|
|
# Mock the internal _make_request method
|
|
with patch.object(client, '_make_request') as mock_make:
|
|
# Simulate a successful confirmation
|
|
mock_make.return_value = {"response": True}
|
|
|
|
args = {"script": "echo hello", "base_dir": "."}
|
|
result = client.request_confirmation("run_powershell", args)
|
|
|
|
assert result is True
|
|
mock_make.assert_called_once_with(
|
|
'POST',
|
|
'/api/ask',
|
|
data={'type': 'tool_approval', 'tool': 'run_powershell', 'args': args},
|
|
timeout=60.0
|
|
)
|
|
|
|
def test_api_ask_client_rejection() -> None:
|
|
client = ApiHookClient()
|
|
with patch.object(client, '_make_request') as mock_make:
|
|
mock_make.return_value = {"response": False}
|
|
result = client.request_confirmation("run_powershell", {})
|
|
assert result is False
|
|
|
|
def test_api_ask_client_error() -> None:
|
|
client = ApiHookClient()
|
|
with patch.object(client, '_make_request') as mock_make:
|
|
mock_make.return_value = None
|
|
result = client.request_confirmation("run_powershell", {})
|
|
assert result is None
|