Gerador de vídeos narrativos (Godot + FFmpeg), painel Next.js, serviço de voz, Clipador de lives e Publicador para YouTube, TikTok e Instagram. Inclui a leitura das visualizações dos posts para o Dashboard e o botão "Publicar no <rede>" nos cartões das publicações. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
85 lines
2.9 KiB
Python
85 lines
2.9 KiB
Python
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import json
|
|
from contextlib import asynccontextmanager
|
|
from dataclasses import replace
|
|
from pathlib import Path
|
|
|
|
import httpx
|
|
import pytest
|
|
|
|
from app.config import Settings
|
|
from app.engine import FakeEngine
|
|
from app.main import create_app
|
|
from app.stt import FakeSttEngine
|
|
|
|
KEY = "k" * 40
|
|
HEADERS = {"X-Service-Key": KEY}
|
|
|
|
|
|
@pytest.fixture
|
|
def anyio_backend():
|
|
return "asyncio"
|
|
|
|
|
|
@pytest.fixture
|
|
def settings(tmp_path: Path) -> Settings:
|
|
models = tmp_path / "models"
|
|
(models / "piper").mkdir(parents=True)
|
|
files = {"piper/fake.onnx": b"fake-model", "piper/fake.onnx.json": b"{}"}
|
|
lock = []
|
|
for rel, content in files.items():
|
|
(models / rel).write_bytes(content)
|
|
lock.append({"path": rel, "url": "https://example.invalid/" + rel, "sha256": hashlib.sha256(content).hexdigest()})
|
|
(tmp_path / "lock.json").write_text(json.dumps({"files": lock}))
|
|
catalog = {
|
|
"voices": [
|
|
{
|
|
"id": "pt-br-test", "name": "Teste", "language": "pt-BR", "engine": "fake",
|
|
"model": "piper/fake.onnx", "config": "piper/fake.onnx.json", "sampleRate": 22050,
|
|
"default": True, "source": "teste", "license": "teste",
|
|
}
|
|
]
|
|
}
|
|
(tmp_path / "catalog.json").write_text(json.dumps(catalog))
|
|
return Settings(
|
|
service_key=KEY, models_dir=models, data_dir=tmp_path / "data",
|
|
catalog_path=tmp_path / "catalog.json", lock_path=tmp_path / "lock.json",
|
|
max_concurrency=1, max_queue_per_key=4, queue_timeout_s=5, synth_timeout_s=5,
|
|
max_text_chars=200, max_audio_s=10,
|
|
# Limites do contrato herdado do dropsz_voice (os testes de transcrição contam com 60 s / 8 MiB).
|
|
stt_max_audio_s=60, stt_max_bytes=8 * 1024 * 1024, stt_queue_timeout_s=90, stt_timeout_s=45,
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def engine() -> FakeEngine:
|
|
return FakeEngine()
|
|
|
|
|
|
@pytest.fixture
|
|
def stt_engine() -> FakeSttEngine:
|
|
return FakeSttEngine()
|
|
|
|
|
|
@pytest.fixture
|
|
def make_client(settings: Settings, engine: FakeEngine, stt_engine: FakeSttEngine):
|
|
@asynccontextmanager
|
|
async def _make(stt: FakeSttEngine | None | bool = True, **overrides):
|
|
# stt=True usa o motor falso do fixture; None desliga a transcrição; outro objeto substitui.
|
|
chosen = stt_engine if stt is True else stt
|
|
app = create_app(replace(settings, **overrides), engine=engine, stt_engine=chosen)
|
|
async with app.router.lifespan_context(app):
|
|
transport = httpx.ASGITransport(app=app)
|
|
async with httpx.AsyncClient(transport=transport, base_url="http://voice") as client:
|
|
yield client
|
|
|
|
return _make
|
|
|
|
|
|
def body(request_id: str = "req-00000001", text: str = "Olá, valeu pela doação!", **extra) -> dict:
|
|
payload = {"requestId": request_id, "text": text, "voiceId": "pt-br-test"}
|
|
payload.update(extra)
|
|
return payload
|