fix(tests): resolve lazy loading errors in test_engine.py

Add await db.refresh() calls with relationship attributes before accessing
test_job.executions and execution.backups in async test context.

Fixes lazy loading errors in:
- test_execute_full_backup
- test_execute_incremental_without_full
This commit is contained in:
2026-05-11 21:40:52 +02:00
parent ed64b5ff62
commit 7676438466
+10
View File
@@ -4,6 +4,7 @@ import tempfile
import os import os
from pathlib import Path from pathlib import Path
from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import selectinload
from app.models import Source, Job, JobExecution from app.models import Source, Job, JobExecution
from backup.engine import BackupEngine from backup.engine import BackupEngine
@@ -49,8 +50,14 @@ async def test_execute_full_backup(db: AsyncSession, test_job):
assert execution.bytes_backed_up > 0 assert execution.bytes_backed_up > 0
assert execution.triggered_by == "manual" assert execution.triggered_by == "manual"
# Refresh test_job to load executions relationship
await db.refresh(test_job, ["executions"])
# Verify backup was created # Verify backup was created
assert len(test_job.executions) == 1 assert len(test_job.executions) == 1
# Refresh execution to load backups relationship
await db.refresh(test_job.executions[0], ["backups"])
backup = test_job.executions[0].backups[0] backup = test_job.executions[0].backups[0]
assert backup.type == "full" assert backup.type == "full"
assert backup.checksum is not None assert backup.checksum is not None
@@ -67,6 +74,9 @@ async def test_execute_incremental_without_full(db: AsyncSession, test_job):
# Should fall back to full backup # Should fall back to full backup
assert execution.status == "success" assert execution.status == "success"
# Refresh execution to load backups relationship
await db.refresh(execution, ["backups"])
backup = execution.backups[0] backup = execution.backups[0]
assert backup.type == "full" assert backup.type == "full"
assert backup.parent_backup_id is None assert backup.parent_backup_id is None