| import asyncio
|
| import io
|
| import time
|
| import requests
|
| import uvicorn
|
| import threading
|
| from PIL import Image
|
| from cora_engine import CoraEngine
|
| from fastapi.testclient import TestClient
|
| from api import app
|
|
|
| def create_dummy_image():
|
| img = Image.new('RGB', (100, 100), color = 'white')
|
| return img
|
|
|
| def test_engine_logic():
|
| print("\n--- Testing CoraEngine ---")
|
| try:
|
| engine = CoraEngine()
|
| if not engine.client:
|
| print("FAIL: Engine initialized/HuggingFace Client missing (Check .env)")
|
| return False
|
|
|
| print("PASS: Engine Initialized")
|
|
|
|
|
| big_img = Image.new('RGB', (2000, 2000), color='white')
|
| resized = engine.resize_image(big_img, max_size=1024)
|
| if resized.size != (1024, 1024):
|
| print(f"FAIL: Resize logic incorrect. Got {resized.size}")
|
| return False
|
| print("PASS: Resize Logic")
|
| return True
|
| except Exception as e:
|
| print(f"FAIL: Engine Error - {e}")
|
| return False
|
|
|
| def test_api_logic():
|
| print("\n--- Testing API (TestClient) ---")
|
| client = TestClient(app)
|
|
|
|
|
| try:
|
| response = client.get("/health")
|
| if response.status_code == 200 and response.json().get("status") == "online":
|
| print("PASS: /health endpoint")
|
| else:
|
| print(f"FAIL: /health endpoint - {response.json()}")
|
| except Exception as e:
|
| print(f"FAIL: API Error - {e}")
|
|
|
| if __name__ == "__main__":
|
| img = create_dummy_image()
|
|
|
| if test_engine_logic():
|
| test_api_logic()
|
| else:
|
| print("Skipping API test due to Engine failure.")
|
|
|