forked from jacepark12/ticktick-mcp
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_integration.py
More file actions
183 lines (149 loc) · 5.45 KB
/
test_integration.py
File metadata and controls
183 lines (149 loc) · 5.45 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/env python3
"""
Integration test for TickTick MCP server CLI startup.
This test verifies that the server can start up properly and catches import errors.
"""
import subprocess
import sys
import os
from pathlib import Path
def test_cli_import():
"""Test that the CLI module can be imported without errors."""
print("Testing CLI module import...")
# Test importing the CLI module directly
try:
import ticktick_mcp.cli
print("✅ CLI module imported successfully")
return True
except ImportError as e:
print(f"❌ CLI module import failed: {e}")
return False
except Exception as e:
print(f"❌ Unexpected error during CLI import: {e}")
return False
def test_server_import():
"""Test that the server module can be imported without errors."""
print("Testing server module import...")
# Test importing the server module directly
try:
import ticktick_mcp.src.server
print("✅ Server module imported successfully")
return True
except ImportError as e:
print(f"❌ Server module import failed: {e}")
return False
except Exception as e:
print(f"❌ Unexpected error during server import: {e}")
return False
def test_cli_help_command():
"""Test that the CLI help command works without errors."""
print("Testing CLI help command...")
# Change to the project directory
project_dir = Path(__file__).parent
try:
# Run the CLI help command
result = subprocess.run(
["/opt/homebrew/bin/uv", "run", "-m", "ticktick_mcp.cli", "run", "--help"],
cwd=project_dir,
capture_output=True,
text=True,
timeout=10
)
if result.returncode == 0:
print("✅ CLI help command executed successfully")
return True
else:
print(f"❌ CLI help command failed with exit code {result.returncode}")
print(f"STDOUT: {result.stdout}")
print(f"STDERR: {result.stderr}")
return False
except subprocess.TimeoutExpired:
print("❌ CLI help command timed out")
return False
except Exception as e:
print(f"❌ Error running CLI help command: {e}")
return False
def test_cli_startup_simulation():
"""Test that the CLI can start up (simulate without actually running the server)."""
print("Testing CLI startup simulation...")
project_dir = Path(__file__).parent
try:
# Try to start the server but timeout quickly to just test startup
result = subprocess.run(
["/opt/homebrew/bin/uv", "run", "-m", "ticktick_mcp.cli", "run"],
cwd=project_dir,
capture_output=True,
text=True,
timeout=5 # Give it 5 seconds to start up
)
# We expect this to timeout or be killed, but not crash on import
if "Error starting server" in result.stderr:
print(f"❌ Server startup failed: {result.stderr}")
return False
elif "NameError" in result.stderr or "ImportError" in result.stderr:
print(f"❌ Import error during startup: {result.stderr}")
return False
else:
print("✅ CLI startup simulation passed (no import errors)")
return True
except subprocess.TimeoutExpired:
print("✅ CLI startup simulation passed (timed out as expected)")
return True
except Exception as e:
print(f"❌ Error during CLI startup simulation: {e}")
return False
def test_auth_command():
"""Test that the auth command can be imported and shows help."""
print("Testing auth command...")
project_dir = Path(__file__).parent
try:
# Run the auth help command
result = subprocess.run(
["/opt/homebrew/bin/uv", "run", "-m", "ticktick_mcp.cli", "auth", "--help"],
cwd=project_dir,
capture_output=True,
text=True,
timeout=10
)
if result.returncode == 0:
print("✅ Auth command executed successfully")
return True
else:
print(f"❌ Auth command failed with exit code {result.returncode}")
print(f"STDERR: {result.stderr}")
return False
except subprocess.TimeoutExpired:
print("❌ Auth command timed out")
return False
except Exception as e:
print(f"❌ Error running auth command: {e}")
return False
def main():
"""Run all integration tests."""
print("Running TickTick MCP integration tests...\n")
tests = [
test_cli_import,
test_server_import,
test_cli_help_command,
test_cli_startup_simulation,
test_auth_command,
]
passed = 0
total = len(tests)
for test in tests:
try:
if test():
passed += 1
print() # Add spacing between tests
except Exception as e:
print(f"❌ Test {test.__name__} crashed: {e}\n")
print(f"Integration test results: {passed}/{total} tests passed")
if passed == total:
print("🎉 All integration tests passed!")
return True
else:
print("❌ Some integration tests failed.")
return False
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)