-
Notifications
You must be signed in to change notification settings - Fork 296
/
Copy pathtest_api.py
62 lines (57 loc) · 2.59 KB
/
test_api.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import pytest
import json
from model import SpacyMLBackend
@pytest.fixture
def client():
from _wsgi import init_app
app = init_app(model_class=SpacyMLBackend)
app.config['TESTING'] = True
with app.test_client() as client:
yield client
def test_predict(client):
expected_response = {
"results": [
{
"model_version": "SpacyMLBackend-v0.0.1",
"result": [
{
"from_name": "ner_tags",
"to_name": "text",
"type": "labels",
"value": {
"end": 10,
"labels": ["PERSON"],
"start": 0,
"text": "Katy Perry"
}
},
{
"from_name": "ner_tags",
"to_name": "text",
"type": "labels",
"value": {
"end": 23,
"labels": ["ORG"],
"start": 15,
"text": "Pharrell"
}
},
{
"from_name": "ner_tags",
"to_name": "text",
"type": "labels",
"value": {
"end": 83,
"labels": ["PRODUCT"],
"start": 47,
"text": "Apple Watches http://t.co/k6k3SdwShP"
}
}
],
"score": 0.0
}
]
}
response = client.post('/predict', json=json.loads('{"tasks": [{"id": 1428, "data": {"text": "Katy Perry and Pharrell have the same taste in Apple Watches http://t.co/k6k3SdwShP"}, "meta": {}, "created_at": "2024-03-20T20:50:22.955810Z", "updated_at": "2024-03-20T20:50:22.955819Z", "is_labeled": false, "overlap": 1, "inner_id": 18, "total_annotations": 0, "cancelled_annotations": 0, "total_predictions": 0, "comment_count": 0, "unresolved_comment_count": 0, "last_comment_updated_at": null, "project": 6, "updated_by": null, "file_upload": 8, "comment_authors": [], "annotations": [], "predictions": []}], "project": "6.1710967805", "label_config": "<View>\\n <Labels name=\\"ner_tags\\" toName=\\"text\\">\\n <Label value=\\"label_1\\" background=\\"#FFA39E\\"/>\\n <Label value=\\"label_2\\" background=\\"#D4380D\\"/>\\n <Label value=\\"label_3\\" background=\\"#FFC069\\"/>\\n </Labels>\\n <Text name=\\"text\\" value=\\"$text\\"/>\\n</View>", "params": {"login": null, "password": null, "context": null}}'))
assert response.status_code == 200
assert response.json == expected_response