mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 03:39:27 +08:00
49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
from __future__ import annotations
|
|
|
|
import sqlite3
|
|
from pathlib import Path
|
|
|
|
from deeptutor.services.path_service import PathService
|
|
from deeptutor.services.session.sqlite_store import SQLiteSessionStore
|
|
|
|
|
|
def test_sqlite_store_defaults_to_data_user_chat_history_db(tmp_path: Path) -> None:
|
|
service = PathService.get_instance()
|
|
original_root = service._project_root
|
|
original_user_dir = service._user_data_dir
|
|
|
|
try:
|
|
service._project_root = tmp_path
|
|
service._user_data_dir = tmp_path / "data" / "user"
|
|
|
|
store = SQLiteSessionStore()
|
|
|
|
assert store.db_path == tmp_path / "data" / "user" / "chat_history.db"
|
|
assert store.db_path.exists()
|
|
finally:
|
|
service._project_root = original_root
|
|
service._user_data_dir = original_user_dir
|
|
|
|
|
|
def test_sqlite_store_migrates_legacy_chat_history_db(tmp_path: Path) -> None:
|
|
service = PathService.get_instance()
|
|
original_root = service._project_root
|
|
original_user_dir = service._user_data_dir
|
|
|
|
try:
|
|
service._project_root = tmp_path
|
|
service._user_data_dir = tmp_path / "data" / "user"
|
|
legacy_db = tmp_path / "data" / "chat_history.db"
|
|
legacy_db.parent.mkdir(parents=True, exist_ok=True)
|
|
with sqlite3.connect(legacy_db) as conn:
|
|
conn.execute("CREATE TABLE legacy (id INTEGER PRIMARY KEY)")
|
|
conn.commit()
|
|
|
|
store = SQLiteSessionStore()
|
|
|
|
assert store.db_path.exists()
|
|
assert not legacy_db.exists()
|
|
finally:
|
|
service._project_root = original_root
|
|
service._user_data_dir = original_user_dir
|