File size: 2,457 Bytes
c9d1b27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import requests
import sys
import time

def verify_endpoints():
    print("=======================================")
    print("🔍 Mahoraga Space Endpoint Verification")
    print("=======================================\n")
    
    BASE_URL = "http://localhost:7860"
    all_passed = True

    # 1. Test Frontend Serve
    print("1️⃣  Testing Frontend Catch-all Route (/) ...", end=" ")
    try:
        response = requests.get(f"{BASE_URL}/", timeout=5)
        if response.status_code == 200 and "<html" in response.text.lower():
            print("✅ PASSED")
        else:
            print(f"❌ FAILED (Status: {response.status_code}, Is HTML: {'<html' in response.text.lower()})")
            all_passed = False
    except requests.exceptions.RequestException as e:
        print(f"❌ FAILED (Connection Error: {e})")
        all_passed = False

    # 2. Test Backend API (/api/model-status)
    print("2️⃣  Testing Backend API (/api/model-status) ...", end=" ")
    try:
        response = requests.get(f"{BASE_URL}/api/model-status", timeout=5)
        if response.status_code == 200:
            try:
                data = response.json()
                print("✅ PASSED")
            except ValueError:
                print("❌ FAILED (Did not return valid JSON)")
                all_passed = False
        else:
            print(f"❌ FAILED (Status: {response.status_code})")
            all_passed = False
    except requests.exceptions.RequestException as e:
        print(f"❌ FAILED (Connection Error: {e})")
        all_passed = False
        
    # 3. Test React Router Fallback (/some-random-path)
    print("3️⃣  Testing React Router Fallback (/random-path) ...", end=" ")
    try:
        response = requests.get(f"{BASE_URL}/random-path", timeout=5)
        if response.status_code == 200 and "<html" in response.text.lower():
            print("✅ PASSED")
        else:
            print(f"❌ FAILED (Status: {response.status_code})")
            all_passed = False
    except requests.exceptions.RequestException as e:
        print(f"❌ FAILED (Connection Error: {e})")
        all_passed = False

    print("\n=======================================")
    if all_passed:
        print("🎉 ALL TESTS PASSED! Your Space is ready.")
        sys.exit(0)
    else:
        print("⚠️  SOME TESTS FAILED. Please check the logs.")
        sys.exit(1)

if __name__ == "__main__":
    verify_endpoints()