From a3daea883b774c3fe1b9329a4bc4332a12ed1ce9 Mon Sep 17 00:00:00 2001 From: Daniel O'Connell Date: Thu, 26 Jun 2025 14:10:31 +0200 Subject: [PATCH] fix tests --- .gitignore | 3 +++ src/memory/common/db/models/source_item.py | 2 +- src/memory/common/db/models/source_items.py | 4 ++-- tests/memory/common/db/models/test_source_item.py | 4 +++- tests/memory/common/db/models/test_source_items.py | 2 ++ tests/memory/workers/tasks/test_ebook_tasks.py | 5 +++-- tests/memory/workers/test_email.py | 2 ++ 7 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 600b98f..72cb856 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ + +Books +CLAUDE.md memory_files venv .env diff --git a/src/memory/common/db/models/source_item.py b/src/memory/common/db/models/source_item.py index 1f52aad..49c66b4 100644 --- a/src/memory/common/db/models/source_item.py +++ b/src/memory/common/db/models/source_item.py @@ -370,7 +370,7 @@ class SourceItem(Base): @property def display_contents(self) -> str | dict | None: payload = self.as_payload() - payload.pop("id", None) # type: ignore + payload.pop("source_id", None) # type: ignore return { **payload, "tags": self.tags, diff --git a/src/memory/common/db/models/source_items.py b/src/memory/common/db/models/source_items.py index 509e702..98ee028 100644 --- a/src/memory/common/db/models/source_items.py +++ b/src/memory/common/db/models/source_items.py @@ -91,9 +91,9 @@ class MailMessage(SourceItem): def as_payload(self) -> MailMessagePayload: base_payload = super().as_payload() | { - "tags": cast(list[str], self.tags) + "tags": (cast(list[str], self.tags) or []) + [cast(str, self.sender)] - + cast(list[str], self.recipients) + + (cast(list[str], self.recipients) or []) } return MailMessagePayload( **cast(dict, base_payload), diff --git a/tests/memory/common/db/models/test_source_item.py b/tests/memory/common/db/models/test_source_item.py index e9eeb71..0b47372 100644 --- a/tests/memory/common/db/models/test_source_item.py +++ b/tests/memory/common/db/models/test_source_item.py @@ -4,8 +4,10 @@ from typing import cast import pytest from PIL import Image from memory.common import settings, chunker, extract -from memory.common.db.models.source_items import ( +from memory.common.db.models.source_item import ( Chunk, +) +from memory.common.db.models.source_items import ( MailMessage, ) from memory.common.db.models.source_item import ( diff --git a/tests/memory/common/db/models/test_source_items.py b/tests/memory/common/db/models/test_source_items.py index edc4fa7..a5ef267 100644 --- a/tests/memory/common/db/models/test_source_items.py +++ b/tests/memory/common/db/models/test_source_items.py @@ -203,6 +203,8 @@ Test Body Content""" "sender": "sender@example.com", "recipients": ["recipient@example.com"], "tags": None, + "folder": None, + "message_id": "", } diff --git a/tests/memory/workers/tasks/test_ebook_tasks.py b/tests/memory/workers/tasks/test_ebook_tasks.py index b214a32..390114e 100644 --- a/tests/memory/workers/tasks/test_ebook_tasks.py +++ b/tests/memory/workers/tasks/test_ebook_tasks.py @@ -3,6 +3,7 @@ from pathlib import Path from unittest.mock import patch, Mock from memory.common.db.models import Book, BookSection +from memory.common import settings from memory.parsers.ebook import Ebook, Section from memory.workers.tasks import ebook @@ -46,7 +47,7 @@ def mock_ebook(): end_page=20, ), ], - file_path=Path("/test/book.epub"), + file_path=settings.FILE_STORAGE_DIR / "test/book.epub", n_pages=20, ) @@ -70,7 +71,7 @@ def test_create_book_from_ebook(mock_ebook): assert book.author == "Test Author" # type: ignore assert book.publisher == "Test Publisher" # type: ignore assert book.language == "en" # type: ignore - assert book.file_path == "/test/book.epub" # type: ignore + assert book.file_path == "test/book.epub" # type: ignore assert book.total_pages == 20 # type: ignore assert book.book_metadata == { # type: ignore "language": "en", diff --git a/tests/memory/workers/test_email.py b/tests/memory/workers/test_email.py index 9935efd..8064dd7 100644 --- a/tests/memory/workers/test_email.py +++ b/tests/memory/workers/test_email.py @@ -257,6 +257,8 @@ def test_create_mail_message(db_session): "recipients": ["recipient@example.com"], "date": "2023-01-01T12:00:00+00:00", "mime_type": "message/rfc822", + "folder": "INBOX", + "message_id": "321", "size": 412, "tags": ["test"], "filename": None,