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