This repository was archived by the owner on Feb 22, 2025. It is now read-only.
forked from ronnie-36/University-Management-System
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_faculty.py
More file actions
346 lines (319 loc) · 16 KB
/
test_faculty.py
File metadata and controls
346 lines (319 loc) · 16 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
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
import flask
import unittest
import flask_testing
from flask import *
from app import app
import data_requests
class TestFaculty(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 testFacultyLoginGet(self):
with app.test_client() as TestClient:
response = TestClient.get('/login/faculty')
self.assertEqual(response.status_code, 200)
self.assert_template_used('faculty/login.html')
def testFacultyLoginPost(self):
data1 = data_requests.faculty_login1
data2 = data_requests.faculty_login2
with app.test_client() as TestClient:
# login sequence
response = TestClient.post('/login/faculty', data=data1)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'faculty')
# login done
# invalid login
response = TestClient.post('/login/faculty', data=data2)
self.assertEqual(response.status_code, 200)
self.assert_template_used('faculty/login.html')
def testFaculty_logged_out(self):
data = data_requests.admin_login
with app.test_client() as TestClient:
# login not done
response = TestClient.get('/faculty/dashboard')
self.assert_template_used('error.html')
response = TestClient.get('/faculty/setting')
self.assert_template_used('error.html')
response = TestClient.get('/faculty/profile')
self.assert_template_used('error.html')
response = TestClient.get('/faculty/changepassword')
self.assert_template_used('error.html')
response = TestClient.get('/faculty/create_new_assignment')
self.assert_template_used('error.html')
response = TestClient.get('/faculty/grade_assignment')
self.assert_template_used('error.html')
response = TestClient.get('/faculty/grade_assignment/1')
self.assert_template_used('error.html')
response = TestClient.get('/faculty/grade_assignment/1/1')
self.assert_template_used('error.html')
response = TestClient.get('/faculty/grade_assignment/submission/1')
self.assert_template_used('error.html')
def testAdmin_partial_logged_out(self):
data = data_requests.faculty_login1
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('/faculty/dashboard')
self.assert_template_used('error.html')
response = TestClient.get('/faculty/setting')
self.assert_template_used('error.html')
response = TestClient.get('/faculty/profile')
self.assert_template_used('error.html')
response = TestClient.get('/faculty/changepassword')
self.assert_template_used('error.html')
response = TestClient.get('/faculty/create_new_assignment')
self.assert_template_used('error.html')
response = TestClient.get('/faculty/grade_assignment')
self.assert_template_used('error.html')
response = TestClient.get('/faculty/grade_assignment/1')
self.assert_template_used('error.html')
response = TestClient.get('/faculty/grade_assignment/1/1')
self.assert_template_used('error.html')
response = TestClient.get('/faculty/grade_assignment/submission/1')
self.assert_template_used('error.html')
def testFacultyDashboard(self):
data = data_requests.faculty_login1
with app.test_client() as TestClient:
# login sequence
response = TestClient.post('/login/faculty', data=data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'faculty')
# login done
response = TestClient.get('/faculty/dashboard')
self.assert_template_used('faculty/instructor_dashboard.html')
def testFacultySetting(self):
data = data_requests.faculty_login1
with app.test_client() as TestClient:
# login sequence
response = TestClient.post('/login/faculty', data=data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'faculty')
# login done
response = TestClient.get('/faculty/setting')
self.assert_template_used('faculty/setting.html')
def testFacultyProfileGet(self):
data = data_requests.faculty_login1
with app.test_client() as TestClient:
# login sequence
response = TestClient.post('/login/faculty', data=data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'faculty')
# login done
response = TestClient.get('/faculty/profile')
self.assert_template_used('faculty/faculty-profile.html')
def testFacultyProfilePost(self):
data = data_requests.faculty_login1
data_profile = data_requests.faculty_profile
with app.test_client() as TestClient:
# login sequence
response = TestClient.post('/login/faculty', data=data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'faculty')
# login done
response = TestClient.post('/faculty/profile', data=data_profile)
self.assertEqual(response.status_code, 302)
self.assertEqual(request.path, url_for('faculty_profile'))
def testFacultyChangePasswordGet(self):
data = data_requests.faculty_login1
with app.test_client() as TestClient:
# login sequence
response = TestClient.post('/login/faculty', data=data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'faculty')
# login done
response = TestClient.get('/faculty/changepassword')
self.assertEqual(response.status_code, 405)
def testFacultyChangePasswordPost(self):
data = data_requests.faculty_login1
data_password_change_empty = data_requests.faculty_change_password1
data_password_change_different = data_requests.faculty_change_password2
data_password_change_wrong = data_requests.faculty_change_password3
data_password_change_correct = data_requests.faculty_change_password4
data_password_change_revert = data_requests.faculty_change_password_revert
with app.test_client() as TestClient:
# login sequence
response = TestClient.post('/login/faculty', data=data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'faculty')
# login done
# testing for null values
response = TestClient.post(
'/faculty/changepassword', data=data_password_change_empty)
self.assert_template_used('faculty/setting.html')
self.assert_context("flash", "Null Values Encountered.")
# new password and confirm password don't match
response = TestClient.post(
'/faculty/changepassword', data=data_password_change_different)
self.assert_template_used('faculty/setting.html')
self.assert_context(
"flash", "Passwords do not match. Check password.")
# wrong current password
response = TestClient.post(
'/faculty/changepassword', data=data_password_change_wrong)
self.assert_template_used('faculty/setting.html')
self.assert_context("flash", "Current Password is wrong.")
# correct case
response = TestClient.post(
'/faculty/changepassword', data=data_password_change_correct)
self.assert_template_used('faculty/setting.html')
self.assert_context("flash", "Password Changed.")
# reverting
response = TestClient.post(
'/faculty/changepassword', data=data_password_change_revert)
self.assert_template_used('faculty/setting.html')
self.assert_context("flash", "Password Changed.")
def testFacultyCourseGet(self):
data = data_requests.faculty_login1
with app.test_client() as TestClient:
# login sequence
response = TestClient.post('/login/faculty', data=data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'faculty')
# login done
response = TestClient.get('/faculty/courses')
self.assert_template_used('faculty/faculty-courses.html')
def testFacultyCreateNewAssignmentGet(self):
data = data_requests.faculty_login1
with app.test_client() as TestClient:
# login sequence
response = TestClient.post('/login/faculty', data=data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'faculty')
# login done
response = TestClient.get('/faculty/create_new_assignment')
self.assert_template_used('faculty/create_new_assignment.html')
def testFacultyCreateNewAssignmentPost(self):
data = data_requests.faculty_login1
assignmentData = data_requests.faculty_create_new_assignment
with app.test_client() as TestClient:
# login sequence
response = TestClient.post('/login/faculty', data=data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'faculty')
# login done
response = TestClient.post(
'/faculty/create_new_assignment', data=assignmentData)
self.assertEqual(response.status_code, 302)
self.assertEqual(request.path, url_for(
'faculty_create_new_assignment'))
def testFacultySelectSectionForAssignmentGet(self):
data = data_requests.faculty_login1
with app.test_client() as TestClient:
# login sequence
response = TestClient.post('/login/faculty', data=data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'faculty')
# login done
response = TestClient.get('/faculty/grade_assignment')
self.assert_template_used(
'faculty/select_section_for_assignment.html')
def testFacultySelectSectionForAssignmentPost(self):
data = data_requests.faculty_login1
with app.test_client() as TestClient:
# login sequence
response = TestClient.post('/login/faculty', data=data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'faculty')
# login done
response = TestClient.post('/faculty/grade_assignment')
self.assertEqual(response.status_code, 302)
self.assertEqual(request.path, url_for(
'select_section_for_assignment'))
def testFacultySelectAssignmentForGradeGet(self):
data = data_requests.faculty_login1
with app.test_client() as TestClient:
# login sequence
response = TestClient.post('/login/faculty', data=data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'faculty')
# login done
response = TestClient.get('/faculty/grade_assignment/1')
self.assert_template_used(
'faculty/select_assignment_for_grade.html')
self.assert_context("sec_id", 1)
def testFacultySelectAssignmentForGradePost(self):
data = data_requests.faculty_login1
with app.test_client() as TestClient:
# login sequence
response = TestClient.post('/login/faculty', data=data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'faculty')
# login done
response = TestClient.post('/faculty/grade_assignment/1')
self.assertEqual(response.status_code, 302)
self.assertEqual(request.path, url_for(
'select_assignment_for_grade', sec_id=1))
def testFacultySelectStudentForGradeGet(self):
data = data_requests.faculty_login1
with app.test_client() as TestClient:
# login sequence
response = TestClient.post('/login/faculty', data=data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'faculty')
# login done
response = TestClient.get('/faculty/grade_assignment/1/1')
self.assert_template_used(
'faculty/select_student_for_grade.html')
def testFacultySelectStudentForGradePost(self):
data = data_requests.faculty_login1
with app.test_client() as TestClient:
# login sequence
response = TestClient.post('/login/faculty', data=data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'faculty')
# login done
response = TestClient.post('/faculty/grade_assignment/1/1')
self.assertEqual(response.status_code, 302)
self.assertEqual(request.path, url_for(
'select_student_for_grade', sec_id=1, a_id=1))
def testFacultyAssignmentGradeSubmissionGet(self):
data = data_requests.faculty_login1
with app.test_client() as TestClient:
# login sequence
response = TestClient.post('/login/faculty', data=data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'faculty')
# login done
response = TestClient.get('/faculty/grade_assignment/submission/1')
self.assert_template_used(
'faculty/grade_submission.html')
def testFacultyAssignmentGradeSubmissionPost(self):
data = data_requests.faculty_login1
gradeData = data_requests.faculty_grade_assignment
with app.test_client() as TestClient:
# login sequence
response = TestClient.post('/login/faculty', data=data)
self.assertEqual(response.status_code, 302)
self.assertEqual(flask.session['id'], '1')
self.assertEqual(flask.session['role'], 'faculty')
# login done
response = TestClient.post(
'/faculty/grade_assignment/submission/2', data=gradeData)
self.assertEqual(response.status_code, 302)
if __name__ == "__main__":
unittest.main()