File size: 2,670 Bytes
1459a60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Test script for TransitApp MCP Server
Verifies all MCP tools are working correctly
"""

import json
from app import (
    get_nearby_transit,
    plan_trip,
    get_realtime_vehicle_location,
    get_service_alerts,
    compare_trip_modes,
    search_stops_and_stations
)

def test_tool(tool_name, func, *args):
    """Test a single MCP tool"""
    print(f"\n{'='*60}")
    print(f"Testing: {tool_name}")
    print('='*60)
    try:
        result = func(*args)
        data = json.loads(result)
        print(json.dumps(data, indent=2))
        print(f"✅ {tool_name} - PASSED")
        return True
    except Exception as e:
        print(f"❌ {tool_name} - FAILED: {e}")
        return False

def main():
    """Run all tests"""
    print("🚇 TransitApp MCP Server - Testing Suite")
    print("=========================================\n")
    
    tests_passed = 0
    tests_total = 0
    
    # Test 1: Nearby Transit
    tests_total += 1
    if test_tool(
        "get_nearby_transit",
        get_nearby_transit,
        40.7420, -73.9871, 500, "all"
    ):
        tests_passed += 1
    
    # Test 2: Trip Planning
    tests_total += 1
    if test_tool(
        "plan_trip",
        plan_trip,
        40.7420, -73.9871, 40.7060, -74.0110, "now", "all", "balanced"
    ):
        tests_passed += 1
    
    # Test 3: Real-time Vehicle Location
    tests_total += 1
    if test_tool(
        "get_realtime_vehicle_location",
        get_realtime_vehicle_location,
        "M15", "both"
    ):
        tests_passed += 1
    
    # Test 4: Service Alerts
    tests_total += 1
    if test_tool(
        "get_service_alerts",
        get_service_alerts,
        40.7420, -73.9871, 5000, "all"
    ):
        tests_passed += 1
    
    # Test 5: Mode Comparison
    tests_total += 1
    if test_tool(
        "compare_trip_modes",
        compare_trip_modes,
        40.7420, -73.9871, 40.7060, -74.0110
    ):
        tests_passed += 1
    
    # Test 6: Search Stops
    tests_total += 1
    if test_tool(
        "search_stops_and_stations",
        search_stops_and_stations,
        "23rd St", 40.7420, -73.9871, 10
    ):
        tests_passed += 1
    
    # Summary
    print(f"\n{'='*60}")
    print("TEST SUMMARY")
    print('='*60)
    print(f"Tests Passed: {tests_passed}/{tests_total}")
    print(f"Success Rate: {tests_passed/tests_total*100:.1f}%")
    
    if tests_passed == tests_total:
        print("\n✅ All tests passed! Server is ready for deployment.")
        return 0
    else:
        print(f"\n⚠️  {tests_total - tests_passed} test(s) failed. Review errors above.")
        return 1

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