-
-
Notifications
You must be signed in to change notification settings - Fork 469
/
Copy pathtest_project_fastapi.py
30 lines (26 loc) · 1.1 KB
/
test_project_fastapi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import pytest
from spacy.cli.project.run import project_run
from spacy.cli.project.assets import project_assets
from pathlib import Path
@pytest.mark.skip(reason="Import currently fails")
def test_fastapi_project():
root = Path(__file__).parent
project_assets(root)
project_run(root, "download", capture=True)
# This is ugly, but we only have the dependency here
from fastapi.testclient import TestClient
from scripts.main import app, ModelName
model_names = [model.value for model in ModelName]
assert model_names
client = TestClient(app)
response = client.get("/models")
assert response.status_code == 200
assert response.json() == model_names
articles = [{"text": "This is a text"}, {"text": "This is another text"}]
data = {"articles": articles, "model": model_names[0]}
response = client.post("/process/", json=data)
assert response.status_code == 200
result = response.json()["result"]
assert len(result) == len(articles)
assert [{"text": entry["text"]} for entry in result] == articles
assert all("ents" in entry for entry in result)