-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_API.py
More file actions
122 lines (98 loc) · 5.06 KB
/
Copy pathtest_API.py
File metadata and controls
122 lines (98 loc) · 5.06 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import unittest
from unittest import TestCase
from server import app
from model import connect_to_db, db, Program, Section, Activity, init_app
# All endpoints have been tested on Postman
class FlaskTests(unittest.TestCase):
def setUp(self):
# create a test client
self.client = app.test_client()
app.config['TESTING'] = True
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
def test_all_programs(self):
"""Test GET request for all programs"""
result = self.client.get("/program",data =
{"all_programs_key": [
{
"description": "hi",
"id": 1,
"name": "Linh",
"sections": []
},
{
"description": "1st program description",
"id": 2,
"name": "1st program from SeHwan",
"sections": []
},
{
"description": "2nd program description",
"id": 3,
"name": "2nd program from SeHwan",
"sections": []
},
{
"description": "3rd program description",
"id": 4,
"name": "3rd program from SeHwan",
"sections": []
},
{
"description": "helll yeah!!!",
"id": 5,
"name": "haha finally working",
"sections": [
"Section POST REQUEST",
"Section POST REQUEST2",
"Section POST REQUEST3",
"Section POST REQUEST4",
"Section POST REQUEST 5"
]
},
{
"description": "please work",
"id": 6,
"name": "this is name",
"sections": []
}
]
})
self.assertEqual(result.status_code, 200)
self.assertIN(b'Woah! Working', result.data)
# def test_program(self):
# """Test GET request for one program"""
# result = self.client.get('/program', data={
# "program_name": "linh6",
# "description" : "this is the best program"
# })
# self.assertEqual(result.status_code, 200)
# self.assertIn(b'Woah! Working', result.data)
def test_one_section(self):
"""Test GET request for one section in one program"""
result = self.client.get('/program/Linh/section', data ={
"section_name": "section_1_name",
"description": "section_1_detail",
"overview_Image_url": "http://awesome.io",
"activities": []
})
self.assertEqual(result.status_code, 200)
self.assertIn(b'Woah! Working', result.data)
def test_activity(self):
"""Test GET request for all activity for one section in one program"""
result = self.client.get('/program/Linh/section/section_1_name/activity', data={
"all_activities_key": []
})
self.assertEqual(result.status_code, 200)
self.assertIn(b'Woah! Working', result.data)
def test_program(self):
"""Test POST request for one program"""
result = self.client.post('/program', data={
"program_name": "linh6",
"description" : "this is the best program"
})
self.assertEqual(result.status_code, 200)
self.assertIn(b'Woah! Working', result.data)
init_app()
if __name__ == "__main__":
unittest.main()
# init_app()