intra_max_bot/tests/conftest.py
2026-03-19 16:47:49 +03:00

41 lines
1.1 KiB
Python

from __future__ import annotations
import uuid
from pathlib import Path
import pytest
from app.config import Settings
from app.db import Database, ensure_db
@pytest.fixture()
def test_settings() -> Settings:
data_dir = Path("data/testdb")
data_dir.mkdir(parents=True, exist_ok=True)
db_path = data_dir / f"test_{uuid.uuid4().hex}.db"
settings = Settings(
db_path=str(db_path),
session_secret="test-secret",
web_admin_login="admin",
web_admin_password="admin",
max_bot_token="",
channel_local_enabled=True,
channel_external_enabled=True,
external_api_create_url_with_key="https://example.com/create?key=abc",
context_backend="memory",
max_use_webhook=False,
operator_chat_ids=[],
request_categories=["A", "B", "C"],
)
ensure_db(settings)
yield settings
try:
db_path.unlink(missing_ok=True)
except Exception:
pass
@pytest.fixture()
def database(test_settings: Settings) -> Database:
return Database(test_settings.db_path)