From cc0116466a0ace48eaab6c3c6b926d93d6debe80 Mon Sep 17 00:00:00 2001 From: phernandez Date: Thu, 26 Dec 2024 21:24:32 -0600 Subject: [PATCH] fix entity_repository --- tests/conftest.py | 13 ++++++++++--- tests/repository/test_entity_repository.py | 13 +++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index af69dc05..e77a87df 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -21,7 +21,8 @@ from basic_memory.services import ( EntityService, ObservationService, RelationService, - DocumentService, FileSyncService, + DocumentService, + FileSyncService, ) from basic_memory.services.file_service import FileService from basic_memory.services.knowledge.service import KnowledgeService @@ -142,13 +143,13 @@ def knowledge_writer(): """Create writer instance.""" return KnowledgeWriter() + @pytest_asyncio.fixture def file_sync_service(document_repository, entity_repository) -> FileSyncService: """Create FileSyncService instance.""" return FileSyncService(document_repository, entity_repository) - @pytest_asyncio.fixture async def knowledge_service( entity_service: EntityService, @@ -172,5 +173,11 @@ async def knowledge_service( @pytest_asyncio.fixture(scope="function") async def sample_entity(entity_repository: EntityRepository) -> Entity: """Create a sample entity for testing.""" - entity_data = {"name": "Test Entity", "entity_type": "test", "description": "A test entity", "path_id": "test/test_entity"} + entity_data = { + "name": "Test Entity", + "entity_type": "test", + "description": "A test entity", + "path_id": "test/test_entity", + "file_path": "test/test_entity.md", + } return await entity_repository.create(entity_data) diff --git a/tests/repository/test_entity_repository.py b/tests/repository/test_entity_repository.py index dc731f66..0c56cc1b 100644 --- a/tests/repository/test_entity_repository.py +++ b/tests/repository/test_entity_repository.py @@ -32,12 +32,14 @@ async def related_entities(session_maker): name="source", entity_type="source", path_id="source/source", + file_path="source/source.md", description="Source entity", ) target = Entity( name="target", entity_type="target", path_id="target/target", + file_path="target/target.md", description="Target entity", ) session.add(source) @@ -57,6 +59,7 @@ async def test_create_entity(entity_repository: EntityRepository): "name": "Test", "entity_type": "test", "path_id": "test/test", + "file_path": "test/test.md", "description": "Test description", } entity = await entity_repository.create(entity_data) @@ -89,12 +92,14 @@ async def test_create_all(entity_repository: EntityRepository): "name": "Test_1", "entity_type": "test", "path_id": "test/test_1", + "file_path": "test/test_1.md", "description": "Test description", }, { "name": "Test-2", "entity_type": "test", "path_id": "test/test_2", + "file_path": "test/test_2.md", "description": "Test description", }, ] @@ -124,6 +129,7 @@ async def test_entity_type_name_unique_constraint(entity_repository: EntityRepos "name": "Test Entity", "entity_type": "type1", "path_id": "type1/test_entity", + "file_path": "type1/test_entity1.md", "description": "First entity", } await entity_repository.create(entity1_data) @@ -133,6 +139,7 @@ async def test_entity_type_name_unique_constraint(entity_repository: EntityRepos "name": "Test Entity", # Same name "entity_type": "type1", # Same type "path_id": "type1/test_entity", + "file_path": "type1/test_entity2.md", "description": "Second entity", } @@ -149,6 +156,7 @@ async def test_create_entity_null_description(session_maker, entity_repository: "name": "Test", "entity_type": "test", "path_id": "test/test", + "file_path": "test/test.md", "description": None, } entity = await entity_repository.create(entity_data) @@ -297,12 +305,14 @@ async def test_search(session_maker, entity_repository: EntityRepository): name="Search Test 1", entity_type="test", path_id="test/search_test_1", + file_path="test/search_test_1.md", description="First test entity", ) entity2 = Entity( name="Search Test 2", entity_type="other", path_id="other/search_test_2", + file_path="other/search_test_2.md", description="Second test entity", ) session.add_all([entity1, entity2]) @@ -353,18 +363,21 @@ async def test_entities(session_maker): entity_type="type1", description="First test entity", path_id="type1/entity1", + file_path="type1/entity1.md", ), Entity( name="entity2", entity_type="type1", description="Second test entity", path_id="type1/entity2", + file_path="type1/entity2.md", ), Entity( name="entity3", entity_type="type2", description="Third test entity", path_id="type2/entity3", + file_path="type2/entity3.md", ), ] session.add_all(entities)