surf-spot-finder-mcp / mcp_server /tests /test_ui_integration.py
D3MI4N's picture
Production ready app version
7b6b271
#!/usr/bin/env python3
"""
Test script for the Gradio UI functionality
"""
import sys
import os
# Add paths for imports
sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'hf_space'))
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
def test_mcp_client():
"""Test the MCP client integration"""
print("πŸ§ͺ Testing MCP Client Integration...")
try:
from mcp_client import find_best_spots
# Test with a simple location
print(" Testing: MΓ‘laga, Spain")
result = find_best_spots("MΓ‘laga, Spain", max_distance_km=50, top_n=3)
if result.get("ok"):
spots = result.get("results", [])
ai_summary = result.get("ai_summary", "")
print(f" βœ… Found {len(spots)} surf spots")
if ai_summary:
print(f" πŸ€– AI Summary: {ai_summary[:100]}...")
for i, spot in enumerate(spots[:2], 1):
print(f" {i}. {spot['name']} - Score: {spot['score']}/100")
return True
else:
print(f" ❌ Error: {result.get('error')}")
return False
except Exception as e:
print(f" πŸ’₯ Exception: {e}")
return False
def test_ui_functions():
"""Test UI formatting functions"""
print("\n🎨 Testing UI Functions...")
try:
from app import format_spot_results, run_surf_finder
# Test with sample data
sample_spots = [
{
"name": "Test Spot",
"score": 85.5,
"distance_km": 25.3,
"conditions": {"wave_height": 1.5, "wind_speed": 10},
"explain": "Good conditions for surfing with moderate waves and favorable wind direction"
}
]
spots_html, ai_html, reasoning = format_spot_results(sample_spots, "Test AI summary")
if "Test Spot" in spots_html and "85.5" in spots_html:
print(" βœ… Spot formatting works correctly")
else:
print(" ❌ Spot formatting failed")
return False
if "Test AI summary" in ai_html:
print(" βœ… AI summary formatting works")
else:
print(" ❌ AI summary formatting failed")
return False
return True
except Exception as e:
print(f" πŸ’₯ Exception: {e}")
return False
def main():
"""Run all tests"""
print("πŸš€ Testing Surf Spot Finder UI Components")
print("=" * 50)
# Test MCP integration
client_ok = test_mcp_client()
# Test UI functions
ui_ok = test_ui_functions()
print("\n" + "=" * 50)
print("πŸ“Š Test Results:")
print(f" MCP Client: {'βœ…' if client_ok else '❌'}")
print(f" UI Functions: {'βœ…' if ui_ok else '❌'}")
if client_ok and ui_ok:
print("\nπŸŽ‰ All tests passed! UI is ready for deployment.")
print("πŸ’‘ The Gradio app should work correctly on HF Space.")
else:
print("\n⚠️ Some tests failed. Check the issues above.")
return client_ok and ui_ok
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)