File size: 3,384 Bytes
aaa3e82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Test script for A1D MCP Server
"""

import os
import sys

def test_imports():
    """Test if all modules can be imported"""
    try:
        import gradio as gr
        print("βœ… Gradio imported successfully")
        
        import config
        print("βœ… Config module imported successfully")
        
        import utils
        print("βœ… Utils module imported successfully")
        
        import app
        print("βœ… App module imported successfully")
        
        return True
    except ImportError as e:
        print(f"❌ Import error: {e}")
        return False

def test_config():
    """Test configuration"""
    try:
        from config import TOOLS_CONFIG, GRADIO_CONFIG
        
        print(f"βœ… Found {len(TOOLS_CONFIG)} tools configured:")
        for tool_name in TOOLS_CONFIG.keys():
            print(f"   - {tool_name}")
        
        print(f"βœ… Gradio config: {GRADIO_CONFIG['title']}")
        return True
    except Exception as e:
        print(f"❌ Config error: {e}")
        return False

def test_gradio_app():
    """Test Gradio app creation"""
    try:
        # Set a dummy API key for testing
        os.environ['A1D_API_KEY'] = 'test_key_for_demo'
        
        from app import create_gradio_app
        demo = create_gradio_app()
        
        print("βœ… Gradio app created successfully")
        print(f"βœ… App title: {demo.title}")
        
        return True
    except Exception as e:
        print(f"❌ Gradio app error: {e}")
        return False

def test_tool_functions():
    """Test individual tool functions"""
    try:
        # Set a dummy API key for testing
        os.environ['A1D_API_KEY'] = 'test_key_for_demo'
        
        from app import remove_bg, image_upscaler, image_generator
        
        # Test with invalid inputs to check validation
        result = remove_bg("invalid_url")
        if "Invalid image URL format" in result:
            print("βœ… URL validation working")
        
        result = image_upscaler("invalid_url", 3)
        if "Invalid image URL format" in result:
            print("βœ… Image upscaler validation working")
        
        result = image_generator("")
        if "Prompt is required" in result:
            print("βœ… Prompt validation working")
        
        return True
    except Exception as e:
        print(f"❌ Tool function error: {e}")
        return False

def main():
    """Run all tests"""
    print("πŸ§ͺ Testing A1D MCP Server...")
    print("=" * 50)
    
    tests = [
        ("Imports", test_imports),
        ("Configuration", test_config),
        ("Gradio App", test_gradio_app),
        ("Tool Functions", test_tool_functions),
    ]
    
    passed = 0
    total = len(tests)
    
    for test_name, test_func in tests:
        print(f"\nπŸ“‹ Testing {test_name}...")
        if test_func():
            passed += 1
            print(f"βœ… {test_name} test passed")
        else:
            print(f"❌ {test_name} test failed")
    
    print("\n" + "=" * 50)
    print(f"🎯 Test Results: {passed}/{total} tests passed")
    
    if passed == total:
        print("πŸŽ‰ All tests passed! The MCP server is ready to use.")
        return 0
    else:
        print("⚠️  Some tests failed. Please check the errors above.")
        return 1

if __name__ == "__main__":
    sys.exit(main())