47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
import os
|
|
import sqlite3
|
|
import pytest
|
|
from src.lyricflow_core.storage.db_manager import DatabaseManager
|
|
|
|
@pytest.fixture
|
|
def db_manager(tmp_path):
|
|
# Use an in-memory database path or a temp file
|
|
db_file = tmp_path / "test.db"
|
|
manager = DatabaseManager(str(db_file))
|
|
yield manager
|
|
# Teardown
|
|
manager.clear_all()
|
|
|
|
def test_save_and_get_snapshots(db_manager):
|
|
file_path = "/test/path.lmd"
|
|
|
|
# Save a snapshot
|
|
db_manager.save_snapshot(file_path, "Version 1 content")
|
|
|
|
# Save another snapshot
|
|
db_manager.save_snapshot(file_path, "Version 2 content")
|
|
|
|
# Identical snapshot should not save a duplicate
|
|
db_manager.save_snapshot(file_path, "Version 2 content")
|
|
|
|
snapshots = db_manager.get_snapshots(file_path)
|
|
|
|
assert len(snapshots) == 2
|
|
assert snapshots[0].content == "Version 2 content"
|
|
assert snapshots[1].content == "Version 1 content"
|
|
|
|
def test_save_and_get_scratchpad(db_manager):
|
|
project_id = "test_project"
|
|
|
|
# Initially empty
|
|
content = db_manager.get_scratchpad(project_id)
|
|
assert content == ""
|
|
|
|
# Save content
|
|
db_manager.save_scratchpad(project_id, "Idea 1")
|
|
assert db_manager.get_scratchpad(project_id) == "Idea 1"
|
|
|
|
# Update content (replace)
|
|
db_manager.save_scratchpad(project_id, "Idea 2")
|
|
assert db_manager.get_scratchpad(project_id) == "Idea 2"
|