feat(mcp): 5 outils notes + tests
Ajoute search_notes, get_note, create_note, update_note, delete_note au serveur MCP. Tests: 6 nouveaux tests notes (13 tests MCP au total, tous passent). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
import json
|
||||
import pytest
|
||||
from sqlalchemy import delete
|
||||
import app.api.mcp_server as mcp_server_module
|
||||
from app.api.mcp_server import (
|
||||
get_todos, create_todo, update_todo, postpone_todo, delete_todo,
|
||||
)
|
||||
from app.core.database import AsyncSessionLocal
|
||||
from app.api.mcp_server import (
|
||||
search_notes, get_note, create_note, update_note, delete_note,
|
||||
)
|
||||
from app.models.todos import TodoItem
|
||||
from app.models.notes import NoteItem
|
||||
|
||||
pytestmark = pytest.mark.usefixtures("mcp_nullpool_session")
|
||||
|
||||
@@ -13,8 +17,10 @@ pytestmark = pytest.mark.usefixtures("mcp_nullpool_session")
|
||||
@pytest.fixture(autouse=True)
|
||||
async def cleanup_mcp_todos():
|
||||
yield
|
||||
async with AsyncSessionLocal() as session:
|
||||
# Utilise AsyncSessionLocal depuis le module mcp_server (patché par mcp_nullpool_session)
|
||||
async with mcp_server_module.AsyncSessionLocal() as session:
|
||||
await session.execute(delete(TodoItem).where(TodoItem.title.like("TEST_MCP_%")))
|
||||
await session.execute(delete(NoteItem).where(NoteItem.title.like("TEST_MCP_%")))
|
||||
await session.commit()
|
||||
|
||||
|
||||
@@ -67,3 +73,51 @@ async def test_delete_todo_introuvable():
|
||||
result = await delete_todo(id="00000000-0000-0000-0000-000000000000")
|
||||
data = json.loads(result)
|
||||
assert "error" in data
|
||||
|
||||
|
||||
# ── NOTES ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
async def test_search_notes_retourne_liste():
|
||||
result = await search_notes(query="inexistant_xyz_abc_999")
|
||||
data = json.loads(result)
|
||||
assert isinstance(data, list)
|
||||
assert data == []
|
||||
|
||||
|
||||
async def test_create_note_outil():
|
||||
result = await create_note(title="TEST_MCP_note_create", content="Contenu de test MCP")
|
||||
data = json.loads(result)
|
||||
assert data["title"] == "TEST_MCP_note_create"
|
||||
assert "id" in data
|
||||
await delete_note(id=str(data["id"]))
|
||||
|
||||
|
||||
async def test_get_note_outil():
|
||||
created = json.loads(await create_note(title="TEST_MCP_note_get", content="Contenu get"))
|
||||
result = await get_note(id=str(created["id"]))
|
||||
data = json.loads(result)
|
||||
assert data["title"] == "TEST_MCP_note_get"
|
||||
assert data["content"] == "Contenu get"
|
||||
assert "attachments" in data
|
||||
await delete_note(id=str(created["id"]))
|
||||
|
||||
|
||||
async def test_update_note_outil():
|
||||
created = json.loads(await create_note(title="TEST_MCP_note_update", content="avant"))
|
||||
result = await update_note(id=str(created["id"]), content="après")
|
||||
data = json.loads(result)
|
||||
assert "id" in data
|
||||
await delete_note(id=str(created["id"]))
|
||||
|
||||
|
||||
async def test_delete_note_outil():
|
||||
created = json.loads(await create_note(title="TEST_MCP_note_delete", content="x"))
|
||||
result = await delete_note(id=str(created["id"]))
|
||||
data = json.loads(result)
|
||||
assert "deleted" in data
|
||||
|
||||
|
||||
async def test_get_note_introuvable():
|
||||
result = await get_note(id="00000000-0000-0000-0000-000000000000")
|
||||
data = json.loads(result)
|
||||
assert "error" in data
|
||||
|
||||
Reference in New Issue
Block a user