Fix: Test Process Text
This commit is contained in:
parent
db895532a8
commit
379708e986
@ -1,38 +1,27 @@
|
||||
#!/usr/bin/env python3
|
||||
from fastapi.testclient import TestClient
|
||||
from app.server import app
|
||||
from app.server import app # Asegúrate de importar tu aplicación FastAPI
|
||||
|
||||
# Crea un cliente de prueba
|
||||
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?"}]}
|
||||
}]
|
||||
def test_process_text():
|
||||
# Define el texto de entrada
|
||||
input_text = {"text": "Hola, ¿cómo estás?"}
|
||||
|
||||
# Simular la función `graph.stream` usando mocker
|
||||
mock_stream = mocker.patch('app.graph.stream', return_value=mock_response)
|
||||
# Realiza una solicitud POST al endpoint
|
||||
response = client.post("/process_text", json=input_text)
|
||||
|
||||
# Realizar la solicitud POST
|
||||
response = client.post('/process_text', json={"text": test_input})
|
||||
|
||||
# Comprobar que el estado de la respuesta es 200 (éxito)
|
||||
# Verifica que la respuesta tenga un código de estado 200
|
||||
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
|
||||
# Verifica que la respuesta contenga la clave 'response'
|
||||
assert 'response' in response.json()
|
||||
|
||||
# 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"
|
||||
)
|
||||
# Verifica que la respuesta sea una lista
|
||||
assert isinstance(response.json()['response'], list)
|
||||
|
||||
# Aquí puedes agregar más verificaciones
|
||||
# según lo que esperas en la respuesta
|
||||
# Por ejemplo, verificar que la lista no esté vacía
|
||||
assert len(response.json()['response']) > 0
|
||||
|
Loading…
Reference in New Issue
Block a user