-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_server.py
30 lines (23 loc) · 1008 Bytes
/
test_server.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 unittest
import base64
import server
class ServerTestCase(unittest.TestCase):
def setUp(self):
self.app = server.create_app()
self.app.config['TESTING'] = True
self.client = self.app.test_client()
self.url_image = {'url': 'https://tensorflow.org/images/blogs/serving/cat.jpg'}
self.path_image = 'cat.jpg'
self.url = 'https://tensorflow.org/images/blogs/serving/cat.jpg'
def test_post_PredictImage(self):
input_image = open(self.path_image, "rb").read()
encoded_input_string = base64.b64encode(input_image)
input_string = encoded_input_string.decode("utf-8")
body = {'img': input_string}
response = self.client.post('/api/image/', json=body)
self.assertEqual(response.status_code, 200)
def test_post_PredictURL(self):
response = self.client.post('/api/url/', json=self.url_image)
self.assertEqual(response.status_code, 200)
if __name__ == "__main__":
unittest.main()