bc-test / tests /test_api.py
lamossta's picture
tests
594db4d
"""Tests for the FastAPI endpoints."""
# ── GET /health ──────────────────────────────────────────────────────────────
def test_health_returns_ok(client):
resp = client.get("/health")
assert resp.status_code == 200
data = resp.json()
assert data["status"] == "ok"
assert isinstance(data["available_models"], list)
assert len(data["available_models"]) >= 1
def test_health_lists_distilbert(client):
resp = client.get("/health")
models = resp.json()["available_models"]
assert "distilbert" in models
# ── POST /fix-newlines ───────────────────────────────────────────────────────
def test_fix_newlines_returns_fixed_text(client):
resp = client.post("/fix-newlines", json={"text": "Hello world. This is a test."})
assert resp.status_code == 200
data = resp.json()
assert "fixed_text" in data
assert "model_used" in data
assert isinstance(data["fixed_text"], str)
def test_fix_newlines_returns_model_name(client):
resp = client.post("/fix-newlines", json={"text": "Hello world."})
assert resp.json()["model_used"] == "bert"
def test_fix_newlines_empty_text(client):
resp = client.post("/fix-newlines", json={"text": ""})
assert resp.status_code == 200
assert resp.json()["fixed_text"] == ""
def test_fix_newlines_missing_text_returns_422(client):
resp = client.post("/fix-newlines", json={})
assert resp.status_code == 422
def test_fix_newlines_multiline_input(client):
text = "First sentence.\nSecond sentence.\n\nNew paragraph."
resp = client.post("/fix-newlines", json={"text": text})
assert resp.status_code == 200
assert len(resp.json()["fixed_text"]) > 0
def test_fix_newlines_preserves_content(client):
text = "The quick brown fox jumps over the lazy dog. It was a sunny day."
resp = client.post("/fix-newlines", json={"text": text})
fixed = resp.json()["fixed_text"]
# all original words should be present
for word in ["quick", "brown", "fox", "sunny", "day"]:
assert word in fixed
# ── POST /fix-newlines-all-models ────────────────────────────────────────────
def test_fix_newlines_all_models(client):
resp = client.post("/fix-newlines-all-models", json={"text": "Hello world. This is a test."})
assert resp.status_code == 200
data = resp.json()
assert "results" in data
assert len(data["results"]) >= 1
def test_fix_newlines_all_models_has_model_names(client):
resp = client.post("/fix-newlines-all-models", json={"text": "Hello world."})
names = [r["model_name"] for r in resp.json()["results"]]
assert "distilbert" in names
def test_fix_newlines_all_models_has_fixed_text(client):
resp = client.post("/fix-newlines-all-models", json={"text": "Hello world. Testing."})
for result in resp.json()["results"]:
assert "fixed_text" in result
assert isinstance(result["fixed_text"], str)
assert len(result["fixed_text"]) > 0
def test_fix_newlines_all_models_empty_text(client):
resp = client.post("/fix-newlines-all-models", json={"text": ""})
assert resp.status_code == 200
for result in resp.json()["results"]:
assert result["fixed_text"] == ""
def test_fix_newlines_all_models_missing_text_returns_422(client):
resp = client.post("/fix-newlines-all-models", json={})
assert resp.status_code == 422