refactor Repository constructor arg in EntityService

This commit is contained in:
phernandez
2024-12-03 17:38:48 -06:00
parent 0c535a8208
commit e00ecfb3ad
2 changed files with 11 additions and 6 deletions
+3 -4
View File
@@ -1,9 +1,8 @@
from datetime import datetime, UTC
from pathlib import Path
from typing import Dict, Optional
from typing import Dict
from uuid import uuid4
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.exc import IntegrityError
from basic_memory.models import Entity
@@ -31,9 +30,9 @@ class EntityService:
Follows the "filesystem is source of truth" principle.
"""
def __init__(self, project_path: Path, session: AsyncSession):
def __init__(self, project_path: Path, entity_repo: EntityRepository):
self.project_path = project_path
self.entity_repo = EntityRepository(session, Entity)
self.entity_repo = entity_repo
self.entities_path = project_path / "entities"
@staticmethod
+8 -2
View File
@@ -7,6 +7,7 @@ from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker
from sqlalchemy.pool import StaticPool
from basic_memory.models import Base, Entity
from basic_memory.repository import EntityRepository
from basic_memory.services import EntityService, FileOperationError, DatabaseSyncError, EntityNotFoundError
pytestmark = pytest.mark.asyncio
@@ -38,14 +39,19 @@ async def session(engine):
yield session
@pytest_asyncio.fixture
async def entity_service(session):
async def entity_repo(session):
"""Create an EntityRepository instance."""
return EntityRepository(session, Entity)
@pytest_asyncio.fixture
async def entity_service(session, entity_repo):
"""Fixture providing initialized EntityService with temp directories."""
with tempfile.TemporaryDirectory() as temp_dir:
project_path = Path(temp_dir) / "test-project"
entities_path = project_path / "entities"
entities_path.mkdir(parents=True)
service = EntityService(project_path, session)
service = EntityService(project_path, entity_repo)
yield service
# Happy Path Tests