1 | ## $Id: test_browser.py 7454 2012-01-12 11:53:01Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
4 | ## This program is free software; you can redistribute it and/or modify |
---|
5 | ## it under the terms of the GNU General Public License as published by |
---|
6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
7 | ## (at your option) any later version. |
---|
8 | ## |
---|
9 | ## This program is distributed in the hope that it will be useful, |
---|
10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | ## GNU General Public License for more details. |
---|
13 | ## |
---|
14 | ## You should have received a copy of the GNU General Public License |
---|
15 | ## along with this program; if not, write to the Free Software |
---|
16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | ## |
---|
18 | """ |
---|
19 | Test the student-related UI components. |
---|
20 | """ |
---|
21 | import shutil |
---|
22 | import tempfile |
---|
23 | from StringIO import StringIO |
---|
24 | from datetime import datetime |
---|
25 | import os |
---|
26 | import grok |
---|
27 | from zope.event import notify |
---|
28 | from zope.component import createObject |
---|
29 | from zope.component.hooks import setSite, clearSite |
---|
30 | from zope.security.interfaces import Unauthorized |
---|
31 | from zope.securitypolicy.interfaces import IPrincipalRoleManager |
---|
32 | from zope.testbrowser.testing import Browser |
---|
33 | from hurry.workflow.interfaces import IWorkflowInfo |
---|
34 | from waeup.sirp.testing import FunctionalLayer, FunctionalTestCase |
---|
35 | from waeup.sirp.app import University |
---|
36 | from waeup.sirp.configuration import SessionConfiguration |
---|
37 | from waeup.sirp.students.student import Student |
---|
38 | from waeup.sirp.students.studylevel import StudentStudyLevel |
---|
39 | from waeup.sirp.university.faculty import Faculty |
---|
40 | from waeup.sirp.university.department import Department |
---|
41 | from waeup.sirp.interfaces import IUserAccount |
---|
42 | from waeup.sirp.authentication import LocalRoleSetEvent |
---|
43 | from waeup.sirp.hostels.hostel import Hostel, Bed, NOT_OCCUPIED |
---|
44 | |
---|
45 | PH_LEN = 2059 # Length of placeholder file |
---|
46 | |
---|
47 | def lookup_submit_value(name, value, browser): |
---|
48 | """Find a button with a certain value.""" |
---|
49 | for num in range(0, 100): |
---|
50 | try: |
---|
51 | button = browser.getControl(name=name, index=num) |
---|
52 | if button.value.endswith(value): |
---|
53 | return button |
---|
54 | except IndexError: |
---|
55 | break |
---|
56 | return None |
---|
57 | |
---|
58 | class StudentsFullSetup(FunctionalTestCase): |
---|
59 | # A test case that only contains a setup and teardown |
---|
60 | # |
---|
61 | # Complete setup for students handlings is rather complex and |
---|
62 | # requires lots of things created before we can start. This is a |
---|
63 | # setup that does all this, creates a university, creates PINs, |
---|
64 | # etc. so that we do not have to bother with that in different |
---|
65 | # test cases. |
---|
66 | |
---|
67 | layer = FunctionalLayer |
---|
68 | |
---|
69 | def setUp(self): |
---|
70 | super(StudentsFullSetup, self).setUp() |
---|
71 | |
---|
72 | # Setup a sample site for each test |
---|
73 | app = University() |
---|
74 | self.dc_root = tempfile.mkdtemp() |
---|
75 | app['datacenter'].setStoragePath(self.dc_root) |
---|
76 | |
---|
77 | # Prepopulate the ZODB... |
---|
78 | self.getRootFolder()['app'] = app |
---|
79 | # we add the site immediately after creation to the |
---|
80 | # ZODB. Catalogs and other local utilities are not setup |
---|
81 | # before that step. |
---|
82 | self.app = self.getRootFolder()['app'] |
---|
83 | # Set site here. Some of the following setup code might need |
---|
84 | # to access grok.getSite() and should get our new app then |
---|
85 | setSite(app) |
---|
86 | |
---|
87 | # Add student with subobjects |
---|
88 | student = Student() |
---|
89 | student.firstname = u'Anna' |
---|
90 | student.lastname = u'Tester' |
---|
91 | student.reg_number = u'123' |
---|
92 | student.matric_number = u'234' |
---|
93 | student.sex = u'm' |
---|
94 | student.email = 'aa@aa.ng' |
---|
95 | student.phone = u'1234' |
---|
96 | self.app['students'].addStudent(student) |
---|
97 | self.student_id = student.student_id |
---|
98 | self.student = self.app['students'][self.student_id] |
---|
99 | |
---|
100 | # Set password |
---|
101 | IUserAccount( |
---|
102 | self.app['students'][self.student_id]).setPassword('spwd') |
---|
103 | |
---|
104 | self.login_path = 'http://localhost/app/login' |
---|
105 | self.container_path = 'http://localhost/app/students' |
---|
106 | self.manage_container_path = self.container_path + '/@@manage' |
---|
107 | self.add_student_path = self.container_path + '/addstudent' |
---|
108 | self.student_path = self.container_path + '/' + self.student_id |
---|
109 | self.manage_student_path = self.student_path + '/manage_base' |
---|
110 | self.clearance_student_path = self.student_path + '/view_clearance' |
---|
111 | self.personal_student_path = self.student_path + '/view_personal' |
---|
112 | self.edit_clearance_student_path = self.student_path + '/edit_clearance' |
---|
113 | self.edit_personal_student_path = self.student_path + '/edit_personal' |
---|
114 | self.studycourse_student_path = self.student_path + '/studycourse' |
---|
115 | self.payments_student_path = self.student_path + '/payments' |
---|
116 | self.acco_student_path = self.student_path + '/accommodation' |
---|
117 | self.history_student_path = self.student_path + '/history' |
---|
118 | |
---|
119 | # Create 5 access codes with prefix'PWD' |
---|
120 | pin_container = self.app['accesscodes'] |
---|
121 | pin_container.createBatch( |
---|
122 | datetime.now(), 'some_userid', 'PWD', 9.99, 5) |
---|
123 | pins = pin_container['PWD-1'].values() |
---|
124 | self.pwdpins = [x.representation for x in pins] |
---|
125 | self.existing_pwdpin = self.pwdpins[0] |
---|
126 | parts = self.existing_pwdpin.split('-')[1:] |
---|
127 | self.existing_pwdseries, self.existing_pwdnumber = parts |
---|
128 | # Create 5 access codes with prefix 'CLR' |
---|
129 | pin_container.createBatch( |
---|
130 | datetime.now(), 'some_userid', 'CLR', 9.99, 5) |
---|
131 | pins = pin_container['CLR-1'].values() |
---|
132 | pins[0].owner = u'Hans Wurst' |
---|
133 | self.existing_clrac = pins[0] |
---|
134 | self.existing_clrpin = pins[0].representation |
---|
135 | parts = self.existing_clrpin.split('-')[1:] |
---|
136 | self.existing_clrseries, self.existing_clrnumber = parts |
---|
137 | # Create 2 access codes with prefix 'HOS' |
---|
138 | pin_container.createBatch( |
---|
139 | datetime.now(), 'some_userid', 'HOS', 9.99, 2) |
---|
140 | pins = pin_container['HOS-1'].values() |
---|
141 | self.existing_hosac = pins[0] |
---|
142 | self.existing_hospin = pins[0].representation |
---|
143 | parts = self.existing_hospin.split('-')[1:] |
---|
144 | self.existing_hosseries, self.existing_hosnumber = parts |
---|
145 | |
---|
146 | # Populate university |
---|
147 | self.certificate = createObject('waeup.Certificate') |
---|
148 | self.certificate.code = u'CERT1' |
---|
149 | self.certificate.application_category = 'basic' |
---|
150 | self.certificate.study_mode = 'ug_ft' |
---|
151 | self.certificate.start_level = 100 |
---|
152 | self.certificate.end_level = 500 |
---|
153 | self.app['faculties']['fac1'] = Faculty() |
---|
154 | self.app['faculties']['fac1']['dep1'] = Department(code='dep1') |
---|
155 | self.app['faculties']['fac1']['dep1'].certificates.addCertificate( |
---|
156 | self.certificate) |
---|
157 | self.course = createObject('waeup.Course') |
---|
158 | self.course.code = 'COURSE1' |
---|
159 | self.course.semester = 1 |
---|
160 | self.course.credits = 10 |
---|
161 | self.course.passmark = 40 |
---|
162 | self.app['faculties']['fac1']['dep1'].courses.addCourse( |
---|
163 | self.course) |
---|
164 | self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCourseRef( |
---|
165 | self.course, level=100) |
---|
166 | |
---|
167 | # Configure university |
---|
168 | self.app['configuration'].accommodation_states = ['admitted'] |
---|
169 | self.app['configuration'].accommodation_session = 2004 |
---|
170 | configuration = SessionConfiguration() |
---|
171 | # These attributes must also exist in the customization packages. |
---|
172 | configuration.academic_session = 2004 |
---|
173 | configuration.fee_1 = 20000 |
---|
174 | configuration.boocking_fee = 500 |
---|
175 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
176 | |
---|
177 | # Create a hostel with two beds |
---|
178 | hostel = Hostel() |
---|
179 | hostel.hostel_id = u'hall-1' |
---|
180 | hostel.hostel_name = u'Hall 1' |
---|
181 | self.app['hostels'].addHostel(hostel) |
---|
182 | bed = Bed() |
---|
183 | bed.bed_id = u'hall-1_A_101_A' |
---|
184 | bed.bed_number = 1 |
---|
185 | bed.owner = NOT_OCCUPIED |
---|
186 | bed.bed_type = u'regular_male_fr' |
---|
187 | self.app['hostels'][hostel.hostel_id].addBed(bed) |
---|
188 | bed = Bed() |
---|
189 | bed.bed_id = u'hall-1_A_101_B' |
---|
190 | bed.bed_number = 2 |
---|
191 | bed.owner = NOT_OCCUPIED |
---|
192 | bed.bed_type = u'regular_female_fr' |
---|
193 | self.app['hostels'][hostel.hostel_id].addBed(bed) |
---|
194 | |
---|
195 | # Set study course attributes of test student |
---|
196 | self.student['studycourse'].certificate = self.certificate |
---|
197 | self.student['studycourse'].current_session = 2004 |
---|
198 | self.student['studycourse'].entry_session = 2004 |
---|
199 | self.student['studycourse'].current_verdict = 'A' |
---|
200 | self.student['studycourse'].current_level = 100 |
---|
201 | # Update the catalog |
---|
202 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
203 | |
---|
204 | # Put the prepopulated site into test ZODB and prepare test |
---|
205 | # browser |
---|
206 | self.browser = Browser() |
---|
207 | self.browser.handleErrors = False |
---|
208 | |
---|
209 | def tearDown(self): |
---|
210 | super(StudentsFullSetup, self).tearDown() |
---|
211 | clearSite() |
---|
212 | shutil.rmtree(self.dc_root) |
---|
213 | |
---|
214 | |
---|
215 | |
---|
216 | class StudentsContainerUITests(StudentsFullSetup): |
---|
217 | # Tests for StudentsContainer class views and pages |
---|
218 | |
---|
219 | layer = FunctionalLayer |
---|
220 | |
---|
221 | def test_anonymous_access(self): |
---|
222 | # Anonymous users can't access students containers |
---|
223 | self.assertRaises( |
---|
224 | Unauthorized, self.browser.open, self.container_path) |
---|
225 | self.assertRaises( |
---|
226 | Unauthorized, self.browser.open, self.manage_container_path) |
---|
227 | return |
---|
228 | |
---|
229 | def test_manage_access(self): |
---|
230 | # Managers can access the view page of students |
---|
231 | # containers and can perform actions |
---|
232 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
233 | self.browser.open(self.container_path) |
---|
234 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
235 | self.assertEqual(self.browser.url, self.container_path) |
---|
236 | self.browser.getLink("Manage student section").click() |
---|
237 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
238 | self.assertEqual(self.browser.url, self.manage_container_path) |
---|
239 | return |
---|
240 | |
---|
241 | def test_add_search_delete_students(self): |
---|
242 | # Managers can add search and remove students |
---|
243 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
244 | self.browser.open(self.manage_container_path) |
---|
245 | self.browser.getLink("Add student").click() |
---|
246 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
247 | self.assertEqual(self.browser.url, self.add_student_path) |
---|
248 | self.browser.getControl(name="form.firstname").value = 'Bob' |
---|
249 | self.browser.getControl(name="form.lastname").value = 'Tester' |
---|
250 | self.browser.getControl("Create student record").click() |
---|
251 | self.assertTrue('Student record created' in self.browser.contents) |
---|
252 | |
---|
253 | # Registration and matric numbers must be unique |
---|
254 | self.browser.getLink("Manage").click() |
---|
255 | self.browser.getControl(name="form.reg_number").value = '123' |
---|
256 | self.browser.getControl("Save").click() |
---|
257 | self.assertMatches('...Registration number exists...', |
---|
258 | self.browser.contents) |
---|
259 | self.browser.getControl(name="form.reg_number").value = '789' |
---|
260 | self.browser.getControl(name="form.matric_number").value = '234' |
---|
261 | self.browser.getControl("Save").click() |
---|
262 | self.assertMatches('...Matriculation number exists...', |
---|
263 | self.browser.contents) |
---|
264 | |
---|
265 | # We can find a student with a certain student_id |
---|
266 | self.browser.open(self.container_path) |
---|
267 | self.browser.getControl("Search").click() |
---|
268 | self.assertTrue('Empty search string' in self.browser.contents) |
---|
269 | self.browser.getControl(name="searchtype").value = ['student_id'] |
---|
270 | self.browser.getControl(name="searchterm").value = self.student_id |
---|
271 | self.browser.getControl("Search").click() |
---|
272 | self.assertTrue('Anna Tester' in self.browser.contents) |
---|
273 | |
---|
274 | # We can find a student in a certain department |
---|
275 | self.browser.open(self.container_path) |
---|
276 | self.browser.getControl(name="searchtype").value = ['depcode'] |
---|
277 | self.browser.getControl(name="searchterm").value = 'dep1' |
---|
278 | self.browser.getControl("Search").click() |
---|
279 | self.assertTrue('Anna Tester' in self.browser.contents) |
---|
280 | |
---|
281 | # We can find a student by searching for all kind of name parts |
---|
282 | self.browser.open(self.manage_container_path) |
---|
283 | self.browser.getControl("Search").click() |
---|
284 | self.assertTrue('Empty search string' in self.browser.contents) |
---|
285 | self.browser.getControl(name="searchtype").value = ['fullname'] |
---|
286 | self.browser.getControl(name="searchterm").value = 'Anna Tester' |
---|
287 | self.browser.getControl("Search").click() |
---|
288 | self.assertTrue('Anna Tester' in self.browser.contents) |
---|
289 | self.browser.open(self.manage_container_path) |
---|
290 | self.browser.getControl(name="searchtype").value = ['fullname'] |
---|
291 | self.browser.getControl(name="searchterm").value = 'Anna' |
---|
292 | self.browser.getControl("Search").click() |
---|
293 | self.assertTrue('Anna Tester' in self.browser.contents) |
---|
294 | self.browser.open(self.manage_container_path) |
---|
295 | self.browser.getControl(name="searchtype").value = ['fullname'] |
---|
296 | self.browser.getControl(name="searchterm").value = 'Tester' |
---|
297 | self.browser.getControl("Search").click() |
---|
298 | self.assertTrue('Anna Tester' in self.browser.contents) |
---|
299 | self.browser.open(self.manage_container_path) |
---|
300 | self.browser.getControl(name="searchtype").value = ['fullname'] |
---|
301 | self.browser.getControl(name="searchterm").value = 'An' |
---|
302 | self.browser.getControl("Search").click() |
---|
303 | self.assertFalse('Anna Tester' in self.browser.contents) |
---|
304 | self.browser.open(self.manage_container_path) |
---|
305 | self.browser.getControl(name="searchtype").value = ['fullname'] |
---|
306 | self.browser.getControl(name="searchterm").value = 'An*' |
---|
307 | self.browser.getControl("Search").click() |
---|
308 | self.assertTrue('Anna Tester' in self.browser.contents) |
---|
309 | self.browser.open(self.manage_container_path) |
---|
310 | self.browser.getControl(name="searchtype").value = ['fullname'] |
---|
311 | self.browser.getControl(name="searchterm").value = 'tester' |
---|
312 | self.browser.getControl("Search").click() |
---|
313 | self.assertTrue('Anna Tester' in self.browser.contents) |
---|
314 | self.browser.open(self.manage_container_path) |
---|
315 | self.browser.getControl(name="searchtype").value = ['fullname'] |
---|
316 | self.browser.getControl(name="searchterm").value = 'Tester Ana' |
---|
317 | self.browser.getControl("Search").click() |
---|
318 | self.assertFalse('Anna Tester' in self.browser.contents) |
---|
319 | self.browser.open(self.manage_container_path) |
---|
320 | self.browser.getControl(name="searchtype").value = ['fullname'] |
---|
321 | self.browser.getControl(name="searchterm").value = 'Tester Anna' |
---|
322 | self.browser.getControl("Search").click() |
---|
323 | self.assertTrue('Anna Tester' in self.browser.contents) |
---|
324 | # The old searchterm will be used again |
---|
325 | self.browser.getControl("Search").click() |
---|
326 | self.assertTrue('Anna Tester' in self.browser.contents) |
---|
327 | |
---|
328 | ctrl = self.browser.getControl(name='entries') |
---|
329 | ctrl.getControl(value=self.student_id).selected = True |
---|
330 | self.browser.getControl("Remove selected", index=0).click() |
---|
331 | self.assertTrue('Successfully removed' in self.browser.contents) |
---|
332 | self.browser.getControl(name="searchtype").value = ['student_id'] |
---|
333 | self.browser.getControl(name="searchterm").value = self.student_id |
---|
334 | self.browser.getControl("Search").click() |
---|
335 | self.assertTrue('No student found' in self.browser.contents) |
---|
336 | |
---|
337 | self.browser.open(self.container_path) |
---|
338 | self.browser.getControl(name="searchtype").value = ['student_id'] |
---|
339 | self.browser.getControl(name="searchterm").value = self.student_id |
---|
340 | self.browser.getControl("Search").click() |
---|
341 | self.assertTrue('No student found' in self.browser.contents) |
---|
342 | return |
---|
343 | |
---|
344 | class StudentUITests(StudentsFullSetup): |
---|
345 | # Tests for Student class views and pages |
---|
346 | |
---|
347 | layer = FunctionalLayer |
---|
348 | |
---|
349 | def test_manage_access(self): |
---|
350 | # Managers can access the pages of students |
---|
351 | # and can perform actions |
---|
352 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
353 | self.browser.open(self.student_path) |
---|
354 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
355 | self.assertEqual(self.browser.url, self.student_path) |
---|
356 | self.browser.getLink("Manage").click() |
---|
357 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
358 | self.assertEqual(self.browser.url, self.manage_student_path) |
---|
359 | # Managers can edit base data and fire transitions |
---|
360 | self.browser.getControl(name="transition").value = ['admit'] |
---|
361 | self.browser.getControl(name="form.firstname").value = 'John' |
---|
362 | self.browser.getControl(name="form.lastname").value = 'Tester' |
---|
363 | self.browser.getControl(name="form.reg_number").value = '345' |
---|
364 | self.browser.getControl(name="password").value = 'secret' |
---|
365 | self.browser.getControl(name="control_password").value = 'secret' |
---|
366 | self.browser.getControl("Save").click() |
---|
367 | self.assertMatches('...Form has been saved...', |
---|
368 | self.browser.contents) |
---|
369 | self.browser.open(self.student_path) |
---|
370 | self.browser.getLink("Clearance Data").click() |
---|
371 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
372 | self.assertEqual(self.browser.url, self.clearance_student_path) |
---|
373 | self.browser.getLink("Manage").click() |
---|
374 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
375 | self.assertEqual(self.browser.url, self.edit_clearance_student_path) |
---|
376 | self.browser.getControl(name="form.date_of_birth").value = '09/10/1961' |
---|
377 | self.browser.getControl("Save").click() |
---|
378 | self.assertMatches('...Form has been saved...', |
---|
379 | self.browser.contents) |
---|
380 | |
---|
381 | self.browser.open(self.student_path) |
---|
382 | self.browser.getLink("Personal Data").click() |
---|
383 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
384 | self.assertEqual(self.browser.url, self.personal_student_path) |
---|
385 | self.browser.getLink("Manage").click() |
---|
386 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
387 | self.assertEqual(self.browser.url, self.edit_personal_student_path) |
---|
388 | self.browser.getControl("Save").click() |
---|
389 | self.assertMatches('...Form has been saved...', |
---|
390 | self.browser.contents) |
---|
391 | |
---|
392 | # Managers can browse all subobjects |
---|
393 | self.browser.open(self.student_path) |
---|
394 | self.browser.getLink("Payments").click() |
---|
395 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
396 | self.assertEqual(self.browser.url, self.payments_student_path) |
---|
397 | self.browser.open(self.student_path) |
---|
398 | self.browser.getLink("Accommodation").click() |
---|
399 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
400 | self.assertEqual(self.browser.url, self.acco_student_path) |
---|
401 | self.browser.open(self.student_path) |
---|
402 | self.browser.getLink("History").click() |
---|
403 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
404 | self.assertEqual(self.browser.url, self.history_student_path) |
---|
405 | self.assertMatches('...Student admitted by Manager...', |
---|
406 | self.browser.contents) |
---|
407 | # Only the Application Slip does not exist |
---|
408 | self.assertFalse('Application Slip' in self.browser.contents) |
---|
409 | return |
---|
410 | |
---|
411 | def test_manage_contact_student(self): |
---|
412 | # Managers can contact student |
---|
413 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
414 | self.browser.open(self.student_path) |
---|
415 | self.browser.getLink("Send email").click() |
---|
416 | self.browser.getControl(name="form.subject").value = 'Important subject' |
---|
417 | self.browser.getControl(name="form.body").value = 'Hello!' |
---|
418 | self.browser.getControl("Send message now").click() |
---|
419 | self.assertTrue('Your message has been sent' in self.browser.contents) |
---|
420 | return |
---|
421 | |
---|
422 | def test_manage_remove_department(self): |
---|
423 | # Lazy student is studying CERT1 |
---|
424 | lazystudent = Student() |
---|
425 | lazystudent.firstname = u'Lazy' |
---|
426 | lazystudent.lastname = u'Student' |
---|
427 | self.app['students'].addStudent(lazystudent) |
---|
428 | student_id = lazystudent.student_id |
---|
429 | student_path = self.container_path + '/' + student_id |
---|
430 | lazystudent['studycourse'].certificate = self.certificate |
---|
431 | notify(grok.ObjectModifiedEvent(lazystudent)) |
---|
432 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
433 | self.browser.open(student_path + '/studycourse') |
---|
434 | self.assertTrue('CERT1' in self.browser.contents) |
---|
435 | # After some years the department is removed |
---|
436 | del self.app['faculties']['fac1']['dep1'] |
---|
437 | # So CERT1 does no longer exist and lazy student's |
---|
438 | # certificate reference is removed too |
---|
439 | self.browser.open(student_path + '/studycourse') |
---|
440 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
441 | self.assertEqual(self.browser.url, student_path + '/studycourse') |
---|
442 | self.assertFalse('CERT1' in self.browser.contents) |
---|
443 | self.assertMatches('...<div class="widget">Nothing</div>...', |
---|
444 | self.browser.contents) |
---|
445 | |
---|
446 | def test_manage_upload_file(self): |
---|
447 | # Managers can upload a file via the StudentClearanceManageFormPage |
---|
448 | # The image is stored even if form has errors |
---|
449 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
450 | self.browser.open(self.edit_clearance_student_path) |
---|
451 | # No birth certificate has been uploaded yet |
---|
452 | # Browsing the link shows a placerholder image |
---|
453 | self.browser.open('birth_certificate') |
---|
454 | self.assertEqual( |
---|
455 | self.browser.headers['content-type'], 'image/jpeg') |
---|
456 | self.assertEqual(len(self.browser.contents), PH_LEN) |
---|
457 | # Create a pseudo image file and select it to be uploaded in form |
---|
458 | # as birth certificate |
---|
459 | self.browser.open(self.edit_clearance_student_path) |
---|
460 | pseudo_image = StringIO('I pretend to be a graphics file') |
---|
461 | ctrl = self.browser.getControl(name='birthcertificateupload') |
---|
462 | file_ctrl = ctrl.mech_control |
---|
463 | file_ctrl.add_file(pseudo_image, filename='my_birth_certificate.jpg') |
---|
464 | # The Save action does not upload files |
---|
465 | self.browser.getControl("Save").click() # submit form |
---|
466 | self.assertFalse( |
---|
467 | '<a target="image" href="birth_certificate">' |
---|
468 | in self.browser.contents) |
---|
469 | # ... but the correct upload submit button does |
---|
470 | pseudo_image = StringIO('I pretend to be a graphics file') |
---|
471 | ctrl = self.browser.getControl(name='birthcertificateupload') |
---|
472 | file_ctrl = ctrl.mech_control |
---|
473 | file_ctrl.add_file(pseudo_image, filename='my_birth_certificate.jpg') |
---|
474 | self.browser.getControl( |
---|
475 | name='upload_birthcertificateupload').click() |
---|
476 | # There is a correct <img> link included |
---|
477 | self.assertTrue( |
---|
478 | '<a target="image" href="birth_certificate">' |
---|
479 | in self.browser.contents) |
---|
480 | |
---|
481 | # Browsing the link shows a real image |
---|
482 | self.browser.open('birth_certificate') |
---|
483 | self.assertEqual( |
---|
484 | self.browser.headers['content-type'], 'image/jpeg') |
---|
485 | self.assertEqual(len(self.browser.contents), 31) |
---|
486 | # Reuploading a file which is bigger than 150k will raise an error |
---|
487 | self.browser.open(self.edit_clearance_student_path) |
---|
488 | photo_content = 'A' * 1024 * 151 # A string of 21 KB size |
---|
489 | pseudo_image = StringIO(photo_content) |
---|
490 | ctrl = self.browser.getControl(name='birthcertificateupload') |
---|
491 | file_ctrl = ctrl.mech_control |
---|
492 | file_ctrl.add_file(pseudo_image, filename='my_birth_certificate.jpg') |
---|
493 | self.browser.getControl( |
---|
494 | name='upload_birthcertificateupload').click() |
---|
495 | self.assertTrue( |
---|
496 | 'Uploaded file is too big' in self.browser.contents) |
---|
497 | # File names must meet several conditions |
---|
498 | pseudo_image = StringIO('I pretend to be a graphics file') |
---|
499 | ctrl = self.browser.getControl(name='birthcertificateupload') |
---|
500 | file_ctrl = ctrl.mech_control |
---|
501 | file_ctrl.add_file(pseudo_image, filename='my.photo.jpg') |
---|
502 | self.browser.getControl( |
---|
503 | name='upload_birthcertificateupload').click() |
---|
504 | self.assertTrue('File name contains more than one dot' |
---|
505 | in self.browser.contents) |
---|
506 | ctrl = self.browser.getControl(name='birthcertificateupload') |
---|
507 | file_ctrl = ctrl.mech_control |
---|
508 | file_ctrl.add_file(pseudo_image, filename='my_birth_certificate') |
---|
509 | self.browser.getControl( |
---|
510 | name='upload_birthcertificateupload').click() |
---|
511 | self.assertTrue('File name has no extension' in self.browser.contents) |
---|
512 | ctrl = self.browser.getControl(name='birthcertificateupload') |
---|
513 | file_ctrl = ctrl.mech_control |
---|
514 | file_ctrl.add_file(pseudo_image, filename='my_birth_certificate.bmp') |
---|
515 | self.browser.getControl( |
---|
516 | name='upload_birthcertificateupload').click() |
---|
517 | self.assertTrue('Only the following extension are allowed' |
---|
518 | in self.browser.contents) |
---|
519 | # Managers can delete files |
---|
520 | self.browser.getControl(name='delete_birthcertificateupload').click() |
---|
521 | self.assertTrue( |
---|
522 | 'birth_certificate deleted' in self.browser.contents) |
---|
523 | # Managers can add and delete second file |
---|
524 | self.browser.open(self.edit_clearance_student_path) |
---|
525 | pseudo_image = StringIO('I pretend to be a graphics file') |
---|
526 | ctrl = self.browser.getControl(name='birthcertificateupload') |
---|
527 | file_ctrl = ctrl.mech_control |
---|
528 | file_ctrl.add_file(pseudo_image, filename='my_acceptance_letter.jpg') |
---|
529 | self.browser.getControl( |
---|
530 | name='upload_acceptanceletterupload').click() |
---|
531 | self.assertFalse( |
---|
532 | '<a target="image" href="acceptance_letter">' |
---|
533 | in self.browser.contents) |
---|
534 | ctrl = self.browser.getControl(name='acceptanceletterupload') |
---|
535 | file_ctrl = ctrl.mech_control |
---|
536 | file_ctrl.add_file(pseudo_image, filename='my_acceptance_letter.jpg') |
---|
537 | self.browser.getControl( |
---|
538 | name='upload_acceptanceletterupload').click() |
---|
539 | self.assertTrue( |
---|
540 | '<a target="image" href="acceptance_letter">' |
---|
541 | in self.browser.contents) |
---|
542 | self.browser.getControl( |
---|
543 | name='delete_acceptanceletterupload').click() |
---|
544 | self.assertTrue( |
---|
545 | 'acceptance_letter deleted' |
---|
546 | in self.browser.contents) |
---|
547 | # Managers can upload a file via the StudentBaseManageFormPage |
---|
548 | self.browser.open(self.manage_student_path) |
---|
549 | pseudo_image = StringIO('I pretend to be a graphics file') |
---|
550 | ctrl = self.browser.getControl(name='passportuploadmanage') |
---|
551 | file_ctrl = ctrl.mech_control |
---|
552 | file_ctrl.add_file(pseudo_image, filename='my_photo.bmp') |
---|
553 | self.browser.getControl( |
---|
554 | name='upload_passportuploadmanage').click() |
---|
555 | self.assertTrue('jpg file extension expected' |
---|
556 | in self.browser.contents) |
---|
557 | ctrl = self.browser.getControl(name='passportuploadmanage') |
---|
558 | file_ctrl = ctrl.mech_control |
---|
559 | file_ctrl.add_file(pseudo_image, filename='my_photo.jpg') |
---|
560 | self.browser.getControl( |
---|
561 | name='upload_passportuploadmanage').click() |
---|
562 | self.assertTrue( |
---|
563 | '<img align="middle" height="125px" src="passport.jpg" />' |
---|
564 | in self.browser.contents) |
---|
565 | # The clearance slip can't be opened because it requires a proper |
---|
566 | # passport jpg file. |
---|
567 | self.browser.open(self.student_path + '/clearance.pdf') |
---|
568 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
569 | self.assertTrue('Error in image file' in self.browser.contents) |
---|
570 | # We remove the passport file again |
---|
571 | self.browser.open(self.manage_student_path) |
---|
572 | self.browser.getControl('Delete').click() |
---|
573 | self.browser.open(self.student_path + '/clearance.pdf') |
---|
574 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
575 | self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf') |
---|
576 | |
---|
577 | def test_manage_course_lists(self): |
---|
578 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
579 | self.browser.open(self.student_path) |
---|
580 | self.browser.getLink("Study Course").click() |
---|
581 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
582 | self.assertEqual(self.browser.url, self.studycourse_student_path) |
---|
583 | self.browser.getLink("Manage").click() |
---|
584 | self.assertTrue('Manage study course' in self.browser.contents) |
---|
585 | # Before we can select a level, the certificate must |
---|
586 | # be selected and saved |
---|
587 | self.browser.getControl(name="form.certificate").value = ['CERT1'] |
---|
588 | self.browser.getControl(name="form.current_session").value = ['2004'] |
---|
589 | self.browser.getControl(name="form.current_verdict").value = ['A'] |
---|
590 | self.browser.getControl("Save").click() |
---|
591 | # Now we can save also the current level which depends on start and end |
---|
592 | # level of the certificate |
---|
593 | self.browser.getControl(name="form.current_level").value = ['100'] |
---|
594 | self.browser.getControl("Save").click() |
---|
595 | # Managers can add and remove any study level (course list) |
---|
596 | self.browser.getControl(name="addlevel").value = ['100'] |
---|
597 | self.browser.getControl("Add study level").click() |
---|
598 | self.assertMatches('...<span>100</span>...', self.browser.contents) |
---|
599 | self.browser.getControl("Add study level").click() |
---|
600 | self.assertMatches('...This level exists...', self.browser.contents) |
---|
601 | self.browser.getControl("Remove selected").click() |
---|
602 | self.assertMatches( |
---|
603 | '...No study level selected...', self.browser.contents) |
---|
604 | self.browser.getControl(name="val_id").value = ['100'] |
---|
605 | self.browser.getControl("Remove selected").click() |
---|
606 | self.assertMatches('...Successfully removed...', self.browser.contents) |
---|
607 | # Add level again |
---|
608 | self.browser.getControl(name="addlevel").value = ['100'] |
---|
609 | self.browser.getControl("Add study level").click() |
---|
610 | self.browser.getControl(name="addlevel").value = ['100'] |
---|
611 | |
---|
612 | # Managers can view and manage course lists |
---|
613 | self.browser.getLink("100").click() |
---|
614 | self.assertMatches( |
---|
615 | '...: Study Level 100 (Year 1)...', self.browser.contents) |
---|
616 | self.browser.getLink("Manage").click() |
---|
617 | self.browser.getControl(name="form.level_session").value = ['2002'] |
---|
618 | self.browser.getControl("Save").click() |
---|
619 | self.browser.getControl("Remove selected").click() |
---|
620 | self.assertMatches('...No ticket selected...', self.browser.contents) |
---|
621 | ctrl = self.browser.getControl(name='val_id') |
---|
622 | ctrl.getControl(value='COURSE1').selected = True |
---|
623 | self.browser.getControl("Remove selected", index=0).click() |
---|
624 | self.assertTrue('Successfully removed' in self.browser.contents) |
---|
625 | self.browser.getControl("Add course ticket").click() |
---|
626 | self.browser.getControl(name="form.course").value = ['COURSE1'] |
---|
627 | self.browser.getControl("Add course ticket").click() |
---|
628 | self.assertTrue('Successfully added' in self.browser.contents) |
---|
629 | self.browser.getControl("Add course ticket").click() |
---|
630 | self.browser.getControl(name="form.course").value = ['COURSE1'] |
---|
631 | self.browser.getControl("Add course ticket").click() |
---|
632 | self.assertTrue('The ticket exists' in self.browser.contents) |
---|
633 | self.browser.getControl("Cancel").click() |
---|
634 | self.browser.getLink("COURSE1").click() |
---|
635 | self.browser.getLink("Manage").click() |
---|
636 | self.browser.getControl(name="form.score").value = '10' |
---|
637 | self.browser.getControl("Save").click() |
---|
638 | self.assertTrue('Form has been saved' in self.browser.contents) |
---|
639 | return |
---|
640 | |
---|
641 | def test_manage_workflow(self): |
---|
642 | # Managers can pass through the whole workflow |
---|
643 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
644 | student = self.app['students'][self.student_id] |
---|
645 | self.browser.open(self.manage_student_path) |
---|
646 | self.assertTrue(student.clearance_locked) |
---|
647 | self.browser.getControl(name="transition").value = ['admit'] |
---|
648 | self.browser.getControl("Save").click() |
---|
649 | self.assertTrue(student.clearance_locked) |
---|
650 | self.browser.getControl(name="transition").value = ['start_clearance'] |
---|
651 | self.browser.getControl("Save").click() |
---|
652 | self.assertFalse(student.clearance_locked) |
---|
653 | self.browser.getControl(name="transition").value = ['request_clearance'] |
---|
654 | self.browser.getControl("Save").click() |
---|
655 | self.assertTrue(student.clearance_locked) |
---|
656 | self.browser.getControl(name="transition").value = ['clear'] |
---|
657 | self.browser.getControl("Save").click() |
---|
658 | self.browser.getControl( |
---|
659 | name="transition").value = ['pay_first_school_fee'] |
---|
660 | self.browser.getControl("Save").click() |
---|
661 | self.browser.getControl(name="transition").value = ['reset6'] |
---|
662 | self.browser.getControl("Save").click() |
---|
663 | # In state returning the pay_school_fee transition triggers some |
---|
664 | # changes of attributes |
---|
665 | self.browser.getControl(name="transition").value = ['pay_school_fee'] |
---|
666 | self.browser.getControl("Save").click() |
---|
667 | self.assertEqual(student['studycourse'].current_session, 2005) # +1 |
---|
668 | self.assertEqual(student['studycourse'].current_level, 200) # +100 |
---|
669 | self.assertEqual(student['studycourse'].current_verdict, '0') # 0 = not set |
---|
670 | self.assertEqual(student['studycourse'].previous_verdict, 'A') |
---|
671 | self.browser.getControl(name="transition").value = ['register_courses'] |
---|
672 | self.browser.getControl("Save").click() |
---|
673 | self.browser.getControl(name="transition").value = ['validate_courses'] |
---|
674 | self.browser.getControl("Save").click() |
---|
675 | self.browser.getControl(name="transition").value = ['return'] |
---|
676 | self.browser.getControl("Save").click() |
---|
677 | return |
---|
678 | |
---|
679 | def test_manage_import(self): |
---|
680 | # Managers can import student data files |
---|
681 | datacenter_path = 'http://localhost/app/datacenter' |
---|
682 | # Prepare a csv file for students |
---|
683 | open('students.csv', 'wb').write( |
---|
684 | """firstname,lastname,reg_number,date_of_birth,matric_number,email,phone |
---|
685 | Aaren,Pieri,1,1990-01-02,100000,aa@aa.ng,1234 |
---|
686 | Claus,Finau,2,1990-01-03,100001,aa@aa.ng,1234 |
---|
687 | Brit,Berson,3,1990-01-04,100001,aa@aa.ng,1234 |
---|
688 | """) |
---|
689 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
690 | self.browser.open(datacenter_path) |
---|
691 | self.browser.getLink('Upload CSV file').click() |
---|
692 | filecontents = StringIO(open('students.csv', 'rb').read()) |
---|
693 | filewidget = self.browser.getControl(name='uploadfile:file') |
---|
694 | filewidget.add_file(filecontents, 'text/plain', 'students.csv') |
---|
695 | self.browser.getControl(name='SUBMIT').click() |
---|
696 | self.browser.getLink('Batch processing').click() |
---|
697 | button = lookup_submit_value( |
---|
698 | 'select', 'students_zope.mgr.csv', self.browser) |
---|
699 | button.click() |
---|
700 | importerselect = self.browser.getControl(name='importer') |
---|
701 | modeselect = self.browser.getControl(name='mode') |
---|
702 | importerselect.getControl('Student Importer').selected = True |
---|
703 | modeselect.getControl(value='create').selected = True |
---|
704 | self.browser.getControl('Proceed to step 3...').click() |
---|
705 | self.assertTrue('Header fields OK' in self.browser.contents) |
---|
706 | self.browser.getControl('Perform import...').click() |
---|
707 | self.assertTrue('Processing of 1 rows failed' in self.browser.contents) |
---|
708 | self.assertTrue('Successfully processed 2 rows' in self.browser.contents) |
---|
709 | self.assertTrue('Batch processing finished' in self.browser.contents) |
---|
710 | open('studycourses.csv', 'wb').write( |
---|
711 | """reg_number,matric_number,certificate,current_session,current_level |
---|
712 | 1,,CERT1,2008,100 |
---|
713 | ,100001,CERT1,2008,100 |
---|
714 | ,100002,CERT1,2008,100 |
---|
715 | """) |
---|
716 | self.browser.open(datacenter_path) |
---|
717 | self.browser.getLink('Upload CSV file').click() |
---|
718 | filecontents = StringIO(open('studycourses.csv', 'rb').read()) |
---|
719 | filewidget = self.browser.getControl(name='uploadfile:file') |
---|
720 | filewidget.add_file(filecontents, 'text/plain', 'studycourses.csv') |
---|
721 | self.browser.getControl(name='SUBMIT').click() |
---|
722 | self.browser.getLink('Batch processing').click() |
---|
723 | button = lookup_submit_value( |
---|
724 | 'select', 'studycourses_zope.mgr.csv', self.browser) |
---|
725 | button.click() |
---|
726 | importerselect = self.browser.getControl(name='importer') |
---|
727 | modeselect = self.browser.getControl(name='mode') |
---|
728 | importerselect.getControl( |
---|
729 | 'StudentStudyCourse Importer (update only)').selected = True |
---|
730 | modeselect.getControl(value='create').selected = True |
---|
731 | self.browser.getControl('Proceed to step 3...').click() |
---|
732 | self.assertTrue('Update mode only' in self.browser.contents) |
---|
733 | self.browser.getControl('Proceed to step 3...').click() |
---|
734 | self.assertTrue('Header fields OK' in self.browser.contents) |
---|
735 | self.browser.getControl('Perform import...').click() |
---|
736 | self.assertTrue('Processing of 1 rows failed' in self.browser.contents) |
---|
737 | self.assertTrue('Successfully processed 2 rows' |
---|
738 | in self.browser.contents) |
---|
739 | # The students are properly indexed and we can |
---|
740 | # thus find a student in the department |
---|
741 | self.browser.open(self.container_path) |
---|
742 | self.browser.getControl(name="searchtype").value = ['depcode'] |
---|
743 | self.browser.getControl(name="searchterm").value = 'dep1' |
---|
744 | self.browser.getControl("Search").click() |
---|
745 | self.assertTrue('Aaren Pieri' in self.browser.contents) |
---|
746 | return |
---|
747 | |
---|
748 | def test_handle_clearance_by_co(self): |
---|
749 | # Create clearance officer |
---|
750 | self.app['users'].addUser('mrclear', 'mrclearsecret') |
---|
751 | self.app['users']['mrclear'].email = 'mrclear@foo.ng' |
---|
752 | self.app['users']['mrclear'].title = 'Carlo Pitter' |
---|
753 | # Clearance officers need not necessarily to get |
---|
754 | # the StudentsOfficer site role |
---|
755 | #prmglobal = IPrincipalRoleManager(self.app) |
---|
756 | #prmglobal.assignRoleToPrincipal('waeup.StudentsOfficer', 'mrclear') |
---|
757 | # Assign local ClearanceOfficer role |
---|
758 | department = self.app['faculties']['fac1']['dep1'] |
---|
759 | prmlocal = IPrincipalRoleManager(department) |
---|
760 | prmlocal.assignRoleToPrincipal('waeup.local.ClearanceOfficer', 'mrclear') |
---|
761 | IWorkflowInfo(self.student).fireTransition('admit') |
---|
762 | IWorkflowInfo(self.student).fireTransition('start_clearance') |
---|
763 | # Login as clearance officer |
---|
764 | self.browser.open(self.login_path) |
---|
765 | self.browser.getControl(name="form.login").value = 'mrclear' |
---|
766 | self.browser.getControl(name="form.password").value = 'mrclearsecret' |
---|
767 | self.browser.getControl("Login").click() |
---|
768 | self.assertMatches('...You logged in...', self.browser.contents) |
---|
769 | # CO can see his roles |
---|
770 | self.browser.getLink("My Roles").click() |
---|
771 | self.assertMatches( |
---|
772 | '...<div>Academics Officer (view only)</div>...', |
---|
773 | self.browser.contents) |
---|
774 | #self.assertMatches( |
---|
775 | # '...<div>Students Officer (view only)</div>...', |
---|
776 | # self.browser.contents) |
---|
777 | # But not his local role ... |
---|
778 | self.assertFalse('Clearance Officer' in self.browser.contents) |
---|
779 | # ... because we forgot to notify the department that the local role |
---|
780 | # has changed |
---|
781 | notify(LocalRoleSetEvent( |
---|
782 | department, 'waeup.local.ClearanceOfficer', 'mrclear', granted=True)) |
---|
783 | self.browser.open('http://localhost/app/users/mrclear/my_roles') |
---|
784 | self.assertTrue('Clearance Officer' in self.browser.contents) |
---|
785 | self.assertMatches( |
---|
786 | '...<a href="http://localhost/app/faculties/fac1/dep1">...', |
---|
787 | self.browser.contents) |
---|
788 | # CO can view the student ... |
---|
789 | self.browser.open(self.clearance_student_path) |
---|
790 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
791 | self.assertEqual(self.browser.url, self.clearance_student_path) |
---|
792 | # ... but not other students |
---|
793 | other_student = Student() |
---|
794 | other_student.firstname = u'Dep2' |
---|
795 | other_student.lastname = u'Student' |
---|
796 | self.app['students'].addStudent(other_student) |
---|
797 | other_student_path = ( |
---|
798 | 'http://localhost/app/students/%s' % other_student.student_id) |
---|
799 | self.assertRaises( |
---|
800 | Unauthorized, self.browser.open, other_student_path) |
---|
801 | # Only in state clearance requested the CO does see the 'Clear' button |
---|
802 | self.browser.open(self.clearance_student_path) |
---|
803 | self.assertFalse('Clear student' in self.browser.contents) |
---|
804 | IWorkflowInfo(self.student).fireTransition('request_clearance') |
---|
805 | self.browser.open(self.clearance_student_path) |
---|
806 | self.assertTrue('Clear student' in self.browser.contents) |
---|
807 | self.browser.getLink("Clear student").click() |
---|
808 | self.assertTrue('Student has been cleared' in self.browser.contents) |
---|
809 | self.assertTrue('cleared' in self.browser.contents) |
---|
810 | self.browser.getLink("Reject clearance").click() |
---|
811 | self.assertTrue('Clearance has been annulled' in self.browser.contents) |
---|
812 | urlmessage = 'Clearance+has+been+annulled' |
---|
813 | # CO does now see the contact form |
---|
814 | self.assertEqual(self.browser.url, self.student_path + |
---|
815 | '/contactstudent?subject=%s' % urlmessage) |
---|
816 | self.assertTrue('clearance started' in self.browser.contents) |
---|
817 | IWorkflowInfo(self.student).fireTransition('request_clearance') |
---|
818 | self.browser.open(self.clearance_student_path) |
---|
819 | self.browser.getLink("Reject clearance").click() |
---|
820 | self.assertTrue('Clearance request has been rejected' |
---|
821 | in self.browser.contents) |
---|
822 | self.assertTrue('clearance started' in self.browser.contents) |
---|
823 | # CO does now also see the contact form and can send a message |
---|
824 | self.browser.getControl(name="form.subject").value = 'Important subject' |
---|
825 | self.browser.getControl(name="form.body").value = 'Clearance rejected' |
---|
826 | self.browser.getControl("Send message now").click() |
---|
827 | self.assertTrue('Your message has been sent' in self.browser.contents) |
---|
828 | # The CO can't clear students if not in state |
---|
829 | # clearance requested |
---|
830 | self.browser.open(self.student_path + '/clear') |
---|
831 | self.assertTrue('Student is in the wrong state' |
---|
832 | in self.browser.contents) |
---|
833 | # The CO can go to his department throug the my_roles page |
---|
834 | self.browser.open('http://localhost/app/users/mrclear/my_roles') |
---|
835 | self.browser.getLink("http://localhost/app/faculties/fac1/dep1").click() |
---|
836 | # and view the list of students |
---|
837 | self.browser.getLink("Show students").click() |
---|
838 | self.assertTrue(self.student_id in self.browser.contents) |
---|
839 | |
---|
840 | def test_handle_courses_by_ca(self): |
---|
841 | # Create course adviser |
---|
842 | self.app['users'].addUser('mrsadvise', 'mrsadvisesecret') |
---|
843 | self.app['users']['mrsadvise'].email = 'mradvise@foo.ng' |
---|
844 | self.app['users']['mrsadvise'].title = 'Helen Procter' |
---|
845 | # Assign local CourseAdviser100 role for a certificate |
---|
846 | cert = self.app['faculties']['fac1']['dep1'].certificates['CERT1'] |
---|
847 | prmlocal = IPrincipalRoleManager(cert) |
---|
848 | prmlocal.assignRoleToPrincipal('waeup.local.CourseAdviser100', 'mrsadvise') |
---|
849 | IWorkflowInfo(self.student).fireTransition('admit') |
---|
850 | IWorkflowInfo(self.student).fireTransition('start_clearance') |
---|
851 | IWorkflowInfo(self.student).fireTransition('request_clearance') |
---|
852 | IWorkflowInfo(self.student).fireTransition('clear') |
---|
853 | IWorkflowInfo(self.student).fireTransition('pay_first_school_fee') |
---|
854 | # Login as course adviser |
---|
855 | self.browser.open(self.login_path) |
---|
856 | self.browser.getControl(name="form.login").value = 'mrsadvise' |
---|
857 | self.browser.getControl(name="form.password").value = 'mrsadvisesecret' |
---|
858 | self.browser.getControl("Login").click() |
---|
859 | self.assertMatches('...You logged in...', self.browser.contents) |
---|
860 | # CO can see his roles |
---|
861 | self.browser.getLink("My Roles").click() |
---|
862 | self.assertMatches( |
---|
863 | '...<div>Academics Officer (view only)</div>...', |
---|
864 | self.browser.contents) |
---|
865 | # But not his local role ... |
---|
866 | self.assertFalse('Course Adviser' in self.browser.contents) |
---|
867 | # ... because we forgot to notify the certificate that the local role |
---|
868 | # has changed |
---|
869 | notify(LocalRoleSetEvent( |
---|
870 | cert, 'waeup.local.CourseAdviser100', 'mrsadvise', granted=True)) |
---|
871 | self.browser.open('http://localhost/app/users/mrsadvise/my_roles') |
---|
872 | self.assertTrue('Course Adviser 100L' in self.browser.contents) |
---|
873 | self.assertMatches( |
---|
874 | '...<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">...', |
---|
875 | self.browser.contents) |
---|
876 | # CA can view the student ... |
---|
877 | self.browser.open(self.student_path) |
---|
878 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
879 | self.assertEqual(self.browser.url, self.student_path) |
---|
880 | # ... but not other students |
---|
881 | other_student = Student() |
---|
882 | other_student.firstname = u'Dep2' |
---|
883 | other_student.lastname = u'Student' |
---|
884 | self.app['students'].addStudent(other_student) |
---|
885 | other_student_path = ( |
---|
886 | 'http://localhost/app/students/%s' % other_student.student_id) |
---|
887 | self.assertRaises( |
---|
888 | Unauthorized, self.browser.open, other_student_path) |
---|
889 | # We add study level 110 to the student's studycourse |
---|
890 | studylevel = StudentStudyLevel() |
---|
891 | studylevel.level = 110 |
---|
892 | self.student['studycourse'].addStudentStudyLevel( |
---|
893 | cert,studylevel) |
---|
894 | L110_student_path = self.studycourse_student_path + '/110' |
---|
895 | # Only in state courses registered and only if the current level |
---|
896 | # corresponds with the name of the study level object |
---|
897 | # the 100L CA does see the 'Validate' button |
---|
898 | self.browser.open(L110_student_path) |
---|
899 | self.assertFalse('Validate' in self.browser.contents) |
---|
900 | IWorkflowInfo(self.student).fireTransition('register_courses') |
---|
901 | self.browser.open(L110_student_path) |
---|
902 | self.assertFalse('Validate' in self.browser.contents) |
---|
903 | self.student['studycourse'].current_level = 110 |
---|
904 | self.browser.open(L110_student_path) |
---|
905 | self.assertTrue('Validate' in self.browser.contents) |
---|
906 | # ... but a 100L CA does not see the button on other levels |
---|
907 | studylevel2 = StudentStudyLevel() |
---|
908 | studylevel2.level = 200 |
---|
909 | self.student['studycourse'].addStudentStudyLevel( |
---|
910 | cert,studylevel2) |
---|
911 | L200_student_path = self.studycourse_student_path + '/200' |
---|
912 | self.browser.open(L200_student_path) |
---|
913 | self.assertFalse('Validate' in self.browser.contents) |
---|
914 | self.browser.open(L110_student_path) |
---|
915 | self.browser.getLink("Validate courses").click() |
---|
916 | self.assertTrue('Course list has been validated' in self.browser.contents) |
---|
917 | self.assertTrue('courses validated' in self.browser.contents) |
---|
918 | self.browser.getLink("Reject courses").click() |
---|
919 | self.assertTrue('Course list request has been annulled' |
---|
920 | in self.browser.contents) |
---|
921 | urlmessage = 'Course+list+request+has+been+annulled' |
---|
922 | self.assertEqual(self.browser.url, self.student_path + |
---|
923 | '/contactstudent?subject=%s' % urlmessage) |
---|
924 | self.assertTrue('school fee paid' in self.browser.contents) |
---|
925 | IWorkflowInfo(self.student).fireTransition('register_courses') |
---|
926 | self.browser.open(L110_student_path) |
---|
927 | self.browser.getLink("Reject courses").click() |
---|
928 | self.assertTrue('Course list request has been rejected' |
---|
929 | in self.browser.contents) |
---|
930 | self.assertTrue('school fee paid' in self.browser.contents) |
---|
931 | # CA does now see the contact form and can send a message |
---|
932 | self.browser.getControl(name="form.subject").value = 'Important subject' |
---|
933 | self.browser.getControl(name="form.body").value = 'Course list rejected' |
---|
934 | self.browser.getControl("Send message now").click() |
---|
935 | self.assertTrue('Your message has been sent' in self.browser.contents) |
---|
936 | # The CA can't validate courses if not in state |
---|
937 | # courses registered |
---|
938 | self.browser.open(L110_student_path + '/validate_courses') |
---|
939 | self.assertTrue('Student is in the wrong state' |
---|
940 | in self.browser.contents) |
---|
941 | # The CA can go to his certificate throug the my_roles page |
---|
942 | self.browser.open('http://localhost/app/users/mrsadvise/my_roles') |
---|
943 | self.browser.getLink( |
---|
944 | "http://localhost/app/faculties/fac1/dep1/certificates/CERT1").click() |
---|
945 | # and view the list of students |
---|
946 | self.browser.getLink("Show students").click() |
---|
947 | self.assertTrue(self.student_id in self.browser.contents) |
---|
948 | |
---|
949 | def test_student_change_password(self): |
---|
950 | # Students can change the password |
---|
951 | self.browser.open(self.login_path) |
---|
952 | self.browser.getControl(name="form.login").value = self.student_id |
---|
953 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
954 | self.browser.getControl("Login").click() |
---|
955 | self.assertEqual(self.browser.url, self.student_path) |
---|
956 | self.assertTrue('You logged in' in self.browser.contents) |
---|
957 | # Change password |
---|
958 | self.browser.getLink("Change password").click() |
---|
959 | self.browser.getControl(name="change_password").value = 'pw' |
---|
960 | self.browser.getControl( |
---|
961 | name="change_password_repeat").value = 'pw' |
---|
962 | self.browser.getControl("Save").click() |
---|
963 | self.assertTrue('Password must have at least' in self.browser.contents) |
---|
964 | self.browser.getControl(name="change_password").value = 'new_password' |
---|
965 | self.browser.getControl( |
---|
966 | name="change_password_repeat").value = 'new_passssword' |
---|
967 | self.browser.getControl("Save").click() |
---|
968 | self.assertTrue('Passwords do not match' in self.browser.contents) |
---|
969 | self.browser.getControl(name="change_password").value = 'new_password' |
---|
970 | self.browser.getControl( |
---|
971 | name="change_password_repeat").value = 'new_password' |
---|
972 | self.browser.getControl("Save").click() |
---|
973 | self.assertTrue('Password changed' in self.browser.contents) |
---|
974 | # We are still logged in. Changing the password hasn't thrown us out. |
---|
975 | self.browser.getLink("Base Data").click() |
---|
976 | self.assertEqual(self.browser.url, self.student_path) |
---|
977 | # We can logout |
---|
978 | self.browser.getLink("Logout").click() |
---|
979 | self.assertTrue('You have been logged out' in self.browser.contents) |
---|
980 | self.assertEqual(self.browser.url, 'http://localhost/app') |
---|
981 | # We can login again with the new password |
---|
982 | self.browser.getLink("Login").click() |
---|
983 | self.browser.open(self.login_path) |
---|
984 | self.browser.getControl(name="form.login").value = self.student_id |
---|
985 | self.browser.getControl(name="form.password").value = 'new_password' |
---|
986 | self.browser.getControl("Login").click() |
---|
987 | self.assertEqual(self.browser.url, self.student_path) |
---|
988 | self.assertTrue('You logged in' in self.browser.contents) |
---|
989 | return |
---|
990 | |
---|
991 | def test_setpassword(self): |
---|
992 | # Set password for first-time access |
---|
993 | student = Student() |
---|
994 | student.reg_number = u'123456' |
---|
995 | student.firstname = u'Klaus' |
---|
996 | student.lastname = u'Tester' |
---|
997 | self.app['students'].addStudent(student) |
---|
998 | setpassword_path = 'http://localhost/app/setpassword' |
---|
999 | student_path = 'http://localhost/app/students/%s' % student.student_id |
---|
1000 | self.browser.open(setpassword_path) |
---|
1001 | self.browser.getControl(name="ac_series").value = self.existing_pwdseries |
---|
1002 | self.browser.getControl(name="ac_number").value = self.existing_pwdnumber |
---|
1003 | self.browser.getControl(name="reg_number").value = '223456' |
---|
1004 | self.browser.getControl("Show").click() |
---|
1005 | self.assertMatches('...No student found...', |
---|
1006 | self.browser.contents) |
---|
1007 | self.browser.getControl(name="reg_number").value = '123456' |
---|
1008 | self.browser.getControl(name="ac_number").value = '999999' |
---|
1009 | self.browser.getControl("Show").click() |
---|
1010 | self.assertMatches('...Access code is invalid...', |
---|
1011 | self.browser.contents) |
---|
1012 | self.browser.getControl(name="ac_number").value = self.existing_pwdnumber |
---|
1013 | self.browser.getControl("Show").click() |
---|
1014 | self.assertMatches('...Password has been set. Your Student Id is...', |
---|
1015 | self.browser.contents) |
---|
1016 | self.browser.getControl("Show").click() |
---|
1017 | self.assertMatches( |
---|
1018 | '...Password has already been set. Your Student Id is...', |
---|
1019 | self.browser.contents) |
---|
1020 | existing_pwdpin = self.pwdpins[1] |
---|
1021 | parts = existing_pwdpin.split('-')[1:] |
---|
1022 | existing_pwdseries, existing_pwdnumber = parts |
---|
1023 | self.browser.getControl(name="ac_series").value = existing_pwdseries |
---|
1024 | self.browser.getControl(name="ac_number").value = existing_pwdnumber |
---|
1025 | self.browser.getControl(name="reg_number").value = '123456' |
---|
1026 | self.browser.getControl("Show").click() |
---|
1027 | self.assertMatches( |
---|
1028 | '...You are using the wrong Access Code...', |
---|
1029 | self.browser.contents) |
---|
1030 | # The student can login with the new credentials |
---|
1031 | self.browser.open(self.login_path) |
---|
1032 | self.browser.getControl(name="form.login").value = student.student_id |
---|
1033 | self.browser.getControl( |
---|
1034 | name="form.password").value = self.existing_pwdnumber |
---|
1035 | self.browser.getControl("Login").click() |
---|
1036 | self.assertEqual(self.browser.url, student_path) |
---|
1037 | self.assertTrue('You logged in' in self.browser.contents) |
---|
1038 | return |
---|
1039 | |
---|
1040 | def test_student_access(self): |
---|
1041 | # Students can access their own objects |
---|
1042 | # and can perform actions |
---|
1043 | IWorkflowInfo(self.student).fireTransition('admit') |
---|
1044 | self.browser.open(self.login_path) |
---|
1045 | self.browser.getControl(name="form.login").value = self.student_id |
---|
1046 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
1047 | self.browser.getControl("Login").click() |
---|
1048 | # Student can upload a passport picture |
---|
1049 | self.browser.open(self.student_path + '/change_portrait') |
---|
1050 | ctrl = self.browser.getControl(name='passportuploadedit') |
---|
1051 | file_obj = open( |
---|
1052 | os.path.join(os.path.dirname(__file__), 'test_image.jpg'),'rb') |
---|
1053 | file_ctrl = ctrl.mech_control |
---|
1054 | file_ctrl.add_file(file_obj, filename='my_photo.jpg') |
---|
1055 | self.browser.getControl( |
---|
1056 | name='upload_passportuploadedit').click() |
---|
1057 | self.assertTrue( |
---|
1058 | '<img align="middle" height="125px" src="passport.jpg" />' |
---|
1059 | in self.browser.contents) |
---|
1060 | # Student can view the clearance data |
---|
1061 | self.browser.getLink("Clearance Data").click() |
---|
1062 | # Student can't open clearance edit form before starting clearance |
---|
1063 | self.browser.open(self.student_path + '/cedit') |
---|
1064 | self.assertMatches('...The requested form is locked...', |
---|
1065 | self.browser.contents) |
---|
1066 | self.browser.getLink("Clearance Data").click() |
---|
1067 | self.browser.getLink("Start clearance").click() |
---|
1068 | self.student.email = None |
---|
1069 | # Uups, we forgot to fill the email fields |
---|
1070 | self.browser.getControl("Start clearance").click() |
---|
1071 | self.assertMatches('...Not all required fields filled...', |
---|
1072 | self.browser.contents) |
---|
1073 | self.student.email = 'aa@aa.ng' |
---|
1074 | self.browser.open(self.student_path + '/start_clearance') |
---|
1075 | self.browser.getControl(name="ac_series").value = '3' |
---|
1076 | self.browser.getControl(name="ac_number").value = '4444444' |
---|
1077 | self.browser.getControl("Start clearance now").click() |
---|
1078 | self.assertMatches('...Activation code is invalid...', |
---|
1079 | self.browser.contents) |
---|
1080 | self.browser.getControl(name="ac_series").value = self.existing_clrseries |
---|
1081 | self.browser.getControl(name="ac_number").value = self.existing_clrnumber |
---|
1082 | # Owner is Hans Wurst, AC can't be invalidated |
---|
1083 | self.browser.getControl("Start clearance now").click() |
---|
1084 | self.assertMatches('...You are not the owner of this access code...', |
---|
1085 | self.browser.contents) |
---|
1086 | # Set the correct owner |
---|
1087 | self.existing_clrac.owner = self.student_id |
---|
1088 | self.browser.getControl("Start clearance now").click() |
---|
1089 | self.assertMatches('...Clearance process has been started...', |
---|
1090 | self.browser.contents) |
---|
1091 | self.browser.getControl(name="form.date_of_birth").value = '09/10/1961' |
---|
1092 | self.browser.getControl("Save", index=0).click() |
---|
1093 | # Student can view the clearance data |
---|
1094 | self.browser.getLink("Clearance Data").click() |
---|
1095 | # and go back to the edit form |
---|
1096 | self.browser.getLink("Edit").click() |
---|
1097 | self.browser.getControl("Save and request clearance").click() |
---|
1098 | |
---|
1099 | self.browser.getControl(name="ac_series").value = self.existing_clrseries |
---|
1100 | self.browser.getControl(name="ac_number").value = self.existing_clrnumber |
---|
1101 | self.browser.getControl("Request clearance now").click() |
---|
1102 | self.assertMatches('...Clearance has been requested...', |
---|
1103 | self.browser.contents) |
---|
1104 | # Student can't reopen clearance form after requesting clearance |
---|
1105 | self.browser.open(self.student_path + '/cedit') |
---|
1106 | self.assertMatches('...The requested form is locked...', |
---|
1107 | self.browser.contents) |
---|
1108 | # Student can't add study level if not in state 'school fee paid' |
---|
1109 | self.browser.open(self.student_path + '/studycourse/add') |
---|
1110 | self.assertMatches('...The requested form is locked...', |
---|
1111 | self.browser.contents) |
---|
1112 | # ... and must be transferred first |
---|
1113 | IWorkflowInfo(self.student).fireTransition('clear') |
---|
1114 | IWorkflowInfo(self.student).fireTransition('pay_first_school_fee') |
---|
1115 | # Now students can add the current study level |
---|
1116 | self.browser.getLink("Study Course").click() |
---|
1117 | self.browser.getLink("Add course list").click() |
---|
1118 | self.assertMatches('...Add current level 100 (Year 1)...', |
---|
1119 | self.browser.contents) |
---|
1120 | self.browser.getControl("Create course list now").click() |
---|
1121 | self.browser.getLink("100").click() |
---|
1122 | self.browser.getLink("Add and remove courses").click() |
---|
1123 | self.browser.getControl("Add course ticket").click() |
---|
1124 | self.browser.getControl(name="form.course").value = ['COURSE1'] |
---|
1125 | self.browser.getControl("Add course ticket").click() |
---|
1126 | self.assertMatches('...The ticket exists...', |
---|
1127 | self.browser.contents) |
---|
1128 | self.student['studycourse'].current_level = 200 |
---|
1129 | self.browser.getLink("Study Course").click() |
---|
1130 | self.browser.getLink("Add course list").click() |
---|
1131 | self.assertMatches('...Add current level 200 (Year 2)...', |
---|
1132 | self.browser.contents) |
---|
1133 | self.browser.getControl("Create course list now").click() |
---|
1134 | self.browser.getLink("200").click() |
---|
1135 | self.browser.getLink("Add and remove courses").click() |
---|
1136 | self.browser.getControl("Add course ticket").click() |
---|
1137 | self.browser.getControl(name="form.course").value = ['COURSE1'] |
---|
1138 | self.browser.getControl("Add course ticket").click() |
---|
1139 | self.assertMatches('...Successfully added COURSE1...', |
---|
1140 | self.browser.contents) |
---|
1141 | # Students can open the pdf course registration slip |
---|
1142 | self.browser.open(self.student_path + '/studycourse/200') |
---|
1143 | self.browser.getLink("Download course registration slip").click() |
---|
1144 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
1145 | self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf') |
---|
1146 | # Students can remove course tickets |
---|
1147 | self.browser.open(self.student_path + '/studycourse/200/edit') |
---|
1148 | self.browser.getControl("Remove selected", index=0).click() |
---|
1149 | self.assertTrue('No ticket selected' in self.browser.contents) |
---|
1150 | ctrl = self.browser.getControl(name='val_id') |
---|
1151 | ctrl.getControl(value='COURSE1').selected = True |
---|
1152 | self.browser.getControl("Remove selected", index=0).click() |
---|
1153 | self.assertTrue('Successfully removed' in self.browser.contents) |
---|
1154 | self.browser.getControl("Register course list").click() |
---|
1155 | self.assertTrue('Course list has been registered' in self.browser.contents) |
---|
1156 | self.assertEqual(self.student.state, 'courses registered') |
---|
1157 | return |
---|
1158 | |
---|
1159 | def test_manage_payments(self): |
---|
1160 | # Managers can add online school fee payment tickets |
---|
1161 | # if certain requirements are met |
---|
1162 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
1163 | self.browser.open(self.payments_student_path) |
---|
1164 | self.browser.getControl("Add online payment ticket").click() |
---|
1165 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
1166 | self.browser.getControl("Create ticket").click() |
---|
1167 | self.assertMatches('...ticket created...', |
---|
1168 | self.browser.contents) |
---|
1169 | ctrl = self.browser.getControl(name='val_id') |
---|
1170 | value = ctrl.options[0] |
---|
1171 | self.browser.getLink(value).click() |
---|
1172 | self.assertMatches('...Amount Authorized...', |
---|
1173 | self.browser.contents) |
---|
1174 | payment_url = self.browser.url |
---|
1175 | |
---|
1176 | # The pdf payment receipt can't yet be opened |
---|
1177 | self.browser.open(payment_url + '/payment_receipt.pdf') |
---|
1178 | self.assertMatches('...Ticket not yet paid...', |
---|
1179 | self.browser.contents) |
---|
1180 | |
---|
1181 | # The same payment (with same p_item, p_session and p_category) |
---|
1182 | # can be initialized a second time if the former ticket is not yet paid. |
---|
1183 | self.browser.open(self.payments_student_path) |
---|
1184 | self.browser.getControl("Add online payment ticket").click() |
---|
1185 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
1186 | self.browser.getControl("Create ticket").click() |
---|
1187 | self.assertMatches('...Payment ticket created...', |
---|
1188 | self.browser.contents) |
---|
1189 | |
---|
1190 | # Managers can open the callback view which simulates a valid callback |
---|
1191 | self.assertEqual(len(self.app['accesscodes']['SFE-0']),0) |
---|
1192 | self.browser.open(payment_url) |
---|
1193 | self.browser.getLink("Request callback").click() |
---|
1194 | self.assertMatches('...Valid callback received...', |
---|
1195 | self.browser.contents) |
---|
1196 | |
---|
1197 | # Callback can't be applied twice |
---|
1198 | self.browser.open(payment_url + '/callback') |
---|
1199 | self.assertMatches('...This ticket has already been paid...', |
---|
1200 | self.browser.contents) |
---|
1201 | |
---|
1202 | # Now the first ticket is paid and no more ticket of same type |
---|
1203 | # (with same p_item, p_session and p_category) can be added |
---|
1204 | self.browser.open(self.payments_student_path) |
---|
1205 | self.browser.getControl("Add online payment ticket").click() |
---|
1206 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
1207 | self.browser.getControl("Create ticket").click() |
---|
1208 | self.assertMatches( |
---|
1209 | '...This type of payment has already been made...', |
---|
1210 | self.browser.contents) |
---|
1211 | |
---|
1212 | # Managers can open the pdf payment receipt |
---|
1213 | self.browser.open(payment_url) |
---|
1214 | self.browser.getLink("Download payment receipt").click() |
---|
1215 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
1216 | self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf') |
---|
1217 | |
---|
1218 | # Managers can remove online school fee payment tickets |
---|
1219 | self.browser.open(self.payments_student_path) |
---|
1220 | self.browser.getControl("Remove selected").click() |
---|
1221 | self.assertMatches('...No payment selected...', self.browser.contents) |
---|
1222 | ctrl = self.browser.getControl(name='val_id') |
---|
1223 | value = ctrl.options[0] |
---|
1224 | ctrl.getControl(value=value).selected = True |
---|
1225 | self.browser.getControl("Remove selected", index=0).click() |
---|
1226 | self.assertTrue('Successfully removed' in self.browser.contents) |
---|
1227 | |
---|
1228 | # Managers can add online clearance payment tickets |
---|
1229 | self.browser.open(self.payments_student_path + '/addop') |
---|
1230 | self.browser.getControl(name="form.p_category").value = ['clearance'] |
---|
1231 | self.browser.getControl("Create ticket").click() |
---|
1232 | self.assertMatches('...ticket created...', |
---|
1233 | self.browser.contents) |
---|
1234 | |
---|
1235 | # Managers can open the callback view which simulates a valid callback |
---|
1236 | self.assertEqual(len(self.app['accesscodes']['CLR-0']),0) |
---|
1237 | ctrl = self.browser.getControl(name='val_id') |
---|
1238 | value = ctrl.options[1] # The clearance payment is the second in the table |
---|
1239 | self.browser.getLink(value).click() |
---|
1240 | self.browser.open(self.browser.url + '/callback') |
---|
1241 | self.assertMatches('...Valid callback received...', |
---|
1242 | self.browser.contents) |
---|
1243 | expected = '''... |
---|
1244 | <td> |
---|
1245 | Paid |
---|
1246 | </td>...''' |
---|
1247 | #import pdb; pdb.set_trace() |
---|
1248 | self.assertMatches(expected,self.browser.contents) |
---|
1249 | # The new CLR-0 pin has been created |
---|
1250 | self.assertEqual(len(self.app['accesscodes']['CLR-0']),1) |
---|
1251 | pin = self.app['accesscodes']['CLR-0'].keys()[0] |
---|
1252 | ac = self.app['accesscodes']['CLR-0'][pin] |
---|
1253 | ac.owner = self.student_id |
---|
1254 | return |
---|
1255 | |
---|
1256 | def test_student_payments(self): |
---|
1257 | # Login |
---|
1258 | self.browser.open(self.login_path) |
---|
1259 | self.browser.getControl(name="form.login").value = self.student_id |
---|
1260 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
1261 | self.browser.getControl("Login").click() |
---|
1262 | |
---|
1263 | # Students can add online clearance payment tickets |
---|
1264 | self.browser.open(self.payments_student_path + '/addop') |
---|
1265 | self.browser.getControl(name="form.p_category").value = ['clearance'] |
---|
1266 | self.browser.getControl("Create ticket").click() |
---|
1267 | self.assertMatches('...ticket created...', |
---|
1268 | self.browser.contents) |
---|
1269 | |
---|
1270 | # Students can open the callback view which simulates a valid callback |
---|
1271 | self.assertEqual(len(self.app['accesscodes']['CLR-0']),0) |
---|
1272 | ctrl = self.browser.getControl(name='val_id') |
---|
1273 | value = ctrl.options[0] |
---|
1274 | self.browser.getLink(value).click() |
---|
1275 | payment_url = self.browser.url |
---|
1276 | self.browser.open(payment_url + '/callback') |
---|
1277 | self.assertMatches('...Valid callback received...', |
---|
1278 | self.browser.contents) |
---|
1279 | expected = '''... |
---|
1280 | <td> |
---|
1281 | Paid |
---|
1282 | </td>...''' |
---|
1283 | self.assertMatches(expected,self.browser.contents) |
---|
1284 | # The new CLR-0 pin has been created |
---|
1285 | self.assertEqual(len(self.app['accesscodes']['CLR-0']),1) |
---|
1286 | pin = self.app['accesscodes']['CLR-0'].keys()[0] |
---|
1287 | ac = self.app['accesscodes']['CLR-0'][pin] |
---|
1288 | ac.owner = self.student_id |
---|
1289 | |
---|
1290 | # Students can open the pdf payment receipt |
---|
1291 | self.browser.open(payment_url + '/payment_receipt.pdf') |
---|
1292 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
1293 | self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf') |
---|
1294 | |
---|
1295 | # The new CLR-0 pin can be used for starting clearance |
---|
1296 | # but they have to upload a passport picture first |
---|
1297 | # which is only possible in state admitted |
---|
1298 | self.browser.open(self.student_path + '/change_portrait') |
---|
1299 | self.assertMatches('...form is locked...', |
---|
1300 | self.browser.contents) |
---|
1301 | IWorkflowInfo(self.student).fireTransition('admit') |
---|
1302 | self.browser.open(self.student_path + '/change_portrait') |
---|
1303 | pseudo_image = StringIO('I pretend to be a graphics file') |
---|
1304 | ctrl = self.browser.getControl(name='passportuploadedit') |
---|
1305 | file_ctrl = ctrl.mech_control |
---|
1306 | file_ctrl.add_file(pseudo_image, filename='my_photo.jpg') |
---|
1307 | self.browser.getControl( |
---|
1308 | name='upload_passportuploadedit').click() |
---|
1309 | self.browser.open(self.student_path + '/start_clearance') |
---|
1310 | parts = pin.split('-')[1:] |
---|
1311 | clrseries, clrnumber = parts |
---|
1312 | self.browser.getControl(name="ac_series").value = clrseries |
---|
1313 | self.browser.getControl(name="ac_number").value = clrnumber |
---|
1314 | self.browser.getControl("Start clearance now").click() |
---|
1315 | self.assertMatches('...Clearance process has been started...', |
---|
1316 | self.browser.contents) |
---|
1317 | |
---|
1318 | # Students can add online school fee payment tickets |
---|
1319 | self.browser.open(self.payments_student_path) |
---|
1320 | self.browser.getControl("Add online payment ticket").click() |
---|
1321 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
1322 | self.browser.getControl("Create ticket").click() |
---|
1323 | self.assertMatches('...ticket created...', |
---|
1324 | self.browser.contents) |
---|
1325 | ctrl = self.browser.getControl(name='val_id') |
---|
1326 | value = ctrl.options[0] |
---|
1327 | self.browser.getLink(value).click() |
---|
1328 | self.assertMatches('...Amount Authorized...', |
---|
1329 | self.browser.contents) |
---|
1330 | |
---|
1331 | # Students can open the callback view which simulates a valid callback |
---|
1332 | self.assertEqual(len(self.app['accesscodes']['SFE-0']),0) |
---|
1333 | self.browser.open(self.browser.url + '/callback') |
---|
1334 | self.assertMatches('...Valid callback received...', |
---|
1335 | self.browser.contents) |
---|
1336 | |
---|
1337 | # Students can remove only online payment tickets which have |
---|
1338 | # not received a valid callback |
---|
1339 | self.browser.open(self.payments_student_path) |
---|
1340 | self.assertRaises( |
---|
1341 | LookupError, self.browser.getControl, name='val_id') |
---|
1342 | self.browser.open(self.payments_student_path + '/addop') |
---|
1343 | self.browser.getControl(name="form.p_category").value = ['gown'] |
---|
1344 | self.browser.getControl("Create ticket").click() |
---|
1345 | self.browser.open(self.payments_student_path) |
---|
1346 | ctrl = self.browser.getControl(name='val_id') |
---|
1347 | value = ctrl.options[0] |
---|
1348 | ctrl.getControl(value=value).selected = True |
---|
1349 | self.browser.getControl("Remove selected", index=0).click() |
---|
1350 | self.assertTrue('Successfully removed' in self.browser.contents) |
---|
1351 | |
---|
1352 | # The new SFE-0 pin can be used for starting course registration |
---|
1353 | IWorkflowInfo(self.student).fireTransition('request_clearance') |
---|
1354 | IWorkflowInfo(self.student).fireTransition('clear') |
---|
1355 | self.browser.open(self.studycourse_student_path) |
---|
1356 | self.browser.getLink('Start course registration').click() |
---|
1357 | pin = self.app['accesscodes']['SFE-0'].keys()[0] |
---|
1358 | parts = pin.split('-')[1:] |
---|
1359 | sfeseries, sfenumber = parts |
---|
1360 | self.browser.getControl(name="ac_series").value = sfeseries |
---|
1361 | self.browser.getControl(name="ac_number").value = sfenumber |
---|
1362 | self.browser.getControl("Start course registration now").click() |
---|
1363 | self.assertMatches('...Course registration has been started...', |
---|
1364 | self.browser.contents) |
---|
1365 | self.assertTrue(self.student.state == 'school fee paid') |
---|
1366 | return |
---|
1367 | |
---|
1368 | def test_manage_accommodation(self): |
---|
1369 | # Managers can add online booking fee payment tickets and open the |
---|
1370 | # callback view (see test_manage_payments) |
---|
1371 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
1372 | self.browser.open(self.payments_student_path) |
---|
1373 | self.browser.getControl("Add online payment ticket").click() |
---|
1374 | self.browser.getControl(name="form.p_category").value = ['bed_allocation'] |
---|
1375 | # If student is not in accommodation session, payment cannot be processed |
---|
1376 | self.app['configuration'].accommodation_session = 2011 |
---|
1377 | self.browser.getControl("Create ticket").click() |
---|
1378 | self.assertMatches('...Your current session does not match...', |
---|
1379 | self.browser.contents) |
---|
1380 | self.app['configuration'].accommodation_session = 2004 |
---|
1381 | self.browser.getControl("Add online payment ticket").click() |
---|
1382 | self.browser.getControl(name="form.p_category").value = ['bed_allocation'] |
---|
1383 | self.browser.getControl("Create ticket").click() |
---|
1384 | ctrl = self.browser.getControl(name='val_id') |
---|
1385 | value = ctrl.options[0] |
---|
1386 | self.browser.getLink(value).click() |
---|
1387 | self.browser.open(self.browser.url + '/callback') |
---|
1388 | # The new HOS-0 pin has been created |
---|
1389 | self.assertEqual(len(self.app['accesscodes']['HOS-0']),1) |
---|
1390 | pin = self.app['accesscodes']['HOS-0'].keys()[0] |
---|
1391 | ac = self.app['accesscodes']['HOS-0'][pin] |
---|
1392 | ac.owner = self.student_id |
---|
1393 | parts = pin.split('-')[1:] |
---|
1394 | sfeseries, sfenumber = parts |
---|
1395 | # Managers can use HOS code and book a bed space with it |
---|
1396 | self.browser.open(self.acco_student_path) |
---|
1397 | self.browser.getLink("Book accommodation").click() |
---|
1398 | self.assertMatches('...You are in the wrong...', |
---|
1399 | self.browser.contents) |
---|
1400 | IWorkflowInfo(self.student).fireTransition('admit') |
---|
1401 | # An existing HOS code can only be used if students |
---|
1402 | # are in accommodation session |
---|
1403 | self.student['studycourse'].current_session = 2003 |
---|
1404 | self.browser.getLink("Book accommodation").click() |
---|
1405 | self.assertMatches('...Your current session does not match...', |
---|
1406 | self.browser.contents) |
---|
1407 | self.student['studycourse'].current_session = 2004 |
---|
1408 | # All requirements are met and ticket can be created |
---|
1409 | self.browser.getLink("Book accommodation").click() |
---|
1410 | self.assertMatches('...Activation Code:...', |
---|
1411 | self.browser.contents) |
---|
1412 | self.browser.getControl(name="ac_series").value = sfeseries |
---|
1413 | self.browser.getControl(name="ac_number").value = sfenumber |
---|
1414 | self.browser.getControl("Create bed ticket").click() |
---|
1415 | self.assertMatches('...Hall 1, Block A, Room 101, Bed A...', |
---|
1416 | self.browser.contents) |
---|
1417 | # Bed has been allocated |
---|
1418 | bed1 = self.app['hostels']['hall-1']['hall-1_A_101_A'] |
---|
1419 | self.assertTrue(bed1.owner == self.student_id) |
---|
1420 | # BedTicketAddPage is now blocked |
---|
1421 | self.browser.getLink("Book accommodation").click() |
---|
1422 | self.assertMatches('...You already booked a bed space...', |
---|
1423 | self.browser.contents) |
---|
1424 | # The bed ticket displays the data correctly |
---|
1425 | self.browser.open(self.acco_student_path + '/2004') |
---|
1426 | self.assertMatches('...Hall 1, Block A, Room 101, Bed A...', |
---|
1427 | self.browser.contents) |
---|
1428 | self.assertMatches('...2004/2005...', self.browser.contents) |
---|
1429 | self.assertMatches('...regular_male_fr...', self.browser.contents) |
---|
1430 | self.assertMatches('...%s...' % pin, self.browser.contents) |
---|
1431 | # Managers can relocate students if the student's bed_type has changed |
---|
1432 | self.browser.getLink("Relocate student").click() |
---|
1433 | self.assertMatches( |
---|
1434 | "...Student can't be relocated...", self.browser.contents) |
---|
1435 | self.student.sex = u'f' |
---|
1436 | self.browser.getLink("Relocate student").click() |
---|
1437 | self.assertMatches( |
---|
1438 | "...Hall 1, Block A, Room 101, Bed B...", self.browser.contents) |
---|
1439 | self.assertTrue(bed1.owner == NOT_OCCUPIED) |
---|
1440 | bed2 = self.app['hostels']['hall-1']['hall-1_A_101_B'] |
---|
1441 | self.assertTrue(bed2.owner == self.student_id) |
---|
1442 | self.assertTrue(self.student['accommodation'][ |
---|
1443 | '2004'].bed_type == u'regular_female_fr') |
---|
1444 | # The payment object still shows the original payment item |
---|
1445 | payment_id = self.student['payments'].keys()[0] |
---|
1446 | payment = self.student['payments'][payment_id] |
---|
1447 | self.assertTrue(payment.p_item == u'regular_male_fr') |
---|
1448 | # Managers can relocate students if the bed's bed_type has changed |
---|
1449 | bed1.bed_type = u'regular_female_fr' |
---|
1450 | bed2.bed_type = u'regular_male_fr' |
---|
1451 | notify(grok.ObjectModifiedEvent(bed1)) |
---|
1452 | notify(grok.ObjectModifiedEvent(bed2)) |
---|
1453 | self.browser.getLink("Relocate student").click() |
---|
1454 | self.assertMatches( |
---|
1455 | "...Student relocated...", self.browser.contents) |
---|
1456 | self.assertMatches( |
---|
1457 | "... Hall 1, Block A, Room 101, Bed A...", self.browser.contents) |
---|
1458 | self.assertMatches(bed1.owner, self.student_id) |
---|
1459 | self.assertMatches(bed2.owner, NOT_OCCUPIED) |
---|
1460 | # Managers can't relocate students if bed is reserved |
---|
1461 | self.student.sex = u'm' |
---|
1462 | bed1.bed_type = u'regular_female_reserved' |
---|
1463 | notify(grok.ObjectModifiedEvent(bed1)) |
---|
1464 | self.browser.getLink("Relocate student").click() |
---|
1465 | self.assertMatches( |
---|
1466 | "...Students in reserved beds can't be relocated...", |
---|
1467 | self.browser.contents) |
---|
1468 | # Managers can relocate students if booking has been cancelled but |
---|
1469 | # other bed space has been manually allocated after cancellation |
---|
1470 | old_owner = bed1.releaseBed() |
---|
1471 | self.assertMatches(old_owner, self.student_id) |
---|
1472 | bed2.owner = self.student_id |
---|
1473 | self.browser.open(self.acco_student_path + '/2004') |
---|
1474 | self.assertMatches( |
---|
1475 | "...booking cancelled...", self.browser.contents) |
---|
1476 | self.browser.getLink("Relocate student").click() |
---|
1477 | # We didn't informed the catalog therefore the new owner is not found |
---|
1478 | self.assertMatches( |
---|
1479 | "...There is no free bed in your category regular_male_fr...", |
---|
1480 | self.browser.contents) |
---|
1481 | # Now we fire the event properly |
---|
1482 | notify(grok.ObjectModifiedEvent(bed2)) |
---|
1483 | self.browser.getLink("Relocate student").click() |
---|
1484 | self.assertMatches( |
---|
1485 | "...Student relocated...", self.browser.contents) |
---|
1486 | self.assertMatches( |
---|
1487 | "... Hall 1, Block A, Room 101, Bed B...", self.browser.contents) |
---|
1488 | # Managers can delete bed tickets |
---|
1489 | self.browser.open(self.acco_student_path) |
---|
1490 | ctrl = self.browser.getControl(name='val_id') |
---|
1491 | value = ctrl.options[0] |
---|
1492 | ctrl.getControl(value=value).selected = True |
---|
1493 | self.browser.getControl("Remove selected", index=0).click() |
---|
1494 | self.assertMatches('...Successfully removed...', self.browser.contents) |
---|
1495 | # The bed has been properly released by the event handler |
---|
1496 | self.assertMatches(bed1.owner, NOT_OCCUPIED) |
---|
1497 | self.assertMatches(bed2.owner, NOT_OCCUPIED) |
---|
1498 | return |
---|
1499 | |
---|
1500 | def test_student_accommodation(self): |
---|
1501 | # Login |
---|
1502 | self.browser.open(self.login_path) |
---|
1503 | self.browser.getControl(name="form.login").value = self.student_id |
---|
1504 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
1505 | self.browser.getControl("Login").click() |
---|
1506 | |
---|
1507 | # Students can add online booking fee payment tickets and open the |
---|
1508 | # callback view (see test_manage_payments) |
---|
1509 | self.browser.getLink("Payments").click() |
---|
1510 | self.browser.getControl("Add online payment ticket").click() |
---|
1511 | self.browser.getControl(name="form.p_category").value = ['bed_allocation'] |
---|
1512 | self.browser.getControl("Create ticket").click() |
---|
1513 | ctrl = self.browser.getControl(name='val_id') |
---|
1514 | value = ctrl.options[0] |
---|
1515 | self.browser.getLink(value).click() |
---|
1516 | self.browser.open(self.browser.url + '/callback') |
---|
1517 | # The new HOS-0 pin has been created |
---|
1518 | self.assertEqual(len(self.app['accesscodes']['HOS-0']),1) |
---|
1519 | pin = self.app['accesscodes']['HOS-0'].keys()[0] |
---|
1520 | ac = self.app['accesscodes']['HOS-0'][pin] |
---|
1521 | ac.owner = u'Anybody' |
---|
1522 | parts = pin.split('-')[1:] |
---|
1523 | sfeseries, sfenumber = parts |
---|
1524 | |
---|
1525 | # Students can use HOS code and book a bed space with it |
---|
1526 | self.browser.open(self.acco_student_path) |
---|
1527 | self.browser.getLink("Book accommodation").click() |
---|
1528 | self.assertMatches('...You are in the wrong...', |
---|
1529 | self.browser.contents) |
---|
1530 | IWorkflowInfo(self.student).fireTransition('admit') |
---|
1531 | self.browser.getLink("Book accommodation").click() |
---|
1532 | self.assertMatches('...Activation Code:...', |
---|
1533 | self.browser.contents) |
---|
1534 | self.browser.getControl(name="ac_series").value = u'nonsense' |
---|
1535 | self.browser.getControl(name="ac_number").value = sfenumber |
---|
1536 | self.browser.getControl("Create bed ticket").click() |
---|
1537 | self.assertMatches('...Activation code is invalid...', |
---|
1538 | self.browser.contents) |
---|
1539 | self.browser.getControl(name="ac_series").value = sfeseries |
---|
1540 | self.browser.getControl(name="ac_number").value = sfenumber |
---|
1541 | self.browser.getControl("Create bed ticket").click() |
---|
1542 | self.assertMatches('...You are not the owner of this access code...', |
---|
1543 | self.browser.contents) |
---|
1544 | ac.owner = self.student_id |
---|
1545 | self.browser.getControl(name="ac_series").value = sfeseries |
---|
1546 | self.browser.getControl(name="ac_number").value = sfenumber |
---|
1547 | self.browser.getControl("Create bed ticket").click() |
---|
1548 | self.assertMatches('...Hall 1, Block A, Room 101, Bed A...', |
---|
1549 | self.browser.contents) |
---|
1550 | |
---|
1551 | # Bed has been allocated |
---|
1552 | bed = self.app['hostels']['hall-1']['hall-1_A_101_A'] |
---|
1553 | self.assertTrue(bed.owner == self.student_id) |
---|
1554 | |
---|
1555 | # BedTicketAddPage is now blocked |
---|
1556 | self.browser.getLink("Book accommodation").click() |
---|
1557 | self.assertMatches('...You already booked a bed space...', |
---|
1558 | self.browser.contents) |
---|
1559 | |
---|
1560 | # The bed ticket displays the data correctly |
---|
1561 | self.browser.open(self.acco_student_path + '/2004') |
---|
1562 | self.assertMatches('...Hall 1, Block A, Room 101, Bed A...', |
---|
1563 | self.browser.contents) |
---|
1564 | self.assertMatches('...2004/2005...', self.browser.contents) |
---|
1565 | self.assertMatches('...regular_male_fr...', self.browser.contents) |
---|
1566 | self.assertMatches('...%s...' % pin, self.browser.contents) |
---|
1567 | |
---|
1568 | # Students can open the pdf slip |
---|
1569 | self.browser.open(self.browser.url + '/bed_allocation.pdf') |
---|
1570 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
1571 | self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf') |
---|
1572 | |
---|
1573 | # Students can't relocate themselves |
---|
1574 | self.assertFalse('Relocate' in self.browser.contents) |
---|
1575 | relocate_path = self.acco_student_path + '/2004/relocate' |
---|
1576 | self.assertRaises( |
---|
1577 | Unauthorized, self.browser.open, relocate_path) |
---|
1578 | |
---|
1579 | # Students can't the Remove button and check boxes |
---|
1580 | self.browser.open(self.acco_student_path) |
---|
1581 | self.assertFalse('Remove' in self.browser.contents) |
---|
1582 | self.assertFalse('val_id' in self.browser.contents) |
---|
1583 | return |
---|
1584 | |
---|
1585 | def test_change_password_request(self): |
---|
1586 | self.browser.open('http://localhost/app/changepw') |
---|
1587 | self.browser.getControl(name="form.reg_number").value = '123' |
---|
1588 | self.browser.getControl(name="form.email").value = 'aa@aa.ng' |
---|
1589 | self.browser.getControl("Get login credentials").click() |
---|
1590 | self.assertTrue('An email with' in self.browser.contents) |
---|