mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-19 04:14:46 +08:00
test: add unit tests of the app (#305)
* test: add unit tests in server * test: add unit tests of app.py in server * test: reformat the codes * test: add more tests to cover the exception part * test: add more tests on the server app part * fix: don't show the detail exception to the client * test: try to fix the CI test * fix: keep the TTS API call without exposure information * Fixed the unit test errors * Fixed the lint error
This commit is contained in:
73
tests/unit/server/test_mcp_request.py
Normal file
73
tests/unit/server/test_mcp_request.py
Normal file
@@ -0,0 +1,73 @@
|
||||
# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import pytest
|
||||
from pydantic import ValidationError
|
||||
from src.server.mcp_request import MCPServerMetadataRequest, MCPServerMetadataResponse
|
||||
|
||||
|
||||
def test_mcp_server_metadata_request_required_fields():
|
||||
# 'transport' is required
|
||||
req = MCPServerMetadataRequest(transport="stdio")
|
||||
assert req.transport == "stdio"
|
||||
assert req.command is None
|
||||
assert req.args is None
|
||||
assert req.url is None
|
||||
assert req.env is None
|
||||
assert req.timeout_seconds is None
|
||||
|
||||
|
||||
def test_mcp_server_metadata_request_optional_fields():
|
||||
req = MCPServerMetadataRequest(
|
||||
transport="sse",
|
||||
command="run",
|
||||
args=["--foo", "bar"],
|
||||
url="http://localhost:8080",
|
||||
env={"FOO": "BAR"},
|
||||
timeout_seconds=30,
|
||||
)
|
||||
assert req.transport == "sse"
|
||||
assert req.command == "run"
|
||||
assert req.args == ["--foo", "bar"]
|
||||
assert req.url == "http://localhost:8080"
|
||||
assert req.env == {"FOO": "BAR"}
|
||||
assert req.timeout_seconds == 30
|
||||
|
||||
|
||||
def test_mcp_server_metadata_request_missing_transport():
|
||||
with pytest.raises(ValidationError):
|
||||
MCPServerMetadataRequest()
|
||||
|
||||
|
||||
def test_mcp_server_metadata_response_required_fields():
|
||||
resp = MCPServerMetadataResponse(transport="stdio")
|
||||
assert resp.transport == "stdio"
|
||||
assert resp.command is None
|
||||
assert resp.args is None
|
||||
assert resp.url is None
|
||||
assert resp.env is None
|
||||
assert resp.tools == []
|
||||
|
||||
|
||||
def test_mcp_server_metadata_response_optional_fields():
|
||||
resp = MCPServerMetadataResponse(
|
||||
transport="sse",
|
||||
command="run",
|
||||
args=["--foo", "bar"],
|
||||
url="http://localhost:8080",
|
||||
env={"FOO": "BAR"},
|
||||
tools=["tool1", "tool2"],
|
||||
)
|
||||
assert resp.transport == "sse"
|
||||
assert resp.command == "run"
|
||||
assert resp.args == ["--foo", "bar"]
|
||||
assert resp.url == "http://localhost:8080"
|
||||
assert resp.env == {"FOO": "BAR"}
|
||||
assert resp.tools == ["tool1", "tool2"]
|
||||
|
||||
|
||||
def test_mcp_server_metadata_response_tools_default_factory():
|
||||
resp1 = MCPServerMetadataResponse(transport="stdio")
|
||||
resp2 = MCPServerMetadataResponse(transport="stdio")
|
||||
resp1.tools.append("toolA")
|
||||
assert resp2.tools == [] # Should not share list between instances
|
||||
Reference in New Issue
Block a user