Files
ohm_streaming/tests/conftest.py
T
Roman 9148b5fb6a Mise à jour automatique (Gitea + Watchtower) et conteneurisation Docker
- Détection de version via l'API Gitea, application via Watchtower
- Router système, UI admin (intégrations), bandeau de mise à jour
- Dockerfile multi-étapes, docker-compose, scripts/release.sh
- Version centralisée dans app/version.py (pyproject ou OHM_VERSION au build)
2026-09-22 11:58:03 +00:00

63 lines
1.6 KiB
Python

import os
import tempfile
from collections.abc import AsyncIterator
from pathlib import Path
import pytest
# Environnement de test AVANT tout import de l'app
_tmp = Path(tempfile.mkdtemp(prefix="ohm-test-"))
os.environ["OHM_DATA_DIR"] = str(_tmp)
os.environ["OHM_DOWNLOAD_DIR"] = str(_tmp / "downloads")
os.environ["OHM_DATABASE_PATH"] = str(_tmp / "test.db")
os.environ["OHM_SECRET_KEY"] = "test-secret-key-with-32-bytes-minimum!"
from app.config import get_settings
from app.db import db
@pytest.fixture(scope="session")
def anyio_backend() -> str:
return "asyncio"
@pytest.fixture(autouse=True)
async def database() -> AsyncIterator[None]:
"""DB fraîche par test."""
get_settings.cache_clear()
await db.connect()
for table in (
"users",
"refresh_tokens",
"downloads",
"metadata_cache",
"settings",
"favorites",
"watch_progress",
):
await db.execute(f"DELETE FROM {table}")
yield
await db.close()
# ---------------------------------------------------------------- client HTTP partagé
import pytest
from httpx import ASGITransport, AsyncClient
from app.main import app
@pytest.fixture
async def client() -> AsyncClient:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as c:
yield c
@pytest.fixture
async def admin_cookies(client: AsyncClient):
"""Premier compte créé → administrateur, cookies de session."""
r = await client.post("/auth/register", data={"username": "admin", "password": "secret123"})
assert r.status_code == 303
return r.cookies