Spaces:
Running
Running
File size: 3,955 Bytes
69c20e8 |
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 110 111 112 113 114 |
import time
import requests
import sys
def test_server():
base_url = "http://127.0.0.1:8000"
print("β³ Waiting for server to start...")
# Retry logic to wait for server
for i in range(10):
try:
response = requests.get(f"{base_url}/")
if response.status_code == 200:
print("Server detected!")
break
except requests.exceptions.ConnectionError:
time.sleep(1)
print(f"Attempt {i+1}/10: Server not ready yet...")
else:
print("β Error: Server failed to start within 10 seconds.")
sys.exit(1)
# 1. Health Check (Root Endpoint)
print("\nπ Checking Root Endpoint (/) ...")
try:
response = requests.get(f"{base_url}/")
print(f"Status Code: {response.status_code}")
print(f"Response: {response.json()}")
if response.status_code != 200:
print("β Root endpoint check failed!")
sys.exit(1)
except Exception as e:
print(f"β unexpected error on root check: {e}")
sys.exit(1)
# 2. Docs Check (/docs)
print("\nπ Checking Docs Endpoint (/docs) ...")
try:
response = requests.get(f"{base_url}/docs")
print(f"Status Code: {response.status_code}")
if response.status_code == 200:
print("β
API Documentation is accessible.")
else:
print(f"β Docs endpoint check failed! Status: {response.status_code}")
sys.exit(1)
except Exception as e:
print(f"β unexpected error on docs check: {e}")
sys.exit(1)
print("\nβ
Server is Healthy!")
# 3. Analyze Trends Check (/analyze-trends/{niche})
print("\nπ Checking Trend Spotter (/analyze-trends/cats) ...")
try:
response = requests.get(f"{base_url}/analyze-trends/cats")
print(f"Status Code: {response.status_code}")
print(f"Response: {response.json()}")
if response.status_code == 200:
print("β
Trend Spotter is working!")
else:
print("β Trend Spotter check failed!")
sys.exit(1)
except Exception as e:
print(f"β unexpected error on trend spotter check: {e}")
sys.exit(1)
# 4. Visionary Agent Check (/generate-design)
print("\nπ Checking Visionary Agent (/generate-design) ...")
try:
payload = {"slogan": "Gravity Check", "niche": "Science"}
response = requests.post(f"{base_url}/generate-design", json=payload)
print(f"Status Code: {response.status_code}")
print(f"Response: {response.json()}")
if response.status_code == 200:
print("β
Visionary is working!")
else:
print("β Visionary check failed!")
sys.exit(1)
except Exception as e:
print(f"β unexpected error on visionary check: {e}")
sys.exit(1)
# 5. Manager Agent Check (/run-batch)
print("\nπ Checking Manager Agent (/run-batch) ...")
try:
import os
payload = {"niche": "Coffee"}
response = requests.post(f"{base_url}/run-batch", json=payload)
print(f"Status Code: {response.status_code}")
print(f"Response: {response.json()}")
if response.status_code == 200:
filename = response.json().get("filename")
results_path = os.path.join("results", filename)
if os.path.exists(results_path):
print(f"β
Manager is working! CSV created at: {results_path}")
else:
print(f"β Batch ran but file not found: {results_path}")
sys.exit(1)
else:
print("β Manager check failed!")
sys.exit(1)
except Exception as e:
print(f"β unexpected error on manager check: {e}")
sys.exit(1)
if __name__ == "__main__":
test_server()
|