vienoux's picture
Upload folder using huggingface_hub
f9adcbf verified
"""
Tests for FastAPI endpoints
"""
import pytest
from fastapi.testclient import TestClient
import app.main as main_module
from app.core.orchestrator import Orchestrator
@pytest.fixture(scope="module")
def test_orchestrator():
"""Create orchestrator for testing"""
return Orchestrator()
@pytest.fixture(scope="module", autouse=True)
async def setup_orchestrator(test_orchestrator):
"""Initialize orchestrator before tests"""
await test_orchestrator.initialize()
# Inject into main module
main_module.orchestrator = test_orchestrator
yield
await test_orchestrator.shutdown()
client = TestClient(main_module.app)
def test_health_endpoint():
"""Test health check endpoint"""
response = client.get("/health")
assert response.status_code == 200
data = response.json()
assert data["status"] == "healthy"
assert "version" in data
def test_query_format_endpoint(unformatted_python_code):
"""Test query endpoint for format task"""
response = client.post(
"/api/v1/query",
json={
"task": "format",
"code": unformatted_python_code,
"language": "python"
}
)
assert response.status_code == 200
data = response.json()
assert data["success"] is True
assert data["used_automata"] is True
assert "result" in data
assert "pipeline" in data
def test_query_fix_endpoint(buggy_python_code):
"""Test query endpoint for fix task"""
response = client.post(
"/api/v1/query",
json={
"task": "fix",
"code": buggy_python_code,
"language": "python"
}
)
assert response.status_code == 200
data = response.json()
assert data["success"] is True
assert "result" in data
def test_query_invalid_task():
"""Test query endpoint with invalid task"""
response = client.post(
"/api/v1/query",
json={
"task": "invalid_task",
"code": "def foo(): pass",
"language": "python"
}
)
# Should return validation error
assert response.status_code == 422
def test_query_missing_code():
"""Test query endpoint with missing code"""
response = client.post(
"/api/v1/query",
json={
"task": "format",
"language": "python"
}
)
# Should return validation error
assert response.status_code == 422
def test_query_with_context():
"""Test query endpoint with context parameter"""
response = client.post(
"/api/v1/query",
json={
"task": "boilerplate",
"code": "",
"language": "python",
"context": "Create a function to validate email addresses"
}
)
assert response.status_code == 200
data = response.json()
# May use SLM or fail gracefully
assert "success" in data
def test_query_with_trace(sample_trace):
"""Test query endpoint with trace parameter"""
response = client.post(
"/api/v1/query",
json={
"task": "explain",
"code": "def divide(a, b): return a / b",
"language": "python",
"trace": sample_trace
}
)
assert response.status_code == 200
data = response.json()
assert "success" in data
def test_stats_endpoint():
"""Test stats endpoint"""
response = client.get("/api/v1/stats")
# Stats endpoint may not exist yet in V1
# Just check it doesn't crash
assert response.status_code in [200, 404]