Files
basicmachines-co-basic-memory/tests/mcp/test_tool_get_entity.py
T
2025-01-31 19:29:16 -06:00

49 lines
1.3 KiB
Python

"""Tests for get_entity MCP tool."""
import pytest
from mcp.server.fastmcp.exceptions import ToolError
from basic_memory.mcp.tools import notes
from basic_memory.mcp.tools.knowledge import get_entity
from basic_memory.schemas.base import Entity, ObservationCategory
@pytest.mark.asyncio
async def test_get_basic_entity(client):
"""Test retrieving a basic entity."""
# First create an entity
permalink = await notes.write_note(
title="Test Note",
folder="test",
content="""
# Test\nThis is a test note
- [note] First observation
""",
tags=["test", "documentation"]
)
assert permalink # Got a valid permalink
# Get the entity without content
entity = await get_entity(permalink)
# Verify entity details
assert entity.file_path == "test/Test Note.md"
assert entity.entity_type == "note"
assert entity.permalink == "test/test-note"
# Check observations
assert len(entity.observations) == 1
obs = entity.observations[0]
assert obs.content == "First observation"
assert obs.category == ObservationCategory.NOTE
@pytest.mark.asyncio
async def test_get_nonexistent_entity(client):
"""Test attempting to get a non-existent entity."""
with pytest.raises(ToolError):
await get_entity("test/nonexistent")