-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestGetTopN.py
43 lines (36 loc) · 1.48 KB
/
TestGetTopN.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
import unittest
from Api import Api
class TestGetTopN(unittest.TestCase):
def setUp(self):
api = Api()
self.app = api.app.test_client()
def test_valid_topN(self):
# Test for a valid topN value (within the range 1 to 100)
response = self.app.get('/topN/50')
response_data = response.data.decode('utf-8')
doc_list = response_data.split(",")
self.assertEqual(response.status_code, 200)
self.assertEqual(len(doc_list), 50)
def test_lower_bound(self):
# Test for the lower bound (topN = 1)
response = self.app.get('/topN/1')
response_data = response.data.decode('utf-8')
doc_list = response_data.split(",")
self.assertEqual(response.status_code, 200)
self.assertEqual(len(doc_list), 1)
def test_upper_bound(self):
# Test for the upper bound (topN = 100)
response = self.app.get('/topN/100')
response_data = response.data.decode('utf-8')
doc_list = response_data.split(",")
self.assertEqual(response.status_code, 200)
self.assertEqual(len(doc_list), 100)
def test_out_of_range(self):
# Test for an out-of-range topN value (topN < 1)
response = self.app.get('/topN/0')
self.assertEqual(response.status_code, 400)
# Test for an out-of-range topN value (topN > 100)
response = self.app.get('/topN/101')
self.assertEqual(response.status_code, 400)
if __name__ == '__main__':
unittest.main()