feat(nlp-service): FastAPI app with /parse and /health endpoints
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
52
nlp-service/test_main.py
Normal file
52
nlp-service/test_main.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def client():
|
||||
from main import app
|
||||
with TestClient(app) as c:
|
||||
yield c
|
||||
|
||||
|
||||
def test_health(client):
|
||||
response = client.get("/health")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"status": "ok"}
|
||||
|
||||
|
||||
def test_parse_returns_200_with_all_fields(client):
|
||||
response = client.post("/parse", json={"query": "Briefe vor 1920", "lang": "de"})
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "personNames" in data
|
||||
assert "personRole" in data
|
||||
assert data["personRole"] in ("sender", "receiver", "any")
|
||||
assert "dateFrom" in data
|
||||
assert "dateTo" in data
|
||||
assert "keywords" in data
|
||||
assert "rawQuery" in data
|
||||
assert data["rawQuery"] == "Briefe vor 1920"
|
||||
assert data["dateTo"] == "1920-12-31"
|
||||
|
||||
|
||||
def test_parse_unknown_lang_returns_422(client):
|
||||
response = client.post("/parse", json={"query": "test", "lang": "fr"})
|
||||
assert response.status_code == 422
|
||||
|
||||
|
||||
def test_parse_missing_query_returns_422(client):
|
||||
response = client.post("/parse", json={"lang": "de"})
|
||||
assert response.status_code == 422
|
||||
|
||||
|
||||
def test_parse_all_languages(client):
|
||||
cases = [
|
||||
("de", "Briefe vor 1920"),
|
||||
("en", "letters before 1920"),
|
||||
("es", "cartas antes de 1920"),
|
||||
]
|
||||
for lang, query in cases:
|
||||
response = client.post("/parse", json={"query": query, "lang": lang})
|
||||
assert response.status_code == 200, f"Failed for lang={lang}"
|
||||
assert response.json()["dateTo"] == "1920-12-31", f"Wrong dateTo for lang={lang}"
|
||||
Reference in New Issue
Block a user