Fix: LangChain Dependences
This commit is contained in:
0
app/test/__init__.py
Normal file
0
app/test/__init__.py
Normal file
38
app/test/test_main.py
Normal file
38
app/test/test_main.py
Normal file
@@ -0,0 +1,38 @@
|
||||
#!/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"
|
||||
)
|
||||
Reference in New Issue
Block a user