Implement initial scan tracking for one-time setup
- Add SystemSettings model to track setup completion status - Create SystemSettingsService for managing setup flags - Modify fastapi_app startup to check and set initial_scan_completed flag - Anime folder scanning now only runs on first startup - Update DATABASE.md with new system_settings table documentation - Add unit test for SystemSettingsService functionality This ensures expensive one-time operations like scanning the entire anime directory only occur during initial setup, not on every application restart.
This commit is contained in:
58
tests/unit/test_system_settings_service.py
Normal file
58
tests/unit/test_system_settings_service.py
Normal file
@@ -0,0 +1,58 @@
|
||||
"""Test the system settings service integration."""
|
||||
import pytest
|
||||
|
||||
from src.server.database.connection import get_db_session, init_db
|
||||
from src.server.database.system_settings_service import SystemSettingsService
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_system_settings_integration():
|
||||
"""Test SystemSettings service with actual database operations."""
|
||||
# Initialize database
|
||||
await init_db()
|
||||
|
||||
# Test get_or_create (should create on first call)
|
||||
async with get_db_session() as db:
|
||||
settings = await SystemSettingsService.get_or_create(db)
|
||||
assert settings is not None
|
||||
assert settings.id is not None
|
||||
assert settings.initial_scan_completed is False
|
||||
assert settings.initial_nfo_scan_completed is False
|
||||
assert settings.initial_media_scan_completed is False
|
||||
|
||||
# Test checking individual flags
|
||||
async with get_db_session() as db:
|
||||
is_scan_done = await SystemSettingsService.is_initial_scan_completed(db)
|
||||
assert is_scan_done is False
|
||||
|
||||
is_nfo_done = await SystemSettingsService.is_initial_nfo_scan_completed(db)
|
||||
assert is_nfo_done is False
|
||||
|
||||
is_media_done = await SystemSettingsService.is_initial_media_scan_completed(db)
|
||||
assert is_media_done is False
|
||||
|
||||
# Test marking scans as completed
|
||||
async with get_db_session() as db:
|
||||
await SystemSettingsService.mark_initial_scan_completed(db)
|
||||
|
||||
async with get_db_session() as db:
|
||||
is_scan_done = await SystemSettingsService.is_initial_scan_completed(db)
|
||||
assert is_scan_done is True
|
||||
|
||||
# Others should still be False
|
||||
is_nfo_done = await SystemSettingsService.is_initial_nfo_scan_completed(db)
|
||||
assert is_nfo_done is False
|
||||
|
||||
# Test reset
|
||||
async with get_db_session() as db:
|
||||
await SystemSettingsService.reset_all_scans(db)
|
||||
|
||||
async with get_db_session() as db:
|
||||
settings = await SystemSettingsService.get_or_create(db)
|
||||
assert settings.initial_scan_completed is False
|
||||
assert settings.initial_nfo_scan_completed is False
|
||||
assert settings.initial_media_scan_completed is False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pytest.main([__file__, "-v"])
|
||||
Reference in New Issue
Block a user