zotero-kb/tests/test_zotero_reader.py
Saberlve aaafa78883 feat: Add multilingual support for project cards and attachments
- Introduced `card_language` attribute in ProjectRecord and Workspace classes to handle multiple languages for project cards.
- Updated project creation and renaming methods to accept and store the card language.
- Enhanced ZoteroReader to read and return attachment metadata, including language-specific summaries and claims.
- Modified LLM client to generate card content based on the specified language, supporting both English and Chinese.
- Updated tests to cover new functionality, ensuring correct handling of multilingual card generation and retrieval.
- Adjusted UI tests to verify the presence of language selection options and proper rendering of multilingual content.
2026-04-22 10:21:03 +08:00

83 lines
2.8 KiB
Python

from pathlib import Path
from tests.fixtures.build_zotero_fixture import build_fixture_zotero_dir
from zotero_kb.bridge import read_selected_keys
from zotero_kb.zotero_reader import ZoteroReader
def test_read_selected_items_from_fixture(tmp_path: Path) -> None:
fixture_dir = tmp_path / "zotero"
fixture_dir.mkdir()
build_fixture_zotero_dir(fixture_dir)
reader = ZoteroReader(fixture_dir)
items = reader.read_items(["PAPER0001"])
assert len(items) == 1
item = items[0]
assert item.item_key == "PAPER0001"
assert item.title == "Card Pipelines for Research Writing"
assert item.tags == ["llm", "writing"]
assert item.collection_paths == [["Theory", "Drafting"]]
assert item.notes == ["Merged notes matter."]
assert item.attachment_texts[0].startswith("This paper studies")
assert item.attachments == [
{
"path": str(fixture_dir / "storage" / "ATTACH01" / "paper.txt"),
"filename": "paper.txt",
"content_type": "text/plain",
"is_pdf": False,
}
]
def test_read_selected_keys_from_bridge_snapshot(tmp_path: Path) -> None:
bridge_file = tmp_path / "selected-items.json"
bridge_file.write_text('{"selected_keys": ["PAPER0001", "PAPER0002"]}', encoding="utf-8")
assert read_selected_keys(bridge_file) == ["PAPER0001", "PAPER0002"]
def test_search_items_returns_matching_library_records(tmp_path: Path) -> None:
fixture_dir = tmp_path / "zotero"
fixture_dir.mkdir()
build_fixture_zotero_dir(fixture_dir)
reader = ZoteroReader(fixture_dir)
results = reader.search_items("research", limit=5)
assert len(results) == 1
assert results[0]["item_key"] == "PAPER0001"
assert results[0]["title"] == "Card Pipelines for Research Writing"
def test_build_collection_tree_returns_descendant_counts(tmp_path: Path) -> None:
fixture_dir = tmp_path / "zotero"
fixture_dir.mkdir()
build_fixture_zotero_dir(fixture_dir)
reader = ZoteroReader(fixture_dir)
tree = reader.get_collection_tree()
assert len(tree) == 1
root = tree[0]
assert root["collection_key"] == "COLL0001"
assert root["name"] == "Theory"
assert root["direct_item_count"] == 0
assert root["descendant_item_count"] == 1
assert root["children"][0]["collection_key"] == "COLL0002"
assert root["children"][0]["direct_item_count"] == 1
def test_get_collection_items_includes_descendants(tmp_path: Path) -> None:
fixture_dir = tmp_path / "zotero"
fixture_dir.mkdir()
build_fixture_zotero_dir(fixture_dir)
reader = ZoteroReader(fixture_dir)
items = reader.get_collection_items("COLL0001", include_descendants=True)
assert [item["item_key"] for item in items] == ["PAPER0001"]
assert items[0]["collection_paths"] == [["Theory", "Drafting"]]
assert items[0]["title"] == "Card Pipelines for Research Writing"