zotero-kb/tests/test_workspace.py
Saberlve cf7e2feb19 feat: Implement project management features including rename and delete functionality
- Added project renaming capability in the workspace with appropriate API endpoints.
- Implemented project deletion functionality, ensuring project directories are removed.
- Updated UI to support project renaming and deletion, including inline editing and confirmation dialogs.
- Enhanced batch generation feature for project items with selection and progress tracking.
- Added tests for project renaming and deletion to ensure functionality and integrity.
2026-04-21 16:55:42 +08:00

74 lines
2.7 KiB
Python

from pathlib import Path
from zotero_kb.config import AppConfig
from zotero_kb.workspace import Workspace
def test_workspace_initialization_creates_required_directories(tmp_path: Path) -> None:
config = AppConfig(workspace_dir=tmp_path / "workspace", zotero_data_dir=tmp_path / "zotero")
workspace = Workspace(config)
workspace.ensure_layout()
assert (config.workspace_dir / "library" / "collections").is_dir()
assert (config.workspace_dir / "library" / "index").is_dir()
assert (config.workspace_dir / "library" / "cache" / "source-bundles").is_dir()
assert (config.workspace_dir / "projects").is_dir()
def test_create_project_writes_project_files(tmp_path: Path) -> None:
config = AppConfig(workspace_dir=tmp_path / "workspace", zotero_data_dir=tmp_path / "zotero")
workspace = Workspace(config)
workspace.ensure_layout()
project = workspace.create_project(
project_id="thesis-ch2",
name="Thesis Chapter 2",
llm_provider="openai",
llm_model="gpt-5-mini",
)
assert project.project_id == "thesis-ch2"
assert (config.workspace_dir / "projects" / "thesis-ch2" / "project.json").is_file()
assert (config.workspace_dir / "projects" / "thesis-ch2" / "selected-items.json").is_file()
assert (config.workspace_dir / "projects" / "thesis-ch2" / "project-index.json").is_file()
def test_rename_project_updates_project_name(tmp_path: Path) -> None:
config = AppConfig(workspace_dir=tmp_path / "workspace", zotero_data_dir=tmp_path / "zotero")
workspace = Workspace(config)
workspace.ensure_layout()
workspace.create_project(
project_id="thesis-ch2",
name="Old Name",
llm_provider="openai",
llm_model="gpt-5-mini",
)
project = workspace.rename_project("thesis-ch2", "New Name")
assert project.project_id == "thesis-ch2"
assert project.name == "New Name"
assert '"name": "New Name"' in (
config.workspace_dir / "projects" / "thesis-ch2" / "project.json"
).read_text(encoding="utf-8")
def test_delete_project_removes_project_directory_only(tmp_path: Path) -> None:
config = AppConfig(workspace_dir=tmp_path / "workspace", zotero_data_dir=tmp_path / "zotero")
workspace = Workspace(config)
workspace.ensure_layout()
workspace.create_project(
project_id="thesis-ch2",
name="Thesis Chapter 2",
llm_provider="openai",
llm_model="gpt-5-mini",
)
preserved_index = config.workspace_dir / "library" / "index" / "items.json"
preserved_index.write_text('{"PAPER0001": {"title": "Keep me"}}', encoding="utf-8")
workspace.delete_project("thesis-ch2")
assert not (config.workspace_dir / "projects" / "thesis-ch2").exists()
assert preserved_index.is_file()