-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_test.py
More file actions
54 lines (47 loc) · 2.13 KB
/
api_test.py
File metadata and controls
54 lines (47 loc) · 2.13 KB
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
import unittest
from main import app
class FlaskTest(unittest.TestCase):
# Check for get response 200
def test_index(self):
tester = app.test_client(self)
BASE = "http://127.0.0.1:5000/"
response=tester.get(BASE + "video")
statuscode=response.status_code
self.assertEqual(statuscode, 200)
# Check if content returned is application/json
def test_index_content(self):
tester = app.test_client(self)
BASE = "http://127.0.0.1:5000/"
response=tester.get(BASE + "video?name=video")
self.assertEqual(response.content_type, 'application/json')
# Check for data returned
def test_index_data(self):
tester=app.test_client(self)
BASE = "http://127.0.0.1:5000/"
response = tester.get(BASE + "video?name=video")
print(response)
# do not include the brackets at the ends in the comparison
self.assertTrue(str(response.data.decode("utf-8")[1:-2]) == '{"id": 1, "name": "First Video", "views": 1, "likes": 0}, {"id": 2, "name": "Second Video", "views": 2, "likes": 2}')
# Check for delete response 200
def test_delete_video(self):
tester=app.test_client(self)
BASE = "http://127.0.0.1:5000/"
response = tester.delete(BASE + "video?id=5")
statuscode = response.status_code
self.assertEqual(statuscode, 200)
# Check for put response 201
def test_put_new_video(self):
tester=app.test_client(self)
BASE = "http://127.0.0.1:5000/"
response = tester.put(BASE + "video?id=5&name=FIVE&views=55&likes=5")
statuscode = response.status_code
self.assertEqual(statuscode, 201)
# Check for patch response 200
def test_patch_video(self):
tester=app.test_client(self)
BASE = "http://127.0.0.1:5000/"
response = tester.patch(BASE + "video?id=3&name=Three+Part+2&views=23&likes=3")
statuscode = response.status_code
self.assertEqual(statuscode, 200)
if __name__=='__main__':
unittest.main()