mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 01:48:04 +08:00
test(api): add autospec to MagicMock-based patch usage (#32752)
This commit is contained in:
@ -32,7 +32,7 @@ class TestConstants:
|
||||
class TestCreateSSRFProxyMCPHTTPClient:
|
||||
"""Test create_ssrf_proxy_mcp_http_client function."""
|
||||
|
||||
@patch("core.mcp.utils.dify_config")
|
||||
@patch("core.mcp.utils.dify_config", autospec=True)
|
||||
def test_create_client_with_all_url_proxy(self, mock_config):
|
||||
"""Test client creation with SSRF_PROXY_ALL_URL configured."""
|
||||
mock_config.SSRF_PROXY_ALL_URL = "http://proxy.example.com:8080"
|
||||
@ -50,7 +50,7 @@ class TestCreateSSRFProxyMCPHTTPClient:
|
||||
# Clean up
|
||||
client.close()
|
||||
|
||||
@patch("core.mcp.utils.dify_config")
|
||||
@patch("core.mcp.utils.dify_config", autospec=True)
|
||||
def test_create_client_with_http_https_proxies(self, mock_config):
|
||||
"""Test client creation with separate HTTP/HTTPS proxies."""
|
||||
mock_config.SSRF_PROXY_ALL_URL = None
|
||||
@ -66,7 +66,7 @@ class TestCreateSSRFProxyMCPHTTPClient:
|
||||
# Clean up
|
||||
client.close()
|
||||
|
||||
@patch("core.mcp.utils.dify_config")
|
||||
@patch("core.mcp.utils.dify_config", autospec=True)
|
||||
def test_create_client_without_proxy(self, mock_config):
|
||||
"""Test client creation without proxy configuration."""
|
||||
mock_config.SSRF_PROXY_ALL_URL = None
|
||||
@ -88,7 +88,7 @@ class TestCreateSSRFProxyMCPHTTPClient:
|
||||
# Clean up
|
||||
client.close()
|
||||
|
||||
@patch("core.mcp.utils.dify_config")
|
||||
@patch("core.mcp.utils.dify_config", autospec=True)
|
||||
def test_create_client_default_params(self, mock_config):
|
||||
"""Test client creation with default parameters."""
|
||||
mock_config.SSRF_PROXY_ALL_URL = None
|
||||
@ -111,8 +111,8 @@ class TestCreateSSRFProxyMCPHTTPClient:
|
||||
class TestSSRFProxySSEConnect:
|
||||
"""Test ssrf_proxy_sse_connect function."""
|
||||
|
||||
@patch("core.mcp.utils.connect_sse")
|
||||
@patch("core.mcp.utils.create_ssrf_proxy_mcp_http_client")
|
||||
@patch("core.mcp.utils.connect_sse", autospec=True)
|
||||
@patch("core.mcp.utils.create_ssrf_proxy_mcp_http_client", autospec=True)
|
||||
def test_sse_connect_with_provided_client(self, mock_create_client, mock_connect_sse):
|
||||
"""Test SSE connection with pre-configured client."""
|
||||
# Setup mocks
|
||||
@ -138,9 +138,9 @@ class TestSSRFProxySSEConnect:
|
||||
# Verify result
|
||||
assert result == mock_context
|
||||
|
||||
@patch("core.mcp.utils.connect_sse")
|
||||
@patch("core.mcp.utils.create_ssrf_proxy_mcp_http_client")
|
||||
@patch("core.mcp.utils.dify_config")
|
||||
@patch("core.mcp.utils.connect_sse", autospec=True)
|
||||
@patch("core.mcp.utils.create_ssrf_proxy_mcp_http_client", autospec=True)
|
||||
@patch("core.mcp.utils.dify_config", autospec=True)
|
||||
def test_sse_connect_without_client(self, mock_config, mock_create_client, mock_connect_sse):
|
||||
"""Test SSE connection without pre-configured client."""
|
||||
# Setup config
|
||||
@ -183,8 +183,8 @@ class TestSSRFProxySSEConnect:
|
||||
# Verify result
|
||||
assert result == mock_context
|
||||
|
||||
@patch("core.mcp.utils.connect_sse")
|
||||
@patch("core.mcp.utils.create_ssrf_proxy_mcp_http_client")
|
||||
@patch("core.mcp.utils.connect_sse", autospec=True)
|
||||
@patch("core.mcp.utils.create_ssrf_proxy_mcp_http_client", autospec=True)
|
||||
def test_sse_connect_with_custom_timeout(self, mock_create_client, mock_connect_sse):
|
||||
"""Test SSE connection with custom timeout."""
|
||||
# Setup mocks
|
||||
@ -209,8 +209,8 @@ class TestSSRFProxySSEConnect:
|
||||
# Verify result
|
||||
assert result == mock_context
|
||||
|
||||
@patch("core.mcp.utils.connect_sse")
|
||||
@patch("core.mcp.utils.create_ssrf_proxy_mcp_http_client")
|
||||
@patch("core.mcp.utils.connect_sse", autospec=True)
|
||||
@patch("core.mcp.utils.create_ssrf_proxy_mcp_http_client", autospec=True)
|
||||
def test_sse_connect_error_cleanup(self, mock_create_client, mock_connect_sse):
|
||||
"""Test SSE connection cleans up client on error."""
|
||||
# Setup mocks
|
||||
@ -227,7 +227,7 @@ class TestSSRFProxySSEConnect:
|
||||
# Verify client was cleaned up
|
||||
mock_client.close.assert_called_once()
|
||||
|
||||
@patch("core.mcp.utils.connect_sse")
|
||||
@patch("core.mcp.utils.connect_sse", autospec=True)
|
||||
def test_sse_connect_error_no_cleanup_with_provided_client(self, mock_connect_sse):
|
||||
"""Test SSE connection doesn't clean up provided client on error."""
|
||||
# Setup mocks
|
||||
|
||||
Reference in New Issue
Block a user