7e17b6e5b8
Docker Image CI / build (pull_request) Waiting to run
Задание 15: MEDIA_CACHE_DIR (резолвится один раз при импорте) + media_cache_path(
channel, post_id, fid=None) -> <root>/<channel>/<post_id>[/<fid>] как единый
источник истины формата пути. Заменены все ручные сборки os.path.abspath('./data/
cache')+join (7 мест); строки путей дословно идентичны (drop-in). remove_old_
cached_files_sync/download_new_files сохраняют параметр cache_dir (тестируемость).
Задание 16: in-memory _mime_types (bound _MIME_CACHE_MAX=50000, clear() при
переполнении) перед SQLite в prepare_file_response. Порядок: dict -> SQLite ->
python-magic; SQLite-хит и magic-детект наполняют dict. MIME по file_unique_id
иммутабелен -> повторный /media-хит не открывает SQLite-соединение (ни на чтение
MIME, ни на запись access-time — она уже в аккумуляторе). Кэшируются только
реальные типы.
closes #26
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
"""Shared test bootstrap (issue #17).
|
|
|
|
Ensure the repo root is importable and install the config mock BEFORE any test
|
|
module imports application code. Pytest imports conftest.py before collecting
|
|
test modules, so doing this here (instead of a per-module preamble) makes the
|
|
suite order-independent regardless of collection order or invocation directory.
|
|
"""
|
|
import os
|
|
import sys
|
|
import time
|
|
|
|
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
|
if ROOT not in sys.path:
|
|
sys.path.insert(0, ROOT)
|
|
|
|
import tests.mock_config as _mock_config
|
|
|
|
sys.modules['config'] = _mock_config
|
|
|
|
# Pin the runner timezone to UTC (stage-0 golden determinism, issue #27).
|
|
# Naive kurigram dates are interpreted by datetime.timestamp() in the LOCAL tz, so
|
|
# without this pin RSS <pubDate> values drift between machines (this sandbox is MSK).
|
|
os.environ['TZ'] = 'UTC'
|
|
time.tzset()
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _reset_media_mime_cache():
|
|
"""Clear the process-lifetime MIME dict before each test (issue #26).
|
|
|
|
``api_server._mime_types`` persists for the whole process, so an entry populated by one
|
|
test would otherwise leak into another and mask a get/magic call the next test asserts on.
|
|
"""
|
|
try:
|
|
import api_server
|
|
api_server._mime_types.clear()
|
|
except Exception:
|
|
pass
|
|
yield
|