-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_functional.py
More file actions
257 lines (192 loc) · 7.56 KB
/
Copy pathtest_functional.py
File metadata and controls
257 lines (192 loc) · 7.56 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/usr/bin/env python3
"""
Flowbite MCP Server - Funkčné testovanie
Test základnej funkčnosti MCP servera s reálnymi dependencies
"""
import asyncio
import sys
import os
import json
from pathlib import Path
# Pridáme src do path
sys.path.insert(0, str(Path(__file__).parent / "src"))
async def test_imports():
"""Test importu všetkých modulov"""
print("🔍 Testovanie importov...")
try:
# Test základných importov
from src.config import get_config, ServerConfig
print("✅ Config import OK")
from src.models.component import Component, ComponentRequest, ComponentResponse
print("✅ Models import OK")
from src.tools.generator import ComponentGenerator
print("✅ Generator import OK")
from src.tools.validator import ComponentValidator
print("✅ Validator import OK")
from src.tools.suggestions import ComponentSuggestions
print("✅ Suggestions import OK")
from src.resources.component_db import ComponentDatabase
print("✅ Database import OK")
from src.resources.documentation import DocumentationResource
print("✅ Documentation import OK")
# Test FastMCP importu
from fastmcp import FastMCP
print("✅ FastMCP import OK")
return True
except ImportError as e:
print(f"❌ Import error: {e}")
return False
except Exception as e:
print(f"❌ Unexpected error: {e}")
return False
async def test_config():
"""Test konfigurácie"""
print("\n🔍 Testovanie konfigurácie...")
try:
from src.config import get_config
config = get_config()
print(f"✅ Config načítaný: {config.name}")
print(f"✅ Verzia: {config.version}")
print(f"✅ Data dir: {config.data_dir}")
# Test že data_dir existuje
if Path(config.data_dir).exists():
print("✅ Data directory existuje")
else:
print("❌ Data directory neexistuje")
return True
except Exception as e:
print(f"❌ Config error: {e}")
return False
async def test_component_database():
"""Test component databázy"""
print("\n🔍 Testovanie component databázy...")
try:
from src.resources.component_db import ComponentDatabase
db = ComponentDatabase()
await db.initialize()
print("✅ Database inicializovaná")
# Test načítania komponentov
components = await db.get_all_components()
print(f"✅ Načítaných {len(components)} komponentov")
# Test získania variantov
if components:
first_component = list(components.keys())[0]
variants = await db.get_variants(first_component)
print(f"✅ Component '{first_component}' má {len(variants)} variant")
return True
except Exception as e:
print(f"❌ Database error: {e}")
import traceback
traceback.print_exc()
return False
async def test_component_generator():
"""Test component generátora"""
print("\n🔍 Testovanie component generátora...")
try:
from src.tools.generator import ComponentGenerator
from src.resources.component_db import ComponentDatabase
# Inicializácia
db = ComponentDatabase()
await db.initialize()
generator = ComponentGenerator(db)
# Test generovania button komponenta
result = await generator.generate_component(
component_type="button",
variant="primary",
props={"text": "Test Button", "size": "md"}
)
print("✅ Button component vygenerovaný")
print(f" HTML dĺžka: {len(result.get('html', ''))}")
print(f" CSS classes: {len(result.get('css_classes', []))}")
return True
except Exception as e:
print(f"❌ Generator error: {e}")
import traceback
traceback.print_exc()
return False
async def test_component_validator():
"""Test component validátora"""
print("\n🔍 Testovanie component validátora...")
try:
from src.tools.validator import ComponentValidator
from src.resources.component_db import ComponentDatabase
# Inicializácia
db = ComponentDatabase()
await db.initialize()
validator = ComponentValidator(db)
# Test validácie správneho HTML
valid_html = '<button class="bg-blue-500 text-white px-4 py-2 rounded">Test</button>'
result = await validator.validate_component(
html=valid_html,
component_type="button"
)
print("✅ Validator test dokončený")
print(f" Validation result: {result.get('is_valid', False)}")
return True
except Exception as e:
print(f"❌ Validator error: {e}")
import traceback
traceback.print_exc()
return False
async def test_component_suggestions():
"""Test component suggestions"""
print("\n🔍 Testovanie component suggestions...")
try:
from src.tools.suggestions import ComponentSuggestions
from src.resources.component_db import ComponentDatabase
# Inicializácia
db = ComponentDatabase()
await db.initialize()
suggestions = ComponentSuggestions(db)
# Test návrhov
result = await suggestions.suggest_components(
description="I need a blue button for form submission",
limit=3
)
print("✅ Suggestions test dokončený")
print(f" Počet návrhov: {len(result.get('suggestions', []))}")
return True
except Exception as e:
print(f"❌ Suggestions error: {e}")
import traceback
traceback.print_exc()
return False
async def main():
"""Hlavná test funkcia"""
print("🚀 Flowbite MCP Server - Funkčné testovanie")
print("=" * 50)
tests = [
("Importy", test_imports),
("Konfigurácia", test_config),
("Component databáza", test_component_database),
("Component generátor", test_component_generator),
("Component validátor", test_component_validator),
("Component suggestions", test_component_suggestions)
]
results = []
for test_name, test_func in tests:
try:
result = await test_func()
results.append((test_name, result))
except Exception as e:
print(f"❌ {test_name} failed with exception: {e}")
results.append((test_name, False))
# Súhrn
print("\n" + "=" * 50)
print("📋 SÚHRN FUNKČNÉHO TESTOVANIA")
print("=" * 50)
passed = sum(1 for _, result in results if result)
total = len(results)
for test_name, result in results:
status = "✅ PREŠIEL" if result else "❌ NEPREŠIEL"
print(f"{status}: {test_name}")
print(f"\n📊 Výsledok: {passed}/{total} testov prešlo")
if passed == total:
print("🎉 Všetky funkčné testy úspešné!")
print("🚀 Server je pripravený na produkčné použitie!")
else:
print("⚠️ Niektoré testy zlyhali - potrebná ďalšia oprava")
return passed == total
if __name__ == "__main__":
success = asyncio.run(main())
sys.exit(0 if success else 1)