from __future__ import annotations import sys from pathlib import Path import pytest PROJECT_ROOT = Path(__file__).resolve().parents[1] if str(PROJECT_ROOT) not in sys.path: sys.path.insert(0, str(PROJECT_ROOT)) @pytest.fixture(autouse=True) def security_environment( monkeypatch: pytest.MonkeyPatch, ) -> None: """Každý test dostane platnú bezpečnostnú konfiguráciu.""" monkeypatch.setenv( "WEBHOOK_SECRET", "w" * 64, ) monkeypatch.setenv( "SYNC_API_KEY", "s" * 64, ) monkeypatch.setenv( "SEARCH_API_KEY", "a" * 64, ) monkeypatch.setenv( "EXPECTED_GITEA_REPOSITORY", "KEMT/zpwiki", ) monkeypatch.setenv( "WEBHOOK_PULL_GIT", "false", ) monkeypatch.setenv('EXPECTED_GITEA_BRANCH', 'master') @pytest.fixture(autouse=True) def isolated_sync_queue(monkeypatch, tmp_path): """API tests never start a real index rebuild or share production job state.""" import app.main as main from tools.sync_jobs import SyncJobs class PausedJobs(SyncJobs): def __init__(self, data_dir, **kwargs): super().__init__(tmp_path / 'jobs', runner=lambda **kw: main.rebuild_index(pull_git=kw['pull_git'])) def start(self): pass monkeypatch.setattr(main, 'SyncJobs', PausedJobs)