| | import requests |
| | import time |
| | import subprocess |
| | import signal |
| | import os |
| | import sys |
| |
|
| | def test_api(): |
| | |
| | print("Starting FastAPI server...") |
| | server_process = subprocess.Popen([ |
| | sys.executable, "-m", "uvicorn", "backend.main:app", |
| | "--host", "0.0.0.0", "--port", "8000", "--log-level", "warning" |
| | ], cwd=os.getcwd()) |
| |
|
| | |
| | time.sleep(3) |
| |
|
| | try: |
| | base_url = "http://localhost:8000" |
| |
|
| | |
| | print("Testing root endpoint...") |
| | response = requests.get(f"{base_url}/") |
| | print(f"Status: {response.status_code}") |
| | print(f"Response: {response.json()}") |
| |
|
| | |
| | print("Testing health endpoint...") |
| | response = requests.get(f"{base_url}/health") |
| | print(f"Status: {response.status_code}") |
| | print(f"Response: {response.json()}") |
| |
|
| | |
| | print("Testing analyze/frame endpoint...") |
| | response = requests.post(f"{base_url}/analyze/frame") |
| | print(f"Status: {response.status_code}") |
| | print(f"Response: {response.text}") |
| |
|
| | print("All tests passed!") |
| |
|
| | except Exception as e: |
| | print(f"Test failed: {e}") |
| | return False |
| | finally: |
| | |
| | server_process.terminate() |
| | server_process.wait() |
| |
|
| | return True |
| |
|
| | if __name__ == "__main__": |
| | success = test_api() |
| | sys.exit(0 if success else 1) |