-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_server.py
More file actions
81 lines (70 loc) · 2.66 KB
/
test_server.py
File metadata and controls
81 lines (70 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""Integration tests for the MCP server — tool registration, lifecycle, and configuration."""
import pytest
from nextcloud_mcp.config import Config
from nextcloud_mcp.permissions import PermissionLevel
from nextcloud_mcp.server import create_server
pytestmark = pytest.mark.integration
EXPECTED_TOOLS = [
"close_poll",
"create_conversation",
"create_directory",
"create_poll",
"delete_file",
"delete_message",
"dismiss_all_notifications",
"dismiss_notification",
"get_conversation",
"get_current_user",
"get_file",
"get_messages",
"get_participants",
"get_poll",
"get_user",
"leave_conversation",
"list_conversations",
"list_directory",
"list_notifications",
"list_users",
"move_file",
"send_message",
"upload_file",
"vote_poll",
]
class TestServerCreation:
@pytest.mark.asyncio
async def test_all_tools_registered(self, nc_config: Config) -> None:
mcp = create_server(nc_config)
names = sorted(t.name for t in mcp._tool_manager.list_tools())
assert names == EXPECTED_TOOLS
@pytest.mark.asyncio
async def test_tool_count(self, nc_config: Config) -> None:
mcp = create_server(nc_config)
assert len(mcp._tool_manager.list_tools()) == len(EXPECTED_TOOLS)
@pytest.mark.asyncio
async def test_every_tool_has_description(self, nc_config: Config) -> None:
mcp = create_server(nc_config)
for tool in mcp._tool_manager.list_tools():
assert tool.description, f"Tool '{tool.name}' has no description"
assert len(tool.description) > 20, f"Tool '{tool.name}' description too short"
@pytest.mark.asyncio
async def test_server_name(self, nc_config: Config) -> None:
mcp = create_server(nc_config)
assert mcp.name == "nextcloud-mcp-server"
@pytest.mark.asyncio
async def test_create_server_with_different_permissions(self) -> None:
for level in PermissionLevel:
config = Config(
nextcloud_url="http://nextcloud.ncmcp",
user="admin",
password="admin",
permission_level=level,
)
mcp = create_server(config)
assert len(mcp._tool_manager.list_tools()) == len(EXPECTED_TOOLS)
@pytest.mark.asyncio
async def test_create_server_from_env(self, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("NEXTCLOUD_URL", "http://nextcloud.ncmcp")
monkeypatch.setenv("NEXTCLOUD_USER", "admin")
monkeypatch.setenv("NEXTCLOUD_PASSWORD", "admin")
mcp = create_server()
assert len(mcp._tool_manager.list_tools()) == len(EXPECTED_TOOLS)