oc-assistant/app/test/test_main.py

39 lines
1.2 KiB
Python

#!/usr/bin/env python3
from fastapi.testclient import TestClient
from ..server import app
client = TestClient(app)
def test_process_text(mocker):
# Configurar el texto de entrada
test_input = "Hola, ¿cómo estás?"
mock_response = [{
"agent": {
"messages": [{"content": "Estoy bien, ¿en qué te puedo ayudar?"}]}
}]
# Simular la función `graph.stream` usando mocker
mock_stream = mocker.patch('app.graph.stream', return_value=mock_response)
# Realizar la solicitud POST
response = client.post('/process_text', json={"text": test_input})
# Comprobar que el estado de la respuesta es 200 (éxito)
assert response.status_code == 200
# Verificar la respuesta JSON
json_data = response.json()
expected_response = {
'response': ["Estoy bien, ¿en qué te puedo ayudar?"]
}
assert json_data == expected_response
# Confirmar que `graph.stream` fue llamada con los parámetros correctos
mock_stream.assert_called_once_with(
{"messages": [("user", test_input)], "is_last_step": False},
config={"configurable": {
"thread_id": "thread-1", "recursion_limit": 50}},
stream_mode="updates"
)