import tempfile from pathlib import Path from media_library_viewer_api.services.settings_store import SettingsStore def test_backup_schema_created(): with tempfile.TemporaryDirectory() as tmpdir: db_path = Path(tmpdir) / "test_settings.sqlite" store = SettingsStore(db_path) store.init_schema() with store.connect() as conn: tables = conn.execute("SELECT name FROM sqlite_master WHERE type='table' AND name LIKE 'backup_%'").fetchall() table_names = [t[0] for t in tables] assert "backup_jobs" in table_names assert "backup_runs" in table_names assert "backup_alerts" in table_names def test_backup_report_model(): from media_library_viewer_api.models.backups import BackupReportRequest report = BackupReportRequest( name="test-backup", started_at="2026-05-11T02:00:00Z", status="success", ended_at="2026-05-11T02:15:00Z", duration_ms=900000, bytes_transferred=1024, ) assert report.name == "test-backup" assert report.status == "success" def test_create_job_and_run(): with tempfile.TemporaryDirectory() as tmpdir: db_path = Path(tmpdir) / "test_settings.sqlite" store = SettingsStore(db_path) store.init_schema() job = store.upsert_backup_job({ "name": "test-job", "source": "server-a:/data", "target": "server-b:/backups", "schedule_interval_seconds": 86400, }) assert job["name"] == "test-job" run = store.create_backup_run({ "job_id": job["id"], "started_at": 1715392800, "status": "success", "ended_at": 1715393700, "duration_ms": 900000, "bytes_transferred": 1024, }) assert run["job_id"] == job["id"] assert run["status"] == "success"