dp-zp-agent/test/conftest.py
jp170na 4ef7686a82 nová štruktúra
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 02:25:36 +01:00

68 lines
1.7 KiB
Python

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))
# Tests are grouped in folders by area (api/, planning/, …); some reuse helpers of another test module
# by its name ("from test_index_sync import …"), so every test folder is importable.
for _folder in sorted(p for p in Path(__file__).resolve().parent.iterdir() if p.is_dir() and p.name != "__pycache__"):
if str(_folder) not in sys.path:
sys.path.append(str(_folder))
@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.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)