65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
"""스모크 테스트. `pip install fastapi httpx pytest` 후 실행."""
|
|
from __future__ import annotations
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
from app.main import app
|
|
|
|
API_KEY = "combooks-key-change-me"
|
|
|
|
|
|
def test_health():
|
|
with TestClient(app) as client:
|
|
resp = client.get("/v1/health")
|
|
assert resp.status_code == 200
|
|
body = resp.json()
|
|
assert body["status"] == "ok"
|
|
assert body["corpus_size"] >= 0
|
|
|
|
|
|
def test_detect_requires_api_key():
|
|
with TestClient(app) as client:
|
|
resp = client.post(
|
|
"/v1/plagiarism/detect",
|
|
json={"doc_id": "x", "text": "테스트 본문"},
|
|
)
|
|
assert resp.status_code == 401
|
|
|
|
|
|
def test_detect_returns_schema():
|
|
with TestClient(app) as client:
|
|
resp = client.post(
|
|
"/v1/plagiarism/detect",
|
|
json={
|
|
"doc_id": "t-1",
|
|
"text": "어린왕자는 작은 별에서 온 소년이다. 그는 여우를 만나 길들임을 배운다.",
|
|
},
|
|
headers={"X-API-Key": API_KEY},
|
|
)
|
|
assert resp.status_code == 200
|
|
body = resp.json()
|
|
assert body["doc_id"] == "t-1"
|
|
assert "matches" in body
|
|
assert "extracted_elements" in body
|
|
assert "engine_version" in body
|
|
|
|
|
|
def test_batch_flow():
|
|
with TestClient(app) as client:
|
|
resp = client.post(
|
|
"/v1/plagiarism/batch",
|
|
json={
|
|
"items": [
|
|
{"doc_id": "b-1", "text": "앤 셜리는 초록 지붕 집에 입양된 소녀다."},
|
|
]
|
|
},
|
|
headers={"X-API-Key": API_KEY},
|
|
)
|
|
assert resp.status_code == 202
|
|
job_id = resp.json()["job_id"]
|
|
status = client.get(
|
|
f"/v1/plagiarism/batch/{job_id}",
|
|
headers={"X-API-Key": API_KEY},
|
|
)
|
|
assert status.status_code == 200
|