Spaces:
Running
Running
File size: 1,821 Bytes
774ec97 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from fastapi.testclient import TestClient
from api.main import app
import json
client = TestClient(app)
def test_root_endpoint():
"""Test endpoint raíz"""
response = client.get("/")
assert response.status_code == 200
assert "status" in response.json()
print("✓ Root endpoint test passed")
def test_health_endpoint():
"""Test health check"""
response = client.get("/health")
assert response.status_code == 200
assert response.json()["status"] == "healthy"
print("✓ Health endpoint test passed")
def test_chat_endpoint():
"""Test chat endpoint"""
chat_data = {
"message": "hola, tengo una duda",
"user_id": "test_user_123"
}
response = client.post("/chat", json=chat_data)
assert response.status_code == 200
data = response.json()
assert "response" in data
assert len(data["response"]) > 0
# Verificar headers
assert "X-User-ID" in response.headers
assert "X-Conversation-ID" in response.headers
print("✓ Chat endpoint test passed")
def test_feedback_endpoint():
"""Test feedback endpoint"""
feedback_data = {
"conversation_id": "test_conv_123",
"message_id": "test_msg_456",
"is_helpful": True,
"feedback_text": "Muy útil la respuesta"
}
response = client.post("/feedback", json=feedback_data)
assert response.status_code == 200
assert response.json()["status"] == "success"
print("✓ Feedback endpoint test passed")
if __name__ == "__main__":
test_root_endpoint()
test_health_endpoint()
test_chat_endpoint()
test_feedback_endpoint()
print("\n✅ Todos los tests de API pasaron correctamente!") |