Files
flow2api/tests/test_file_cache.py
genz27 db559a82c5 fix: improve gemini compatibility and cache flow
1. add Gemini /models and /v1beta/models discovery endpoints for newapi compatibility

2. persist tmp cache in Docker and lock cache_timeout=0 behavior with regression tests

3. refine image generation status flow to show captcha verification after uploads
2026-03-16 21:45:34 +08:00

32 lines
858 B
Python

import asyncio
import os
import time
from src.services.file_cache import FileCache
def test_cleanup_keeps_files_when_timeout_is_zero(tmp_path):
cache = FileCache(cache_dir=str(tmp_path), default_timeout=0)
cached_file = tmp_path / "expired.jpg"
cached_file.write_bytes(b"cached")
expired_at = time.time() - 3600
os.utime(cached_file, (expired_at, expired_at))
asyncio.run(cache._cleanup_expired_files())
assert cached_file.exists()
def test_cleanup_removes_files_when_timeout_is_positive(tmp_path):
cache = FileCache(cache_dir=str(tmp_path), default_timeout=1)
cached_file = tmp_path / "expired.jpg"
cached_file.write_bytes(b"cached")
expired_at = time.time() - 3600
os.utime(cached_file, (expired_at, expired_at))
asyncio.run(cache._cleanup_expired_files())
assert not cached_file.exists()