forked from weaviate/t2v-transformers-models
-
Notifications
You must be signed in to change notification settings - Fork 0
/
smoke_test.py
executable file
·59 lines (42 loc) · 1.73 KB
/
smoke_test.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
import time
import unittest
import requests
class SmokeTest(unittest.TestCase):
def setUp(self):
self.url = 'http://localhost:8000'
for i in range(0, 100):
try:
res = requests.get(self.url + '/.well-known/ready')
if res.status_code == 204:
return
else:
raise Exception("status code is {}".format(res.status_code))
except Exception as e:
print("Attempt {}: {}".format(i, e))
time.sleep(1)
raise Exception("did not start up")
def test_well_known_ready(self):
res = requests.get(self.url + '/.well-known/ready')
self.assertEqual(res.status_code, 204)
def test_well_known_live(self):
res = requests.get(self.url + '/.well-known/live')
self.assertEqual(res.status_code, 204)
def test_meta(self):
res = requests.get(self.url + '/meta')
self.assertEqual(res.status_code, 200)
self.assertIsInstance(res.json(), dict)
def test_vectorizing(self):
def try_to_vectorize(url):
print(f"url: {url}")
req_body = {'text': 'The London Eye is a ferris wheel at the River Thames.'}
res = requests.post(url, json=req_body)
resBody = res.json()
self.assertEqual(200, res.status_code)
# below tests that what we deem a reasonable vector is returned. We are
# aware of 384 and 768 dim vectors, which should both fall in that
# range
self.assertTrue(len(resBody['vector']) > 100)
try_to_vectorize(self.url + "/vectors/")
try_to_vectorize(self.url + "/vectors")
if __name__ == "__main__":
unittest.main()