neurotranslator-api / tests /test_api.py
Flaviohb7's picture
Deploy v1f8ac65300833db9a9f8bd55bc82ac8b269ff2e8 - 2026-05-20 17:10
026a938
Raw
History Blame Contribute Delete
1.08 kB
from __future__ import annotations
from fastapi.testclient import TestClient
try:
import src.api.main as main
except Exception:
import main as main # type: ignore
def test_health() -> None:
c = TestClient(main.app)
r = c.get("/health")
assert r.status_code == 200
assert r.json()["status"] == "ok"
def test_models_has_pairs() -> None:
c = TestClient(main.app)
r = c.get("/models")
assert r.status_code == 200
data = r.json()
assert "pairs" in data
assert any(p["source"] == "pt" and p["target"] == "en" for p in data["pairs"])
def test_translate_mock(monkeypatch) -> None:
def fake_translate_with_pivot(text: str, source: str, target: str):
return "hello", "mock-model", 0.9, 12
monkeypatch.setattr(main, "_translate_with_pivot", fake_translate_with_pivot)
c = TestClient(main.app)
r = c.post("/translate", json={"text": "olá", "source": "pt", "target": "en"})
assert r.status_code == 200
assert r.json()["translated_text"] == "hello"
assert r.json()["model_used"] == "mock-model"