-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_student.py
261 lines (238 loc) · 11.4 KB
/
test_student.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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
'''
For running test file
STEPS:
pip install -r requirements.txt
python test_student.py
FOR DETAILED COVERAGE
coverage run --source models -m unittest discover && coverage report
coverage html
TestCase Details -
1. Home section
2. Admin section
3. Student section
4. Faculty section
'''
import flask
import unittest
import flask_testing
from app import app
import data_requests
from flask import json
''' Section 3 - Student Section '''
class TestStudent(flask_testing.TestCase):
def create_app(self):
return app
def testHomepage(self):
with app.test_client() as TestClient:
response= TestClient.get('/')
self.assertEqual(response.status_code, 200)
self.assert_template_used('index.html')
def testStudentLoginGet(self):
with app.test_client() as TestClient:
response= TestClient.get('/login/student')
self.assertEqual(response.status_code, 200)
self.assert_template_used('student/login.html')
def testStudentLoginPost(self):
data = data_requests.student_login
with app.test_client() as TestClient:
# login sequence
response= TestClient.post('/login/student', data = data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'student')
# login done
def testAdmin_logged_out(self):
data = data_requests.student_login
with app.test_client() as TestClient:
# login not done
response= TestClient.get('/student/dashboard')
self.assert_template_used('error.html')
response= TestClient.get('/student/profile')
self.assert_template_used('error.html')
response= TestClient.get('/student/setting')
self.assert_template_used('error.html')
response= TestClient.get('/student/enrolled-courses')
self.assert_template_used('error.html')
response= TestClient.get('/student/my-courses')
self.assert_template_used('error.html')
response= TestClient.get('/student/grades')
self.assert_template_used('error.html')
response= TestClient.get('/student/gradesheet')
self.assert_template_used('error.html')
response= TestClient.get('/student/placement-offers')
self.assert_template_used('error.html')
response= TestClient.get('/student/submit-assignment')
self.assert_template_used('error.html')
response= TestClient.get('/student/submit-assign/2')
self.assert_template_used('error.html')
def testAdmin_partial_logged_out(self):
data = data_requests.admin_login
with app.test_client() as TestClient:
# login sequence
response= TestClient.post('/login/admin', data = data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'admin')
# login done
response= TestClient.get('/student/dashboard')
self.assert_template_used('error.html')
response= TestClient.get('/student/profile')
self.assert_template_used('error.html')
response= TestClient.get('/student/setting')
self.assert_template_used('error.html')
response= TestClient.get('/student/enrolled-courses')
self.assert_template_used('error.html')
response= TestClient.get('/student/my-courses')
self.assert_template_used('error.html')
response= TestClient.get('/student/grades')
self.assert_template_used('error.html')
response= TestClient.get('/student/gradesheet')
self.assert_template_used('error.html')
response= TestClient.get('/student/placement-offers')
self.assert_template_used('error.html')
response= TestClient.get('/student/submit-assignment')
self.assert_template_used('error.html')
response= TestClient.get('/student/submit-assign/2')
self.assert_template_used('error.html')
def testStudentdashboard(self):
data = data_requests.student_login
with app.test_client() as TestClient:
# login sequence
response= TestClient.post('/login/student', data = data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'student')
# login done
response= TestClient.get('/student/dashboard')
self.assertEqual(response.status_code, 200)
self.assert_template_used('student_panel/dashboard.html')
def testStudent_Profile(self):
data = data_requests.student_login
myprofile = data_requests.student_profile
with app.test_client() as TestClient:
# login sequence
response= TestClient.post('/login/student', data = data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'student')
# login done
response= TestClient.get('/student/profile')
self.assertEqual(response.status_code, 200)
self.assert_template_used('student_panel/dashboard-profile.html')
# post
response= TestClient.post('/student/profile', data = myprofile)
self.assertEqual(response.status_code, 302)
def testStudent_setting(self):
data = data_requests.student_login
mysetting = data_requests.student_settings
with app.test_client() as TestClient:
# login sequence
response= TestClient.post('/login/student', data = data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'student')
# login done
response= TestClient.get('/student/setting')
self.assertEqual(response.status_code, 200)
self.assert_template_used('student_panel/dashboard-settings.html')
# post
response= TestClient.post('/student/setting', data = mysetting)
self.assertEqual(response.status_code, 302)
def testStudent_enrolled_course(self):
data = data_requests.student_login
myenroll = data_requests.student_enroll_course
with app.test_client() as TestClient:
# login sequence
response= TestClient.post('/login/student', data = data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'student')
# login done
response= TestClient.get('/student/enrolled-courses')
self.assertEqual(response.status_code, 200)
self.assert_template_used('student_panel/dashboard-enrolled-courses.html')
# post
response= TestClient.post('/student/enrolled-courses', data = myenroll)
self.assertEqual(response.status_code, 302)
def testStudent_my_courses(self):
data = data_requests.student_login
with app.test_client() as TestClient:
# login sequence
response= TestClient.post('/login/student', data = data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'student')
# login done
response= TestClient.get('/student/my-courses')
self.assertEqual(response.status_code, 200)
self.assert_template_used('student_panel/dashboard-courses.html')
def testStudent_grades(self):
data = data_requests.student_login
with app.test_client() as TestClient:
# login sequence
response= TestClient.post('/login/student', data = data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'student')
# login done
response= TestClient.get('/student/grades')
self.assertEqual(response.status_code, 200)
self.assert_template_used('student_panel/dashboard-grades.html')
def testStudent_gradesheet(self):
data = data_requests.student_login
mygradesheet = data_requests.student_gradesheet
with app.test_client() as TestClient:
# login sequence
response= TestClient.post('/login/student', data = data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'student')
# login done
response= TestClient.get('/student/gradesheet')
self.assertEqual(response.status_code, 200)
self.assert_template_used('student_panel/dashboard-gradesheet.html')
# post
response= TestClient.post('/student/gradesheet', data = mygradesheet)
self.assertEqual(response.status_code, 200)
def testStudent_placement(self):
data = data_requests.student_login
with app.test_client() as TestClient:
# login sequence
response= TestClient.post('/login/student', data = data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'student')
# login done
response= TestClient.get('/student/placement-offers')
self.assertEqual(response.status_code, 200)
self.assert_template_used('student_panel/dashboard-placement-offers.html')
def testStudent_submit_assignment(self):
data = data_requests.student_login
with app.test_client() as TestClient:
# login sequence
response= TestClient.post('/login/student', data = data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'student')
# login done
response= TestClient.get('/student/submit-assignment')
self.assertEqual(response.status_code, 200)
self.assert_template_used('student_panel/dashboard-assignment-submit.html')
def testStudent_submit_assign(self):
data = data_requests.student_login
myassn = data_requests.student_submit_assignment
with app.test_client() as TestClient:
# login sequence
response= TestClient.post('/login/student', data = data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'student')
# login done
response= TestClient.get('/student/submit-assign/4')
self.assertEqual(response.status_code, 200)
self.assert_template_used('student_panel/dashboard-submit-assignment.html')
# post
response= TestClient.post('/student/submit-assign/4', data = myassn)
self.assertEqual(response.status_code, 302)
if __name__ == "__main__":
unittest.main()