feat: Implement MemorySaver

This commit is contained in:
2026-02-27 00:47:16 -05:00
parent 4b2d02eca8
commit da2c2a1528
3 changed files with 144 additions and 7 deletions

View File

@@ -1,12 +1,36 @@
import pytest
from types import SimpleNamespace
from httpx import ASGITransport, AsyncClient
from naliiabotapi.main import app
from naliiabotapi.api.dependencies import get_agent
class TestWebhookChatBot:
"""Tests for WebhookChatBot."""
@pytest.mark.anyio
async def tests_webhook_success(self, async_client):
"""Test that the webhook endpoint returns a successful response."""
response = await async_client.post("/webhook", json={"message": "Hello"})
async def tests_webhook_success(self, send_message_payload):
"""Test that the webhook endpoint returns a successful response.
Se crea un `mock_agent` con `invoke` mockeado y se inyecta
mediante `app.dependency_overrides` antes de realizar la petición.
"""
# Crear mock del agente y su invoke
mock_agent = SimpleNamespace()
def mock_invoke(state, config=None):
return {"messages": [SimpleNamespace(content="Respuesta mock")]}
mock_agent.invoke = mock_invoke
# Sobrescribir la dependencia del agente en la app
app.dependency_overrides[get_agent] = lambda: mock_agent
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://localhost:8010") as client:
response = await client.post("/webhook", json=send_message_payload)
# Limpiar override para no afectar a otros tests
app.dependency_overrides.pop(get_agent, None)
assert response.status_code == 200
assert response.json() == {"reply": "Hello, how can I assist you?"}
assert response.json().get("reply") == "Respuesta mock"