forked from Rockachopa/Timmy-time-dashboard
feat: implement v1 API endpoints for iPad app
This commit is contained in:
52
tests/test_api_v1.py
Normal file
52
tests/test_api_v1.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import sys
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
# Absolute path to src
|
||||
src_path = "/home/ubuntu/timmy-time/Timmy-time-dashboard/src"
|
||||
if src_path not in sys.path:
|
||||
sys.path.insert(0, src_path)
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
try:
|
||||
from dashboard.app import app
|
||||
print("✓ Successfully imported dashboard.app")
|
||||
except ImportError as e:
|
||||
print(f"✗ Failed to import dashboard.app: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
def test_v1_status():
|
||||
response = client.get("/api/v1/status")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "timmy" in data
|
||||
assert "model" in data
|
||||
assert "uptime" in data
|
||||
|
||||
def test_v1_chat_history():
|
||||
response = client.get("/api/v1/chat/history")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "messages" in data
|
||||
|
||||
def test_v1_upload_fail():
|
||||
# Test without file
|
||||
response = client.post("/api/v1/upload")
|
||||
assert response.status_code == 422 # Unprocessable Entity (missing file)
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Running API v1 tests...")
|
||||
try:
|
||||
test_v1_status()
|
||||
print("✓ Status test passed")
|
||||
test_v1_chat_history()
|
||||
print("✓ History test passed")
|
||||
test_v1_upload_fail()
|
||||
print("✓ Upload failure test passed")
|
||||
print("All tests passed!")
|
||||
except Exception as e:
|
||||
print(f"Test failed: {e}")
|
||||
sys.exit(1)
|
||||
Reference in New Issue
Block a user