mirror of
https://github.com/rommapp/romm.git
synced 2026-11-28 17:48:31 +01:00
- 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
31 lines
1011 B
Python
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()
|