-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_api.py
39 lines (32 loc) · 952 Bytes
/
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
from starlette.testclient import TestClient
from server import app
import os
client = TestClient(app)
def test_hello_world():
endpoint = '/'
r = client.get(endpoint)
assert r.status_code == 200
def test_api():
img_path = './serena.png'
endpoint = '/predict'
files = {'image': open(img_path, 'rb')}
r = client.post(endpoint, files=files)
assert r.status_code == 200
print(r.json())
assert "nose" in r.json().keys()
"""
out_path = './serena_output.png'
with open(out_path, 'wb') as f:
f.write(r.content)
assert os.path.isfile(out_path)
"""
def test_image_api():
img_path = './serena.png'
endpoint = '/predict_image'
files = {'image': open(img_path, 'rb')}
r = client.post(endpoint, files=files)
assert r.status_code == 200
out_path = './serena_output.png'
with open(out_path, 'wb') as f:
f.write(r.content)
assert os.path.isfile(out_path)