tests: fix the two suites failing on master

test_handle_reorganize_marks_job_failed_on_exception patched
wrolpi.files.worker.shutil.move, but #719 moved handle_reorganize and
its shutil.move call into wrolpi.files.reorganize_job.

test_file_worker_refresh_inserts_new_files loaded FileGroups into the
shared pytest session between refreshes.  The refresh upserts by raw
SQL, so the modeler then read the stale identity-map object and wrote
its old file list back over the upsert.  Production opens a fresh
session per block; expire the test session before the second refresh.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Roland 2026-10-03 10:50:18 -06:00
parent 8610f9c97e
commit bbc93bc51e
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
2 changed files with 6 additions and 1 deletions

View file

@ -238,7 +238,7 @@ async def test_handle_reorganize_marks_job_failed_on_exception(
)
file_worker._set_job_status(job_id, 'pending')
with mock.patch('wrolpi.files.worker.shutil.move', side_effect=OSError('disk full')):
with mock.patch('wrolpi.files.reorganize_job.shutil.move', side_effect=OSError('disk full')):
await file_worker.handle_reorganize(task)
assert file_worker.get_job_status(job_id) == 'failed'

View file

@ -835,6 +835,11 @@ async def test_file_worker_refresh_inserts_new_files(async_client, test_session,
# Now add a real video file that shares a stem with file1
# (must be a real video file so get_mimetype returns video/mp4)
video_file_factory(test_directory / 'docs/file1.mp4')
# Under pytest every get_db_session() is this one shared session. The FileGroups queried
# above would otherwise sit stale in its identity map while the refresh upserts by raw
# SQL, and the modeler would then write that stale file list back over the upsert.
# Production opens a fresh session per block, so only the test needs this.
test_session.expire_all()
# Refresh again - should detect the modified FileGroup
task = FileTask(FileTaskType.refresh, [test_directory], count=4)