at-engine / test_engine.py
Godswill-IoT's picture
Upload 15 files
fb9f2a9 verified
"""
Test Script for Avatar-based AI Tutor Engine
"""
import requests
import json
BASE_URL = "http://127.0.0.1:8003"
def test_health():
"""Test health endpoint"""
print("\n=== Testing Health Endpoint ===")
response = requests.get(f"{BASE_URL}/health")
print(f"Status: {response.status_code}")
print(f"Response: {json.dumps(response.json(), indent=2)}")
return response.status_code == 200
def test_root():
"""Test root endpoint"""
print("\n=== Testing Root Endpoint ===")
response = requests.get(f"{BASE_URL}/")
print(f"Status: {response.status_code}")
print(f"Response: {json.dumps(response.json(), indent=2)}")
return response.status_code == 200
def test_create_avatar_tutor():
"""Test avatar tutor creation"""
print("\n=== Testing Avatar Tutor Creation ===")
payload = {
"request_id": "test-001",
"engine": "avatar-tutor-engine",
"action": "create_avatar_tutor",
"actor": {
"user_id": "test-user",
"session_id": "test-session"
},
"input": {
"text": "Introduction to Python: Python is a versatile programming language.",
"items": [
{
"type": "image",
"ref": "https://example.com/photo.jpg"
},
{
"type": "audio",
"ref": "https://example.com/voice.mp3"
}
]
},
"context": {},
"options": {
"lesson_duration": "3 minutes"
}
}
print(f"Request: {json.dumps(payload, indent=2)}\n")
try:
response = requests.post(f"{BASE_URL}/run", json=payload, timeout=60)
print(f"Status: {response.status_code}")
print(f"Response: {json.dumps(response.json(), indent=2)}")
return response.status_code == 200
except Exception as e:
print(f"Error: {e}")
return False
def test_missing_image():
"""Test error handling for missing image"""
print("\n=== Testing Missing Image Error ===")
payload = {
"request_id": "test-error-001",
"engine": "avatar-tutor-engine",
"action": "create_avatar_tutor",
"actor": {
"user_id": "test-user",
"session_id": None
},
"input": {
"text": "Some content",
"items": [
{
"type": "audio",
"ref": "https://example.com/voice.mp3"
}
]
},
"context": {},
"options": {}
}
response = requests.post(f"{BASE_URL}/run", json=payload)
print(f"Status: {response.status_code}")
result = response.json()
print(f"Response: {json.dumps(result, indent=2)}")
return not result.get("ok") and result.get("error", {}).get("code") == "MISSING_IMAGE"
def test_invalid_action():
"""Test error handling for invalid action"""
print("\n=== Testing Invalid Action Error ===")
payload = {
"request_id": "test-error-002",
"engine": "avatar-tutor-engine",
"action": "invalid_action",
"actor": {
"user_id": "test-user",
"session_id": None
},
"input": {
"text": "Some content",
"items": []
},
"context": {},
"options": {}
}
response = requests.post(f"{BASE_URL}/run", json=payload)
print(f"Status: {response.status_code}")
result = response.json()
print(f"Response: {json.dumps(result, indent=2)}")
return not result.get("ok") and result.get("error", {}).get("code") == "INVALID_ACTION"
def main():
"""Run all tests"""
print("=" * 60)
print("Avatar-based AI Tutor Engine - Test Suite")
print("=" * 60)
tests = [
("Health Check", test_health),
("Root Endpoint", test_root),
("Create Avatar Tutor", test_create_avatar_tutor),
("Missing Image Error", test_missing_image),
("Invalid Action Error", test_invalid_action)
]
results = []
for name, test_func in tests:
try:
passed = test_func()
results.append((name, passed))
except Exception as e:
print(f"\nTest '{name}' failed with exception: {e}")
results.append((name, False))
# Summary
print("\n" + "=" * 60)
print("Test Summary")
print("=" * 60)
for name, passed in results:
status = "✓ PASSED" if passed else "✗ FAILED"
print(f"{status}: {name}")
total = len(results)
passed = sum(1 for _, p in results if p)
print(f"\nTotal: {passed}/{total} tests passed")
if __name__ == "__main__":
main()