source: main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py @ 7413

Last change on this file since 7413 was 7413, checked in by Henrik Bettermann, 13 years ago

Test if managers and officers can contact students.

  • Property svn:keywords set to Id
File size: 80.6 KB
Line 
1## $Id: test_browser.py 7413 2011-12-21 06:36:38Z 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"""
19Test the student-related UI components.
20"""
21import shutil
22import tempfile
23from StringIO import StringIO
24from datetime import datetime
25import os
26import grok
27from zope.event import notify
28from zope.component import createObject
29from zope.component.hooks import setSite, clearSite
30from zope.security.interfaces import Unauthorized
31from zope.securitypolicy.interfaces import IPrincipalRoleManager
32from zope.testbrowser.testing import Browser
33from hurry.workflow.interfaces import IWorkflowInfo
34from waeup.sirp.testing import FunctionalLayer, FunctionalTestCase
35from waeup.sirp.app import University
36from waeup.sirp.configuration import SessionConfiguration
37from waeup.sirp.students.student import Student
38from waeup.sirp.students.studylevel import StudentStudyLevel
39from waeup.sirp.university.faculty import Faculty
40from waeup.sirp.university.department import Department
41from waeup.sirp.interfaces import IUserAccount
42from waeup.sirp.authentication import LocalRoleSetEvent
43from waeup.sirp.hostels.hostel import Hostel, Bed, NOT_OCCUPIED
44
45PH_LEN = 2059  # Length of placeholder file
46
47def 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
58class 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
216class 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
344class 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
685Aaren,Pieri,1,1990-01-02,100000,aa@aa.ng,1234
686Claus,Finau,2,1990-01-03,100001,aa@aa.ng,1234
687Brit,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
7121,,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        return
740
741    def test_handle_clearance_by_co(self):
742        # Create clearance officer
743        self.app['users'].addUser('mrclear', 'mrclearsecret')
744        self.app['users']['mrclear'].email = 'mrclear@foo.ng'
745        self.app['users']['mrclear'].title = 'Carlo Pitter'
746        # Clearance officers need not necessarily to get
747        # the StudentsOfficer site role
748        #prmglobal = IPrincipalRoleManager(self.app)
749        #prmglobal.assignRoleToPrincipal('waeup.StudentsOfficer', 'mrclear')
750        # Assign local ClearanceOfficer role
751        department = self.app['faculties']['fac1']['dep1']
752        prmlocal = IPrincipalRoleManager(department)
753        prmlocal.assignRoleToPrincipal('waeup.local.ClearanceOfficer', 'mrclear')
754        IWorkflowInfo(self.student).fireTransition('admit')
755        IWorkflowInfo(self.student).fireTransition('start_clearance')
756        # Login as clearance officer
757        self.browser.open(self.login_path)
758        self.browser.getControl(name="form.login").value = 'mrclear'
759        self.browser.getControl(name="form.password").value = 'mrclearsecret'
760        self.browser.getControl("Login").click()
761        self.assertMatches('...You logged in...', self.browser.contents)
762        # CO can see his roles
763        self.browser.getLink("My Roles").click()
764        self.assertMatches(
765            '...<div>Academics Officer (view only)</div>...',
766            self.browser.contents)
767        #self.assertMatches(
768        #    '...<div>Students Officer (view only)</div>...',
769        #    self.browser.contents)
770        # But not his local role ...
771        self.assertFalse('Clearance Officer' in self.browser.contents)
772        # ... because we forgot to notify the department that the local role
773        # has changed
774        notify(LocalRoleSetEvent(
775            department, 'waeup.local.ClearanceOfficer', 'mrclear', granted=True))
776        self.browser.open('http://localhost/app/users/mrclear/my_roles')
777        self.assertTrue('Clearance Officer' in self.browser.contents)
778        self.assertMatches(
779            '...<a href="http://localhost/app/faculties/fac1/dep1">...',
780            self.browser.contents)
781        # CO can view the student ...
782        self.browser.open(self.clearance_student_path)
783        self.assertEqual(self.browser.headers['Status'], '200 Ok')
784        self.assertEqual(self.browser.url, self.clearance_student_path)
785        # ... but not other students
786        other_student = Student()
787        other_student.firstname = u'Dep2'
788        other_student.lastname = u'Student'
789        self.app['students'].addStudent(other_student)
790        other_student_path = (
791            'http://localhost/app/students/%s' % other_student.student_id)
792        self.assertRaises(
793            Unauthorized, self.browser.open, other_student_path)
794        # Only in state clearance requested the CO does see the 'Clear' button
795        self.browser.open(self.clearance_student_path)
796        self.assertFalse('Clear student' in self.browser.contents)
797        IWorkflowInfo(self.student).fireTransition('request_clearance')
798        self.browser.open(self.clearance_student_path)
799        self.assertTrue('Clear student' in self.browser.contents)
800        self.browser.getLink("Clear student").click()
801        self.assertTrue('Student has been cleared' in self.browser.contents)
802        self.assertTrue('State: <span>cleared</span>' in self.browser.contents)
803        self.browser.getLink("Reject clearance").click()
804        self.assertTrue('Clearance has been annulled' in self.browser.contents)
805        urlmessage = 'Clearance+has+been+annulled'
806        # CO does now see the contact form
807        self.assertEqual(self.browser.url, self.student_path +
808            '/contactstudent?subject=%s' % urlmessage)
809        self.assertTrue('State: <span>clearance started</span>'
810            in self.browser.contents)
811        IWorkflowInfo(self.student).fireTransition('request_clearance')
812        self.browser.open(self.clearance_student_path)
813        self.browser.getLink("Reject clearance").click()
814        self.assertTrue('Clearance request has been rejected'
815            in self.browser.contents)
816        self.assertTrue('State: <span>clearance started</span>'
817            in self.browser.contents)
818        # CO does now also see the contact form and can send a message
819        self.browser.getControl(name="form.subject").value = 'Important subject'
820        self.browser.getControl(name="form.body").value = 'Clearance rejected'
821        self.browser.getControl("Send message now").click()
822        self.assertTrue('Your message has been sent' in self.browser.contents)
823        # The CO can't clear students if not in state
824        # clearance requested
825        self.browser.open(self.student_path + '/clear')
826        self.assertTrue('Student is in the wrong state'
827            in self.browser.contents)
828        # The CO can go to his department throug the my_roles page
829        self.browser.open('http://localhost/app/users/mrclear/my_roles')
830        self.browser.getLink("http://localhost/app/faculties/fac1/dep1").click()
831        # and view the list of students
832        self.browser.getLink("Show students").click()
833        self.assertTrue(self.student_id in self.browser.contents)
834
835    def test_handle_courses_by_ca(self):
836        # Create course adviser
837        self.app['users'].addUser('mrsadvise', 'mrsadvisesecret')
838        self.app['users']['mrsadvise'].email = 'mradvise@foo.ng'
839        self.app['users']['mrsadvise'].title = 'Helen Procter'
840        # Assign local CourseAdviser100 role for a certificate
841        cert = self.app['faculties']['fac1']['dep1'].certificates['CERT1']
842        prmlocal = IPrincipalRoleManager(cert)
843        prmlocal.assignRoleToPrincipal('waeup.local.CourseAdviser100', 'mrsadvise')
844        IWorkflowInfo(self.student).fireTransition('admit')
845        IWorkflowInfo(self.student).fireTransition('start_clearance')
846        IWorkflowInfo(self.student).fireTransition('request_clearance')
847        IWorkflowInfo(self.student).fireTransition('clear')
848        IWorkflowInfo(self.student).fireTransition('pay_first_school_fee')
849        # Login as course adviser
850        self.browser.open(self.login_path)
851        self.browser.getControl(name="form.login").value = 'mrsadvise'
852        self.browser.getControl(name="form.password").value = 'mrsadvisesecret'
853        self.browser.getControl("Login").click()
854        self.assertMatches('...You logged in...', self.browser.contents)
855        # CO can see his roles
856        self.browser.getLink("My Roles").click()
857        self.assertMatches(
858            '...<div>Academics Officer (view only)</div>...',
859            self.browser.contents)
860        # But not his local role ...
861        self.assertFalse('Course Adviser' in self.browser.contents)
862        # ... because we forgot to notify the certificate that the local role
863        # has changed
864        notify(LocalRoleSetEvent(
865            cert, 'waeup.local.CourseAdviser100', 'mrsadvise', granted=True))
866        self.browser.open('http://localhost/app/users/mrsadvise/my_roles')
867        self.assertTrue('Course Adviser 100L' in self.browser.contents)
868        self.assertMatches(
869            '...<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">...',
870            self.browser.contents)
871        # CA can view the student ...
872        self.browser.open(self.student_path)
873        self.assertEqual(self.browser.headers['Status'], '200 Ok')
874        self.assertEqual(self.browser.url, self.student_path)
875        # ... but not other students
876        other_student = Student()
877        other_student.firstname = u'Dep2'
878        other_student.lastname = u'Student'
879        self.app['students'].addStudent(other_student)
880        other_student_path = (
881            'http://localhost/app/students/%s' % other_student.student_id)
882        self.assertRaises(
883            Unauthorized, self.browser.open, other_student_path)
884        # We add study level 110 to the student's studycourse
885        studylevel = StudentStudyLevel()
886        studylevel.level = 110
887        self.student['studycourse'].addStudentStudyLevel(
888            cert,studylevel)
889        L110_student_path = self.studycourse_student_path + '/110'
890        # Only in state courses registered and only if the current level
891        # corresponds with the name of the study level object
892        # the 100L CA does see the 'Validate' button
893        self.browser.open(L110_student_path)
894        self.assertFalse('Validate' in self.browser.contents)
895        IWorkflowInfo(self.student).fireTransition('register_courses')
896        self.browser.open(L110_student_path)
897        self.assertFalse('Validate' in self.browser.contents)
898        self.student['studycourse'].current_level = 110
899        self.browser.open(L110_student_path)
900        self.assertTrue('Validate' in self.browser.contents)
901        # ... but a 100L CA does not see the button on other levels
902        studylevel2 = StudentStudyLevel()
903        studylevel2.level = 200
904        self.student['studycourse'].addStudentStudyLevel(
905            cert,studylevel2)
906        L200_student_path = self.studycourse_student_path + '/200'
907        self.browser.open(L200_student_path)
908        self.assertFalse('Validate' in self.browser.contents)
909        self.browser.open(L110_student_path)
910        self.browser.getLink("Validate courses").click()
911        self.assertTrue('Course list has been validated' in self.browser.contents)
912        self.assertTrue('State: <span>courses validated</span>' in self.browser.contents)
913        self.browser.getLink("Reject courses").click()
914        self.assertTrue('Course list request has been annulled'
915            in self.browser.contents)
916        urlmessage = 'Course+list+request+has+been+annulled'
917        self.assertEqual(self.browser.url, self.student_path +
918            '/contactstudent?subject=%s' % urlmessage)
919        self.assertTrue('State: <span>school fee paid</span>'
920            in self.browser.contents)
921        IWorkflowInfo(self.student).fireTransition('register_courses')
922        self.browser.open(L110_student_path)
923        self.browser.getLink("Reject courses").click()
924        self.assertTrue('Course list request has been rejected'
925            in self.browser.contents)
926        self.assertTrue('State: <span>school fee paid</span>'
927            in self.browser.contents)
928        # CA does now see the contact form and can send a message
929        self.browser.getControl(name="form.subject").value = 'Important subject'
930        self.browser.getControl(name="form.body").value = 'Course list rejected'
931        self.browser.getControl("Send message now").click()
932        self.assertTrue('Your message has been sent' in self.browser.contents)
933        # The CA can't validate courses if not in state
934        # courses registered
935        self.browser.open(L110_student_path + '/validate_courses')
936        self.assertTrue('Student is in the wrong state'
937            in self.browser.contents)
938        # The CA can go to his certificate throug the my_roles page
939        self.browser.open('http://localhost/app/users/mrsadvise/my_roles')
940        self.browser.getLink(
941            "http://localhost/app/faculties/fac1/dep1/certificates/CERT1").click()
942        # and view the list of students
943        self.browser.getLink("Show students").click()
944        self.assertTrue(self.student_id in self.browser.contents)
945
946    def test_student_change_password(self):
947        # Students can change the password
948        self.browser.open(self.login_path)
949        self.browser.getControl(name="form.login").value = self.student_id
950        self.browser.getControl(name="form.password").value = 'spwd'
951        self.browser.getControl("Login").click()
952        self.assertEqual(self.browser.url, self.student_path)
953        self.assertTrue('You logged in' in self.browser.contents)
954        # Change password
955        self.browser.getLink("Change password").click()
956        self.browser.getControl(name="change_password").value = 'pw'
957        self.browser.getControl(
958            name="change_password_repeat").value = 'pw'
959        self.browser.getControl("Save").click()
960        self.assertTrue('Password must have at least' in self.browser.contents)
961        self.browser.getControl(name="change_password").value = 'new_password'
962        self.browser.getControl(
963            name="change_password_repeat").value = 'new_passssword'
964        self.browser.getControl("Save").click()
965        self.assertTrue('Passwords do not match' in self.browser.contents)
966        self.browser.getControl(name="change_password").value = 'new_password'
967        self.browser.getControl(
968            name="change_password_repeat").value = 'new_password'
969        self.browser.getControl("Save").click()
970        self.assertTrue('Password changed' in self.browser.contents)
971        # We are still logged in. Changing the password hasn't thrown us out.
972        self.browser.getLink("My Data").click()
973        self.assertEqual(self.browser.url, self.student_path)
974        # We can logout
975        self.browser.getLink("Logout").click()
976        self.assertTrue('You have been logged out' in self.browser.contents)
977        self.assertEqual(self.browser.url, 'http://localhost/app')
978        # We can login again with the new password
979        self.browser.getLink("Login").click()
980        self.browser.open(self.login_path)
981        self.browser.getControl(name="form.login").value = self.student_id
982        self.browser.getControl(name="form.password").value = 'new_password'
983        self.browser.getControl("Login").click()
984        self.assertEqual(self.browser.url, self.student_path)
985        self.assertTrue('You logged in' in self.browser.contents)
986        return
987
988    def test_setpassword(self):
989        # Set password for first-time access
990        student = Student()
991        student.reg_number = u'123456'
992        student.firstname = u'Klaus'
993        student.lastname = u'Tester'
994        self.app['students'].addStudent(student)
995        setpassword_path = 'http://localhost/app/setpassword'
996        student_path = 'http://localhost/app/students/%s' % student.student_id
997        self.browser.open(setpassword_path)
998        self.browser.getControl(name="ac_series").value = self.existing_pwdseries
999        self.browser.getControl(name="ac_number").value = self.existing_pwdnumber
1000        self.browser.getControl(name="reg_number").value = '223456'
1001        self.browser.getControl("Show").click()
1002        self.assertMatches('...No student found...',
1003                           self.browser.contents)
1004        self.browser.getControl(name="reg_number").value = '123456'
1005        self.browser.getControl(name="ac_number").value = '999999'
1006        self.browser.getControl("Show").click()
1007        self.assertMatches('...Access code is invalid...',
1008                           self.browser.contents)
1009        self.browser.getControl(name="ac_number").value = self.existing_pwdnumber
1010        self.browser.getControl("Show").click()
1011        self.assertMatches('...Password has been set. Your Student Id is...',
1012                           self.browser.contents)
1013        self.browser.getControl("Show").click()
1014        self.assertMatches(
1015            '...Password has already been set. Your Student Id is...',
1016            self.browser.contents)
1017        existing_pwdpin = self.pwdpins[1]
1018        parts = existing_pwdpin.split('-')[1:]
1019        existing_pwdseries, existing_pwdnumber = parts
1020        self.browser.getControl(name="ac_series").value = existing_pwdseries
1021        self.browser.getControl(name="ac_number").value = existing_pwdnumber
1022        self.browser.getControl(name="reg_number").value = '123456'
1023        self.browser.getControl("Show").click()
1024        self.assertMatches(
1025            '...You are using the wrong Access Code...',
1026            self.browser.contents)
1027        # The student can login with the new credentials
1028        self.browser.open(self.login_path)
1029        self.browser.getControl(name="form.login").value = student.student_id
1030        self.browser.getControl(
1031            name="form.password").value = self.existing_pwdnumber
1032        self.browser.getControl("Login").click()
1033        self.assertEqual(self.browser.url, student_path)
1034        self.assertTrue('You logged in' in self.browser.contents)
1035        return
1036
1037    def test_student_access(self):
1038        # Students can access their own objects
1039        # and can perform actions
1040        IWorkflowInfo(self.student).fireTransition('admit')
1041        self.browser.open(self.login_path)
1042        self.browser.getControl(name="form.login").value = self.student_id
1043        self.browser.getControl(name="form.password").value = 'spwd'
1044        self.browser.getControl("Login").click()
1045        # Student can upload a passport picture
1046        self.browser.open(self.student_path + '/change_portrait')
1047        ctrl = self.browser.getControl(name='passportuploadedit')
1048        file_obj = open(
1049            os.path.join(os.path.dirname(__file__), 'test_image.jpg'),'rb')
1050        file_ctrl = ctrl.mech_control
1051        file_ctrl.add_file(file_obj, filename='my_photo.jpg')
1052        self.browser.getControl(
1053            name='upload_passportuploadedit').click()
1054        self.assertTrue(
1055            '<img align="middle" height="125px" src="passport.jpg" />'
1056            in self.browser.contents)
1057        # Student can view the clearance data
1058        self.browser.getLink("Clearance Data").click()
1059        # Student can't open clearance edit form before starting clearance
1060        self.browser.open(self.student_path + '/cedit')
1061        self.assertMatches('...The requested form is locked...',
1062                           self.browser.contents)
1063        self.browser.getLink("Clearance Data").click()
1064        self.browser.getLink("Start clearance").click()
1065        self.student.email = None
1066        # Uups, we forgot to fill the email fields
1067        self.browser.getControl("Start clearance").click()
1068        self.assertMatches('...Not all required fields filled...',
1069                           self.browser.contents)
1070        self.student.email = 'aa@aa.ng'
1071        self.browser.open(self.student_path + '/start_clearance')
1072        self.browser.getControl(name="ac_series").value = '3'
1073        self.browser.getControl(name="ac_number").value = '4444444'
1074        self.browser.getControl("Start clearance now").click()
1075        self.assertMatches('...Activation code is invalid...',
1076                           self.browser.contents)
1077        self.browser.getControl(name="ac_series").value = self.existing_clrseries
1078        self.browser.getControl(name="ac_number").value = self.existing_clrnumber
1079        # Owner is Hans Wurst, AC can't be invalidated
1080        self.browser.getControl("Start clearance now").click()
1081        self.assertMatches('...You are not the owner of this access code...',
1082                           self.browser.contents)
1083        # Set the correct owner
1084        self.existing_clrac.owner = self.student_id
1085        self.browser.getControl("Start clearance now").click()
1086        self.assertMatches('...Clearance process has been started...',
1087                           self.browser.contents)
1088        self.browser.getControl(name="form.date_of_birth").value = '09/10/1961'
1089        self.browser.getControl("Save", index=0).click()
1090        # Student can view the clearance data
1091        self.browser.getLink("Clearance Data").click()
1092        # and go back to the edit form
1093        self.browser.getLink("Edit").click()
1094        self.browser.getControl("Save and request clearance").click()
1095       
1096        self.browser.getControl(name="ac_series").value = self.existing_clrseries
1097        self.browser.getControl(name="ac_number").value = self.existing_clrnumber
1098        self.browser.getControl("Request clearance now").click()
1099        self.assertMatches('...Clearance has been requested...',
1100                           self.browser.contents)
1101        # Student can't reopen clearance form after requesting clearance
1102        self.browser.open(self.student_path + '/cedit')
1103        self.assertMatches('...The requested form is locked...',
1104                           self.browser.contents)
1105        # Student can't add study level if not in state 'school fee paid'
1106        self.browser.open(self.student_path + '/studycourse/add')
1107        self.assertMatches('...The requested form is locked...',
1108                           self.browser.contents)
1109        # ... and must be transferred first
1110        IWorkflowInfo(self.student).fireTransition('clear')
1111        IWorkflowInfo(self.student).fireTransition('pay_first_school_fee')
1112        # Now students can add the current study level
1113        self.browser.getLink("Study Course").click()
1114        self.browser.getLink("Add course list").click()
1115        self.assertMatches('...Add current level 100 (Year 1)...',
1116                           self.browser.contents)
1117        self.browser.getControl("Create course list now").click()
1118        self.browser.getLink("100").click()
1119        self.browser.getLink("Add and remove courses").click()
1120        self.browser.getControl("Add course ticket").click()
1121        self.browser.getControl(name="form.course").value = ['COURSE1']
1122        self.browser.getControl("Add course ticket").click()
1123        self.assertMatches('...The ticket exists...',
1124                           self.browser.contents)
1125        self.student['studycourse'].current_level = 200
1126        self.browser.getLink("Study Course").click()
1127        self.browser.getLink("Add course list").click()
1128        self.assertMatches('...Add current level 200 (Year 2)...',
1129                           self.browser.contents)
1130        self.browser.getControl("Create course list now").click()
1131        self.browser.getLink("200").click()
1132        self.browser.getLink("Add and remove courses").click()
1133        self.browser.getControl("Add course ticket").click()
1134        self.browser.getControl(name="form.course").value = ['COURSE1']
1135        self.browser.getControl("Add course ticket").click()
1136        self.assertMatches('...Successfully added COURSE1...',
1137                           self.browser.contents)
1138        # Students can open the pdf course registration slip
1139        self.browser.open(self.student_path + '/studycourse/200')
1140        self.browser.getLink("Download course registration slip").click()
1141        self.assertEqual(self.browser.headers['Status'], '200 Ok')
1142        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
1143        # Students can remove course tickets
1144        self.browser.open(self.student_path + '/studycourse/200/edit')
1145        self.browser.getControl("Remove selected", index=0).click()
1146        self.assertTrue('No ticket selected' in self.browser.contents)
1147        ctrl = self.browser.getControl(name='val_id')
1148        ctrl.getControl(value='COURSE1').selected = True
1149        self.browser.getControl("Remove selected", index=0).click()
1150        self.assertTrue('Successfully removed' in self.browser.contents)
1151        self.browser.getControl("Register course list").click()
1152        self.assertTrue('Course list has been registered' in self.browser.contents)
1153        self.assertEqual(self.student.state, 'courses registered')
1154        return
1155
1156    def test_manage_payments(self):
1157        # Managers can add online school fee payment tickets
1158        # if certain requirements are met
1159        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
1160        self.browser.open(self.payments_student_path)
1161        self.browser.getControl("Add online payment ticket").click()
1162        self.browser.getControl(name="form.p_category").value = ['schoolfee']
1163        self.browser.getControl("Create ticket").click()
1164        self.assertMatches('...ticket created...',
1165                           self.browser.contents)
1166        ctrl = self.browser.getControl(name='val_id')
1167        value = ctrl.options[0]
1168        self.browser.getLink(value).click()
1169        self.assertMatches('...Amount Authorized...',
1170                           self.browser.contents)
1171        payment_url = self.browser.url
1172
1173        # The pdf payment receipt can't yet be opened
1174        self.browser.open(payment_url + '/payment_receipt.pdf')
1175        self.assertMatches('...Ticket not yet paid...',
1176                           self.browser.contents)
1177
1178        # The same payment (with same p_item, p_session and p_category)
1179        # can be initialized a second time if the former ticket is not yet paid.
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 = ['schoolfee']
1183        self.browser.getControl("Create ticket").click()
1184        self.assertMatches('...Payment ticket created...',
1185                           self.browser.contents)
1186
1187        # Managers can open the callback view which simulates a valid callback
1188        self.assertEqual(len(self.app['accesscodes']['SFE-0']),0)
1189        self.browser.open(payment_url)
1190        self.browser.getLink("Request callback").click()
1191        self.assertMatches('...Valid callback received...',
1192                          self.browser.contents)
1193
1194        # Callback can't be applied twice
1195        self.browser.open(payment_url + '/callback')
1196        self.assertMatches('...This ticket has already been paid...',
1197                          self.browser.contents)
1198
1199        # Now the first ticket is paid and no more ticket of same type
1200        # (with same p_item, p_session and p_category) can be added
1201        self.browser.open(self.payments_student_path)
1202        self.browser.getControl("Add online payment ticket").click()
1203        self.browser.getControl(name="form.p_category").value = ['schoolfee']
1204        self.browser.getControl("Create ticket").click()
1205        self.assertMatches(
1206            '...This type of payment has already been made...',
1207            self.browser.contents)
1208
1209        # Managers can open the pdf payment receipt
1210        self.browser.open(payment_url)
1211        self.browser.getLink("Download payment receipt").click()
1212        self.assertEqual(self.browser.headers['Status'], '200 Ok')
1213        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
1214
1215        # Managers can remove online school fee payment tickets
1216        self.browser.open(self.payments_student_path)
1217        self.browser.getControl("Remove selected").click()
1218        self.assertMatches('...No payment selected...', self.browser.contents)
1219        ctrl = self.browser.getControl(name='val_id')
1220        value = ctrl.options[0]
1221        ctrl.getControl(value=value).selected = True
1222        self.browser.getControl("Remove selected", index=0).click()
1223        self.assertTrue('Successfully removed' in self.browser.contents)
1224
1225        # Managers can add online clearance payment tickets
1226        self.browser.open(self.payments_student_path + '/addop')
1227        self.browser.getControl(name="form.p_category").value = ['clearance']
1228        self.browser.getControl("Create ticket").click()
1229        self.assertMatches('...ticket created...',
1230                           self.browser.contents)
1231
1232        # Managers can open the callback view which simulates a valid callback
1233        self.assertEqual(len(self.app['accesscodes']['CLR-0']),0)
1234        ctrl = self.browser.getControl(name='val_id')
1235        value = ctrl.options[1] # The clearance payment is the second in the table
1236        self.browser.getLink(value).click()
1237        self.browser.open(self.browser.url + '/callback')
1238        self.assertMatches('...Valid callback received...',
1239                          self.browser.contents)
1240        expected = '''...
1241        <td>
1242          Paid
1243        </td>...'''
1244        #import pdb; pdb.set_trace()
1245        self.assertMatches(expected,self.browser.contents)
1246        # The new CLR-0 pin has been created
1247        self.assertEqual(len(self.app['accesscodes']['CLR-0']),1)
1248        pin = self.app['accesscodes']['CLR-0'].keys()[0]
1249        ac = self.app['accesscodes']['CLR-0'][pin]
1250        ac.owner = self.student_id
1251        return
1252
1253    def test_student_payments(self):
1254        # Login
1255        self.browser.open(self.login_path)
1256        self.browser.getControl(name="form.login").value = self.student_id
1257        self.browser.getControl(name="form.password").value = 'spwd'
1258        self.browser.getControl("Login").click()
1259
1260        # Students can add online clearance payment tickets
1261        self.browser.open(self.payments_student_path + '/addop')
1262        self.browser.getControl(name="form.p_category").value = ['clearance']
1263        self.browser.getControl("Create ticket").click()
1264        self.assertMatches('...ticket created...',
1265                           self.browser.contents)
1266
1267        # Students can open the callback view which simulates a valid callback
1268        self.assertEqual(len(self.app['accesscodes']['CLR-0']),0)
1269        ctrl = self.browser.getControl(name='val_id')
1270        value = ctrl.options[0]
1271        self.browser.getLink(value).click()
1272        payment_url = self.browser.url
1273        self.browser.open(payment_url + '/callback')
1274        self.assertMatches('...Valid callback received...',
1275                          self.browser.contents)
1276        expected = '''...
1277        <td>
1278          Paid
1279        </td>...'''
1280        self.assertMatches(expected,self.browser.contents)
1281        # The new CLR-0 pin has been created
1282        self.assertEqual(len(self.app['accesscodes']['CLR-0']),1)
1283        pin = self.app['accesscodes']['CLR-0'].keys()[0]
1284        ac = self.app['accesscodes']['CLR-0'][pin]
1285        ac.owner = self.student_id
1286
1287        # Students can open the pdf payment receipt
1288        self.browser.open(payment_url + '/payment_receipt.pdf')
1289        self.assertEqual(self.browser.headers['Status'], '200 Ok')
1290        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
1291
1292        # The new CLR-0 pin can be used for starting clearance
1293        # but they have to upload a passport picture first
1294        # which is only possible in state admitted
1295        self.browser.open(self.student_path + '/change_portrait')
1296        self.assertMatches('...form is locked...',
1297                          self.browser.contents)
1298        IWorkflowInfo(self.student).fireTransition('admit')
1299        self.browser.open(self.student_path + '/change_portrait')
1300        pseudo_image = StringIO('I pretend to be a graphics file')
1301        ctrl = self.browser.getControl(name='passportuploadedit')
1302        file_ctrl = ctrl.mech_control
1303        file_ctrl.add_file(pseudo_image, filename='my_photo.jpg')
1304        self.browser.getControl(
1305            name='upload_passportuploadedit').click()
1306        self.browser.open(self.student_path + '/start_clearance')
1307        parts = pin.split('-')[1:]
1308        clrseries, clrnumber = parts
1309        self.browser.getControl(name="ac_series").value = clrseries
1310        self.browser.getControl(name="ac_number").value = clrnumber
1311        self.browser.getControl("Start clearance now").click()
1312        self.assertMatches('...Clearance process has been started...',
1313                           self.browser.contents)
1314
1315        # Students can add online school fee payment tickets
1316        self.browser.open(self.payments_student_path)
1317        self.browser.getControl("Add online payment ticket").click()
1318        self.browser.getControl(name="form.p_category").value = ['schoolfee']
1319        self.browser.getControl("Create ticket").click()
1320        self.assertMatches('...ticket created...',
1321                           self.browser.contents)
1322        ctrl = self.browser.getControl(name='val_id')
1323        value = ctrl.options[0]
1324        self.browser.getLink(value).click()
1325        self.assertMatches('...Amount Authorized...',
1326                           self.browser.contents)
1327
1328        # Students can open the callback view which simulates a valid callback
1329        self.assertEqual(len(self.app['accesscodes']['SFE-0']),0)
1330        self.browser.open(self.browser.url + '/callback')
1331        self.assertMatches('...Valid callback received...',
1332                          self.browser.contents)
1333
1334        # Students can remove only online payment tickets which have
1335        # not received a valid callback
1336        self.browser.open(self.payments_student_path)
1337        self.assertRaises(
1338            LookupError, self.browser.getControl, name='val_id')
1339        self.browser.open(self.payments_student_path + '/addop')
1340        self.browser.getControl(name="form.p_category").value = ['gown']
1341        self.browser.getControl("Create ticket").click()
1342        self.browser.open(self.payments_student_path)
1343        ctrl = self.browser.getControl(name='val_id')
1344        value = ctrl.options[0]
1345        ctrl.getControl(value=value).selected = True
1346        self.browser.getControl("Remove selected", index=0).click()
1347        self.assertTrue('Successfully removed' in self.browser.contents)
1348
1349        # The new SFE-0 pin can be used for starting course registration
1350        IWorkflowInfo(self.student).fireTransition('request_clearance')
1351        IWorkflowInfo(self.student).fireTransition('clear')
1352        self.browser.open(self.studycourse_student_path)
1353        self.browser.getLink('Start course registration').click()
1354        pin = self.app['accesscodes']['SFE-0'].keys()[0]
1355        parts = pin.split('-')[1:]
1356        sfeseries, sfenumber = parts
1357        self.browser.getControl(name="ac_series").value = sfeseries
1358        self.browser.getControl(name="ac_number").value = sfenumber
1359        self.browser.getControl("Start course registration now").click()
1360        self.assertMatches('...Course registration has been started...',
1361                           self.browser.contents)
1362        self.assertTrue(self.student.state == 'school fee paid')
1363        return
1364
1365    def test_manage_accommodation(self):
1366        # Managers can add online booking fee payment tickets and open the
1367        # callback view (see test_manage_payments)
1368        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
1369        self.browser.open(self.payments_student_path)
1370        self.browser.getControl("Add online payment ticket").click()
1371        self.browser.getControl(name="form.p_category").value = ['bed_allocation']
1372        # If student is not in accommodation session, payment cannot be processed
1373        self.app['configuration'].accommodation_session = 2011
1374        self.browser.getControl("Create ticket").click()
1375        self.assertMatches('...Your current session does not match...',
1376                           self.browser.contents)
1377        self.app['configuration'].accommodation_session = 2004
1378        self.browser.getControl("Add online payment ticket").click()
1379        self.browser.getControl(name="form.p_category").value = ['bed_allocation']
1380        self.browser.getControl("Create ticket").click()
1381        ctrl = self.browser.getControl(name='val_id')
1382        value = ctrl.options[0]
1383        self.browser.getLink(value).click()
1384        self.browser.open(self.browser.url + '/callback')
1385        # The new HOS-0 pin has been created
1386        self.assertEqual(len(self.app['accesscodes']['HOS-0']),1)
1387        pin = self.app['accesscodes']['HOS-0'].keys()[0]
1388        ac = self.app['accesscodes']['HOS-0'][pin]
1389        ac.owner = self.student_id
1390        parts = pin.split('-')[1:]
1391        sfeseries, sfenumber = parts
1392        # Managers can use HOS code and book a bed space with it
1393        self.browser.open(self.acco_student_path)
1394        self.browser.getLink("Book accommodation").click()
1395        self.assertMatches('...You are in the wrong...',
1396                           self.browser.contents)
1397        IWorkflowInfo(self.student).fireTransition('admit')
1398        # An existing HOS code can only be used if students
1399        # are in accommodation session
1400        self.student['studycourse'].current_session = 2003
1401        self.browser.getLink("Book accommodation").click()
1402        self.assertMatches('...Your current session does not match...',
1403                           self.browser.contents)
1404        self.student['studycourse'].current_session = 2004
1405        # All requirements are met and ticket can be created
1406        self.browser.getLink("Book accommodation").click()
1407        self.assertMatches('...Activation Code:...',
1408                           self.browser.contents)
1409        self.browser.getControl(name="ac_series").value = sfeseries
1410        self.browser.getControl(name="ac_number").value = sfenumber
1411        self.browser.getControl("Create bed ticket").click()
1412        self.assertMatches('...Hall 1, Block A, Room 101, Bed A...',
1413                           self.browser.contents)
1414        # Bed has been allocated
1415        bed1 = self.app['hostels']['hall-1']['hall-1_A_101_A']
1416        self.assertTrue(bed1.owner == self.student_id)
1417        # BedTicketAddPage is now blocked
1418        self.browser.getLink("Book accommodation").click()
1419        self.assertMatches('...You already booked a bed space...',
1420            self.browser.contents)
1421        # The bed ticket displays the data correctly
1422        self.browser.open(self.acco_student_path + '/2004')
1423        self.assertMatches('...Hall 1, Block A, Room 101, Bed A...',
1424                           self.browser.contents)
1425        self.assertMatches('...2004/2005...', self.browser.contents)
1426        self.assertMatches('...regular_male_fr...', self.browser.contents)
1427        self.assertMatches('...%s...' % pin, self.browser.contents)
1428        # Managers can relocate students if the student's bed_type has changed
1429        self.browser.getLink("Relocate student").click()
1430        self.assertMatches(
1431            "...Student can't be relocated...", self.browser.contents)
1432        self.student.sex = u'f'
1433        self.browser.getLink("Relocate student").click()
1434        self.assertMatches(
1435            "...Hall 1, Block A, Room 101, Bed B...", self.browser.contents)
1436        self.assertTrue(bed1.owner == NOT_OCCUPIED)
1437        bed2 = self.app['hostels']['hall-1']['hall-1_A_101_B']
1438        self.assertTrue(bed2.owner == self.student_id)
1439        self.assertTrue(self.student['accommodation'][
1440            '2004'].bed_type == u'regular_female_fr')
1441        # The payment object still shows the original payment item
1442        payment_id = self.student['payments'].keys()[0]
1443        payment = self.student['payments'][payment_id]
1444        self.assertTrue(payment.p_item == u'regular_male_fr')
1445        # Managers can relocate students if the bed's bed_type has changed
1446        bed1.bed_type = u'regular_female_fr'
1447        bed2.bed_type = u'regular_male_fr'
1448        notify(grok.ObjectModifiedEvent(bed1))
1449        notify(grok.ObjectModifiedEvent(bed2))
1450        self.browser.getLink("Relocate student").click()
1451        self.assertMatches(
1452            "...Student relocated...", self.browser.contents)
1453        self.assertMatches(
1454            "... Hall 1, Block A, Room 101, Bed A...", self.browser.contents)
1455        self.assertMatches(bed1.owner, self.student_id)
1456        self.assertMatches(bed2.owner, NOT_OCCUPIED)
1457        # Managers can't relocate students if bed is reserved
1458        self.student.sex = u'm'
1459        bed1.bed_type = u'regular_female_reserved'
1460        notify(grok.ObjectModifiedEvent(bed1))
1461        self.browser.getLink("Relocate student").click()
1462        self.assertMatches(
1463            "...Students in reserved beds can't be relocated...",
1464            self.browser.contents)
1465        # Managers can relocate students if booking has been cancelled but
1466        # other bed space has been manually allocated after cancellation
1467        old_owner = bed1.releaseBed()
1468        self.assertMatches(old_owner, self.student_id)
1469        bed2.owner = self.student_id
1470        self.browser.open(self.acco_student_path + '/2004')
1471        self.assertMatches(
1472            "...booking cancelled...", self.browser.contents)
1473        self.browser.getLink("Relocate student").click()
1474        # We didn't informed the catalog therefore the new owner is not found
1475        self.assertMatches(
1476            "...There is no free bed in your category regular_male_fr...",
1477            self.browser.contents)
1478        # Now we fire the event properly
1479        notify(grok.ObjectModifiedEvent(bed2))
1480        self.browser.getLink("Relocate student").click()
1481        self.assertMatches(
1482            "...Student relocated...", self.browser.contents)
1483        self.assertMatches(
1484            "... Hall 1, Block A, Room 101, Bed B...", self.browser.contents)
1485          # Managers can delete bed tickets
1486        self.browser.open(self.acco_student_path)
1487        ctrl = self.browser.getControl(name='val_id')
1488        value = ctrl.options[0]
1489        ctrl.getControl(value=value).selected = True
1490        self.browser.getControl("Remove selected", index=0).click()
1491        self.assertMatches('...Successfully removed...', self.browser.contents)
1492        # The bed has been properly released by the event handler
1493        self.assertMatches(bed1.owner, NOT_OCCUPIED)
1494        self.assertMatches(bed2.owner, NOT_OCCUPIED)
1495        return
1496
1497    def test_student_accommodation(self):
1498        # Login
1499        self.browser.open(self.login_path)
1500        self.browser.getControl(name="form.login").value = self.student_id
1501        self.browser.getControl(name="form.password").value = 'spwd'
1502        self.browser.getControl("Login").click()
1503
1504        # Students can add online booking fee payment tickets and open the
1505        # callback view (see test_manage_payments)
1506        self.browser.getLink("Payments").click()
1507        self.browser.getControl("Add online payment ticket").click()
1508        self.browser.getControl(name="form.p_category").value = ['bed_allocation']
1509        self.browser.getControl("Create ticket").click()
1510        ctrl = self.browser.getControl(name='val_id')
1511        value = ctrl.options[0]
1512        self.browser.getLink(value).click()
1513        self.browser.open(self.browser.url + '/callback')
1514        # The new HOS-0 pin has been created
1515        self.assertEqual(len(self.app['accesscodes']['HOS-0']),1)
1516        pin = self.app['accesscodes']['HOS-0'].keys()[0]
1517        ac = self.app['accesscodes']['HOS-0'][pin]
1518        ac.owner = u'Anybody'
1519        parts = pin.split('-')[1:]
1520        sfeseries, sfenumber = parts
1521
1522        # Students can use HOS code and book a bed space with it
1523        self.browser.open(self.acco_student_path)
1524        self.browser.getLink("Book accommodation").click()
1525        self.assertMatches('...You are in the wrong...',
1526                           self.browser.contents)
1527        IWorkflowInfo(self.student).fireTransition('admit')
1528        self.browser.getLink("Book accommodation").click()
1529        self.assertMatches('...Activation Code:...',
1530                           self.browser.contents)
1531        self.browser.getControl(name="ac_series").value = u'nonsense'
1532        self.browser.getControl(name="ac_number").value = sfenumber
1533        self.browser.getControl("Create bed ticket").click()
1534        self.assertMatches('...Activation code is invalid...',
1535                           self.browser.contents)
1536        self.browser.getControl(name="ac_series").value = sfeseries
1537        self.browser.getControl(name="ac_number").value = sfenumber
1538        self.browser.getControl("Create bed ticket").click()
1539        self.assertMatches('...You are not the owner of this access code...',
1540                           self.browser.contents)
1541        ac.owner = self.student_id
1542        self.browser.getControl(name="ac_series").value = sfeseries
1543        self.browser.getControl(name="ac_number").value = sfenumber
1544        self.browser.getControl("Create bed ticket").click()
1545        self.assertMatches('...Hall 1, Block A, Room 101, Bed A...',
1546                           self.browser.contents)
1547
1548        # Bed has been allocated
1549        bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
1550        self.assertTrue(bed.owner == self.student_id)
1551
1552        # BedTicketAddPage is now blocked
1553        self.browser.getLink("Book accommodation").click()
1554        self.assertMatches('...You already booked a bed space...',
1555            self.browser.contents)
1556
1557        # The bed ticket displays the data correctly
1558        self.browser.open(self.acco_student_path + '/2004')
1559        self.assertMatches('...Hall 1, Block A, Room 101, Bed A...',
1560                           self.browser.contents)
1561        self.assertMatches('...2004/2005...', self.browser.contents)
1562        self.assertMatches('...regular_male_fr...', self.browser.contents)
1563        self.assertMatches('...%s...' % pin, self.browser.contents)
1564
1565        # Students can open the pdf slip
1566        self.browser.open(self.browser.url + '/bed_allocation.pdf')
1567        self.assertEqual(self.browser.headers['Status'], '200 Ok')
1568        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
1569
1570        # Students can't relocate themselves
1571        self.assertFalse('Relocate' in self.browser.contents)
1572        relocate_path = self.acco_student_path + '/2004/relocate'
1573        self.assertRaises(
1574            Unauthorized, self.browser.open, relocate_path)
1575
1576        # Students can't the Remove button and check boxes
1577        self.browser.open(self.acco_student_path)
1578        self.assertFalse('Remove' in self.browser.contents)
1579        self.assertFalse('val_id' in self.browser.contents)
1580        return
1581
1582    def test_change_password_request(self):
1583        self.browser.open('http://localhost/app/changepw')
1584        self.browser.getControl(name="form.reg_number").value = '123'
1585        self.browser.getControl(name="form.email").value = 'aa@aa.ng'
1586        self.browser.getControl("Get login credentials").click()
1587        self.assertTrue('An email with' in self.browser.contents)
Note: See TracBrowser for help on using the repository browser.