fix repository tests

This commit is contained in:
phernandez
2024-12-22 12:17:59 -06:00
parent c2d16acb59
commit 955fe899ab
5 changed files with 10 additions and 19 deletions
+1
View File
@@ -87,6 +87,7 @@ class Observation(Base):
id: Mapped[int] = mapped_column(Integer, primary_key=True)
entity_id: Mapped[int] = mapped_column(Integer, ForeignKey("entity.id"))
content: Mapped[str] = mapped_column(Text)
context: Mapped[str] = mapped_column(Text, nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=text("CURRENT_TIMESTAMP"))
# Relationships
@@ -2,7 +2,6 @@
from typing import Sequence
from loguru import logger
from sqlalchemy import select
from sqlalchemy.ext.asyncio import async_sessionmaker
@@ -15,9 +14,8 @@ class ObservationRepository(Repository[Observation]):
def __init__(self, session_maker: async_sessionmaker):
super().__init__(session_maker, Observation)
logger.debug("Initialized ObservationRepository")
async def find_by_entity(self, entity_id: str) -> Sequence[Observation]:
async def find_by_entity(self, entity_id: int) -> Sequence[Observation]:
"""Find all observations for a specific entity."""
query = select(Observation).filter(Observation.entity_id == entity_id)
result = await self.execute_query(query)
@@ -15,13 +15,13 @@ class RelationRepository(Repository[Relation]):
def __init__(self, session_maker: async_sessionmaker):
super().__init__(session_maker, Relation)
async def find_by_entity(self, from_entity_id: str) -> Sequence[Relation]:
async def find_by_entity(self, from_entity_id: int) -> Sequence[Relation]:
"""Find all relations from a specific entity."""
query = select(Relation).filter(Relation.from_id == from_entity_id)
result = await self.execute_query(query)
return result.scalars().all()
async def find_by_entities(self, from_id: str, to_id: str) -> Sequence[Relation]:
async def find_by_entities(self, from_id: int, to_id: int) -> Sequence[Relation]:
"""Find all relations between two entities."""
query = select(Relation).filter(and_(Relation.from_id == from_id, Relation.to_id == to_id))
result = await self.execute_query(query)