forked from tokarevsas31/ml_fastapi_tests
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_main.py
61 lines (46 loc) · 1.91 KB
/
test_main.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
from fastapi.testclient import TestClient
from main import app
client = TestClient(app)
# тест 1
def test_read_main():
response = client.get("/")
assert response.status_code == 200
assert response.json() == {"message": "Hello World"}
# тест 2
def test_predict_positive():
response = client.post("/predict/", json={"text": "I love you!"})
json_data = response.json()
assert response.status_code == 200
assert json_data["Результат:"] == "позитивный :)"
# тест 3
def test_predict_negative():
response = client.post("/predict/", json={"text": "I am very angry"})
json_data = response.json()
assert response.status_code == 200
assert json_data["Результат:"] == "негативный (("
# тест 4
def test_predict_russian_positive():
response = client.post("/predict/", json={"text": "Я люблю учиться"})
json_data = response.json()
assert response.status_code == 200
assert json_data["Результат:"] == "позитивный :)"
# тест 5
def test_predict_russian_negative():
response = client.post("/predict/", json={"text": "Я ненавижу тебя"})
json_data = response.json()
assert response.status_code == 200
assert json_data["Результат:"] == "негативный (("
# тест 6
def test_predict_russian_neutral():
response = client.post("/predict/",
json={"text": "Сегодня наступила весна"}
)
json_data = response.json()
assert response.status_code == 200
assert json_data["Результат:"] == "нейтральный"
# тест 7
def test_predict_neutral():
response = client.post("/predict/", json={"text": "Today spring has come"})
json_data = response.json()
assert response.status_code == 200
assert json_data["Результат:"] == "нейтральный"