Files
MincedPad/backend/tests/conftest.py
T
肉末 175a4ad0d1 feat: per-IP rate limit and write bans
Apply sliding-window 2/s limits and BannedIP checks on write routes.
Also force SVG attachment disposition and claim burn-after-read in DB
before streaming, deleting the file via BackgroundTask after the response.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-14 12:52:45 +08:00

36 lines
1.1 KiB
Python

from pathlib import Path
import pytest
from fastapi.testclient import TestClient
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
@pytest.fixture()
def client(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
monkeypatch.setenv("DATA_DIR", str(tmp_path))
from app.config import Settings
import app.config as config_module
import app.db as db_module
import app.main as main_module
from app.services import rate_limit as rate_limit_module
settings = Settings(_env_file=None, DATA_DIR=tmp_path)
config_module.settings = settings
# Multi-create tests are not about rate limits; the dedicated test sets 2/s.
monkeypatch.setattr(config_module.settings, "rate_limit_per_second", 10_000)
rate_limit_module.reset()
engine = create_engine(
settings.db_url,
connect_args={"check_same_thread": False},
)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
db_module.engine = engine
db_module.SessionLocal = SessionLocal
main_module.engine = engine
with TestClient(main_module.app) as test_client:
yield test_client