a1d-mcp-server / test_app.py
yuxh1996's picture
Initial commit: A1D MCP Server with Gradio interface
aaa3e82
#!/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())