surf-spot-finder-mcp / mcp_server /tests /test_modal_integration_production.py
D3MI4N's picture
fix modal image config
ed5b955
#!/usr/bin/env python3
"""
Test script for Modal integration in production
Tests the deployed Modal endpoint and HF Space integration
"""
import os
import sys
import requests
import pytest
# Production Modal URL
MODAL_URL = "https://mcp-model-labs--surf-spot-finder-mcp-api-find-spots.modal.run"
HEALTH_URL = "https://mcp-model-labs--surf-spot-finder-mcp-health-check.modal.run"
def test_modal_health_endpoint():
"""Test the Modal health check endpoint"""
try:
response = requests.get(HEALTH_URL, timeout=10)
response.raise_for_status()
result = response.json()
assert result.get("status") == "healthy"
assert result.get("service") == "surf-spot-finder-mcp"
print("βœ… Modal health check passed")
except Exception as e:
pytest.fail(f"Health check failed: {e}")
def test_modal_surf_endpoint():
"""Test the Modal surf spot finder endpoint"""
payload = {
"location": "MΓ‘laga, Spain",
"max_distance": 50,
"num_spots": 3,
"preferences": {"skill_level": "intermediate"}
}
try:
response = requests.post(MODAL_URL, json=payload, timeout=30)
response.raise_for_status()
result = response.json()
assert result.get("ok") == True
assert result.get("success") == True
assert "user_location" in result
assert "spots" in result
assert len(result["spots"]) > 0
# Check spot structure
spot = result["spots"][0]
required_fields = ["name", "score", "latitude", "longitude", "distance_km", "explanation", "conditions", "breakdown"]
for field in required_fields:
assert field in spot, f"Missing field: {field}"
assert isinstance(spot["score"], (int, float))
assert 0 <= spot["score"] <= 100
print(f"βœ… Found {len(result['spots'])} surf spots")
print(f"πŸ„β€β™‚οΈ Best spot: {spot['name']} (Score: {spot['score']}/100)")
except Exception as e:
pytest.fail(f"Modal surf endpoint failed: {e}")
def test_hf_space_integration():
"""Test HF Space MCP client with Modal"""
# Set Modal URL environment variable
os.environ["MODAL_URL"] = MODAL_URL
# Add hf_space to path
hf_space_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "hf_space")
sys.path.insert(0, hf_space_path)
try:
from mcp_client import find_best_spots
result = find_best_spots(
user_location="MΓ‘laga, Spain",
max_distance_km=50,
top_n=3,
prefs={"skill_level": "intermediate"}
)
assert result.get("ok") == True
assert "results" in result
assert len(result["results"]) > 0
# Check result structure matches HF Space expectations
spot = result["results"][0]
required_fields = ["name", "score", "latitude", "longitude", "distance_km", "explanation", "conditions", "breakdown"]
for field in required_fields:
assert field in spot, f"Missing field: {field}"
print(f"βœ… HF Space client integration working")
print(f"πŸ€– AI Summary: {result.get('ai_summary', 'N/A')}")
except ImportError:
pytest.skip("HF Space MCP client not available")
except Exception as e:
pytest.fail(f"HF Space integration failed: {e}")
def test_different_locations():
"""Test Modal endpoint with different locations"""
test_locations = [
("Lisbon, Portugal", "European Atlantic coast"),
("Los Angeles, California", "US Pacific coast"),
("Sydney, Australia", "Australian coast")
]
for location, description in test_locations:
payload = {
"location": location,
"max_distance": 100,
"num_spots": 2,
"preferences": {"skill_level": "advanced"}
}
try:
response = requests.post(MODAL_URL, json=payload, timeout=30)
response.raise_for_status()
result = response.json()
assert result.get("ok") == True
print(f"βœ… {description}: {len(result.get('spots', []))} spots found")
except Exception as e:
print(f"⚠️ {description} test failed: {e}")
# Don't fail the test for remote locations that might not have spots
if __name__ == "__main__":
print("πŸ„β€β™‚οΈ Testing Modal Production Integration")
print("=" * 60)
print("\n1. Testing Modal health endpoint...")
test_modal_health_endpoint()
print("\n2. Testing Modal surf endpoint...")
test_modal_surf_endpoint()
print("\n3. Testing HF Space integration...")
test_hf_space_integration()
print("\n4. Testing different locations...")
test_different_locations()
print("\n" + "=" * 60)
print("πŸŽ‰ All Modal integration tests completed!")
print(f"βœ… Production Modal URL: {MODAL_URL}")
print("πŸ”— Modal Dashboard: https://modal.com/apps/mcp-model-labs/main/deployed/surf-spot-finder-mcp")