Files
romm/backend/tests/tasks/test_cleanup_zip_cache.py
nendo 6ffb8ac891 Address Copilot review feedback
- Use zipfile.ZipFile after reload instead of stale direct import
- Use ZipFile.write() for streaming (reload fixes CPython 3.13 bug)
- Wrap cache build in try/except, fall back to mod_zip on failure
- Guard empty entries list in get_cache_key
- Hash bulk namespace to avoid ENAMETOOLONG with 100 ROM IDs
- Use MagicMock for sync unschedule method in tests
- Mock _get_available_space in eviction tests to force eviction path
- Use sparse file (truncate) for large file TTL test
- Add tests for get_bulk_namespace and empty entries
2026-03-24 08:11:55 +09:00

31 lines
1011 B
Python

from unittest.mock import MagicMock
from tasks.scheduled.cleanup_zip_cache import CleanupZipCacheTask
class TestCleanupZipCacheTask:
def test_configuration(self):
task = CleanupZipCacheTask()
assert task.enabled is True
assert task.cron_string == "0 4 * * *"
assert "cleanup_zip_cache" in task.func
async def test_run_calls_cleanup(self, mocker):
task = CleanupZipCacheTask()
mock_cleanup = mocker.patch(
"tasks.scheduled.cleanup_zip_cache.cleanup_stale_zips",
return_value=3,
)
await task.run()
mock_cleanup.assert_called_once_with()
async def test_run_disabled_unschedules(self, mocker):
task = CleanupZipCacheTask()
task.enabled = False
mocker.patch.object(task, "unschedule", MagicMock())
mock_cleanup = mocker.patch(
"tasks.scheduled.cleanup_zip_cache.cleanup_stale_zips",
)
await task.run()
mock_cleanup.assert_not_called()