fix: use in-memory checkpointer for API tests to avoid database dependency

- Replace PostgreSQL AsyncPostgresSaver with MemorySaver in test fixtures
- Create test_app fixture with test_lifespan using in-memory dependencies
- Mock LLM model to avoid requiring API keys during tests
- Update test_api.py to use test_app fixture instead of production app
- Fix test_root endpoint URL to match root_path configuration
- All API tests now pass without requiring external services (0.06s vs 30s+ timeout)

This change allows tests to run in isolation without PostgreSQL or API keys,
making them faster and more reliable for CI/CD and local development.
This commit is contained in:
2026-06-10 16:06:10 -05:00
parent 7fa4d12e30
commit 34053b3fc1
3 changed files with 86 additions and 13 deletions

View File

@@ -1,16 +1,16 @@
import pytest
from fastapi.testclient import TestClient
from src.naliiabotapi.main import app
@pytest.fixture
def client():
with TestClient(app) as client:
def client(test_app):
"""Create a test client using the test app with in-memory dependencies."""
with TestClient(test_app) as client:
yield client
def test_root(client):
response = client.get("/")
response = client.get("/agent/api")
assert response.status_code == 200
@@ -22,7 +22,9 @@ def test_health(client):
def test_chat(client):
response = client.post("/chat", json={"messages": "Hello, how are you?"})
response = client.post(
"/chat", json={"messages": "Hello, how are you?"}
)
assert response.status_code == 200
assert response.json() is not None