|
|
import pytest |
|
|
from fastapi.testclient import TestClient |
|
|
from syntetic_issue_report_data_generation.api.main import app |
|
|
|
|
|
@pytest.fixture |
|
|
def client(): |
|
|
with TestClient(app) as c: |
|
|
yield c |
|
|
|
|
|
def test_root(client): |
|
|
resp = client.get("/") |
|
|
assert resp.status_code == 200 |
|
|
data = resp.json() |
|
|
assert "service" in data |
|
|
assert "endpoints" in data |
|
|
|
|
|
def test_health(client): |
|
|
resp = client.get("/health") |
|
|
assert resp.status_code == 200 |
|
|
data = resp.json() |
|
|
assert "status" in data |
|
|
assert "model_loaded" in data |
|
|
|
|
|
def test_predict_single(client): |
|
|
resp = client.post("/predict", json={"texts": "Bug in login", "return_labels": True}) |
|
|
assert resp.status_code == 200 |
|
|
data = resp.json() |
|
|
assert "predictions" in data |
|
|
assert isinstance(data["predictions"], list) |
|
|
assert data["num_predictions"] == 1 |
|
|
|
|
|
def test_predict_batch(client): |
|
|
resp = client.post("/predict", json={"texts": ["Bug in login", "Add feature"], "return_labels": True}) |
|
|
assert resp.status_code == 200 |
|
|
data = resp.json() |
|
|
assert "predictions" in data |
|
|
assert isinstance(data["predictions"], list) |
|
|
assert data["num_predictions"] == 2 |
|
|
|
|
|
def test_model_info(client): |
|
|
resp = client.get("/models/current") |
|
|
assert resp.status_code == 200 |
|
|
data = resp.json() |
|
|
assert "status" in data |
|
|
assert "model_uri" in data |