-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_app.py
44 lines (29 loc) · 978 Bytes
/
test_app.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
import pytest
from fastapi.testclient import TestClient
from main import app
@pytest.fixture
def client():
return TestClient(app)
def test_base_endpoint_get(client):
""" test base endpoint """
response = client.get('/')
assert response.status_code == 404
def test_base_endpoint_post(client):
response = client.post('/')
assert response.status_code == 404
def test_predict_endpoint_get(client):
""" test predict endpoint """
# test get
response = client.get('/predict')
assert response.status_code == 405
def test_predict_endpoint_post_nojson(client):
# test invalid post
response = client.post('/predict')
assert response.status_code == 422
def test_predict_endpoint_post_valid_json(client):
# test valid post
response = client.post('/predict', json={
"text": "it's a beautiful world"
})
assert response.status_code == 200
assert response.json()["output"] in ["positive", "negative"]