source: main/waeup.aaue/trunk/src/waeup/aaue/students/tests/test_browser.py @ 14310

Last change on this file since 14310 was 14306, checked in by Henrik Bettermann, 8 years ago

Add AlumniRequestPasswordPage?.

  • Property svn:keywords set to Id
File size: 58.7 KB
Line 
1## $Id: test_browser.py 14306 2016-12-03 08:29:30Z 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##
18import os
19import shutil
20import tempfile
21import pytz
22import grok
23from StringIO import StringIO
24from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
25from zope.securitypolicy.interfaces import IPrincipalRoleManager
26from datetime import datetime, timedelta, date
27from mechanize import LinkNotFoundError
28from hurry.workflow.interfaces import IWorkflowState
29from zope.event import notify
30from zope.component.hooks import setSite, clearSite
31from zope.component import getUtility, createObject, queryUtility
32from zope.catalog.interfaces import ICatalog
33from waeup.kofa.app import University
34from waeup.kofa.interfaces import VALIDATED, PAID
35from waeup.kofa.students.tests.test_browser import StudentsFullSetup
36from waeup.kofa.students.accommodation import BedTicket
37from waeup.kofa.testing import FunctionalTestCase
38from waeup.kofa.authentication import LocalRoleSetEvent
39from waeup.kofa.browser.tests.test_pdf import samples_dir
40from waeup.kofa.applicants.container import ApplicantsContainer
41from waeup.aaue.testing import FunctionalLayer
42
43SAMPLE_IMAGE = os.path.join(os.path.dirname(__file__), 'test_image.jpg')
44
45
46UPLOAD_CSV_TEMPLATE = (
47    'matric_number,student_id,display_fullname,level,code,level_session,'
48    'score,ca\r\n'
49    '234,E1000000,Anna Tester,100,COURSE1,2004,%s,%s\r\n')
50
51class OfficerUITests(StudentsFullSetup):
52    # Tests for Student class views and pages
53
54    layer = FunctionalLayer
55
56    def login_as_lecturer(self):
57        self.app['users'].addUser('mrslecturer', 'mrslecturersecret')
58        self.app['users']['mrslecturer'].email = 'mrslecturer@foo.ng'
59        self.app['users']['mrslecturer'].title = u'Mercedes Benz'
60        # Add course ticket
61        studylevel = createObject(u'waeup.StudentStudyLevel')
62        studylevel.level = 100
63        studylevel.level_session = 2004
64        self.student['studycourse'].addStudentStudyLevel(
65            self.certificate, studylevel)
66        # Assign local Lecturer role for a certificate.
67        course = self.app['faculties']['fac1']['dep1'].courses['COURSE1']
68        prmlocal = IPrincipalRoleManager(course)
69        prmlocal.assignRoleToPrincipal('waeup.local.Lecturer', 'mrslecturer')
70        notify(LocalRoleSetEvent(
71            course, 'waeup.local.Lecturer', 'mrslecturer', granted=True))
72        # Login as lecturer.
73        self.browser.open(self.login_path)
74        self.browser.getControl(name="form.login").value = 'mrslecturer'
75        self.browser.getControl(
76            name="form.password").value = 'mrslecturersecret'
77        self.browser.getControl("Login").click()
78        # Store reused urls/paths
79        self.course_url = (
80            'http://localhost/app/faculties/fac1/dep1/courses/COURSE1')
81        self.edit_scores_url = '%s/edit_scores' % self.course_url
82        self.edit_prev_scores_url = '%s/edit_prev_scores' % self.course_url
83        # Set standard parameters
84        self.app['configuration'].current_academic_session = 2004
85        self.app['faculties']['fac1']['dep1'].score_editing_disabled = False
86        IWorkflowState(self.student).setState(VALIDATED)
87
88
89    def test_gpa_calculation(self):
90        studylevel = createObject(u'waeup.StudentStudyLevel')
91        studylevel.level = 100
92        studylevel.level_session = 2005
93        self.student['studycourse'].entry_mode = 'ug_ft'
94        self.student['studycourse'].addStudentStudyLevel(
95            self.certificate, studylevel)
96        # First course has been added automatically.
97        # Set score.
98        studylevel['COURSE1'].score = 35
99        studylevel['COURSE1'].ca = 20
100        # GPA is 3.0.
101        self.assertEqual(studylevel.gpa_params[0], 3.0)
102        courseticket = createObject('waeup.CourseTicket')
103        courseticket.code = 'ANYCODE'
104        courseticket.title = u'Any TITLE'
105        courseticket.credits = 13
106        courseticket.score = 44
107        courseticket.ca = 22
108        courseticket.semester = 1
109        courseticket.dcode = u'ANYDCODE'
110        courseticket.fcode = u'ANYFCODE'
111        studylevel['COURSE2'] = courseticket
112        # total credits
113        self.assertEqual(self.student['studycourse']['100'].gpa_params[1], 23)
114        # weigheted credits = 3 * 10 + 4 * 13
115        self.assertEqual(self.student['studycourse']['100'].gpa_params[2], 82.0)
116        # sgpa = 82 / 23
117        self.assertEqual(
118            self.student['studycourse']['100'].gpa_params[0], 3.565)
119        # imported gpa values override calculated values
120        studylevel.imported_gpa = 4.3
121        studylevel.imported_cgpa = 5.4
122        self.assertEqual(self.student['studycourse']['100'].gpa_params[0], 4.3)
123        self.assertEqual(
124            self.student['studycourse']['100'].cumulative_params[0], 5.4)
125        self.assertEqual(self.student['studycourse']['100'].gpa, 4.3)
126        self.student['studycourse'].imported_cgpa = 6.6
127        self.assertEqual(
128            self.student['studycourse'].getTranscriptData()[1], 6.6)
129        return
130
131    def test_grade_weight(self):
132        studylevel = createObject(u'waeup.StudentStudyLevel')
133        studylevel.level = 100
134        studylevel.level_session = 2005
135        self.student['studycourse'].entry_mode = 'ug_ft'
136        self.student['studycourse'].addStudentStudyLevel(
137            self.certificate, studylevel)
138        studylevel['COURSE1'].score = 42
139        studylevel['COURSE1'].ca = 0
140        courseticket = createObject('waeup.CourseTicket')
141        self.assertEqual(studylevel['COURSE1'].weight, 1)
142        self.assertEqual(studylevel['COURSE1'].grade, 'E')
143        self.student['studycourse'].entry_session = 2015
144        self.assertEqual(studylevel['COURSE1'].weight, 0)
145        self.assertEqual(studylevel['COURSE1'].grade, 'F')
146        studylevel['COURSE1'].score = 45
147        self.assertEqual(studylevel['COURSE1'].weight, 2)
148        self.assertEqual(studylevel['COURSE1'].grade, 'D')
149        return
150
151    def test_manage_payments(self):
152        # Add missing configuration data
153        self.app['configuration']['2004'].gown_fee = 150.0
154        self.app['configuration']['2004'].transfer_fee = 90.0
155        self.app['configuration']['2004'].booking_fee = 150.0
156        self.app['configuration']['2004'].maint_fee = 180.0
157        self.app['configuration']['2004'].late_fee = 80.0
158
159        # Managers can add online payment tickets
160        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
161        self.browser.open(self.payments_path)
162        self.browser.getLink("Add current session payment ticket").click()
163        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
164        self.browser.getControl("Create ticket").click()
165        self.assertMatches('...Wrong state...',
166                           self.browser.contents)
167        IWorkflowState(self.student).setState('cleared')
168        self.browser.open(self.payments_path + '/addop')
169        self.app['configuration']['2004'].clearance_fee = 666.0
170        self.browser.getControl(name="form.p_category").value = ['clearance_incl']
171        self.browser.getControl("Create ticket").click()
172        ctrl = self.browser.getControl(name='val_id')
173        cpt_value = ctrl.options[0]
174        # School fee payment ticket can be added ...
175        self.student['studycourse'].certificate.school_fee_1 = 6666.0
176        self.student.nationality = u'NG'
177        self.browser.open(self.payments_path + '/addop')
178        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
179        self.browser.getControl("Create ticket").click()
180        self.assertMatches('...ticket created...',
181                           self.browser.contents)
182        # ... but not paid through the query_history page.
183        ctrl = self.browser.getControl(name='val_id')
184        sfpt_value = ctrl.options[1]
185        self.student['studycourse'].entry_session = 2013
186        self.browser.open(self.payments_path + '/' + sfpt_value)
187        self.browser.getLink("Query eTranzact History").click()
188        self.assertMatches('...alert-danger">Please pay acceptance fee first...',
189                           self.browser.contents)
190        # If clearance/acceptance fee is paid ...
191        self.student['payments'][cpt_value].approveStudentPayment()
192        self.browser.getLink("Query eTranzact History").click()
193        # ... query_history page is accessible.
194        self.assertMatches(
195            '...<h1 class="kofa-content-label">Requery eTranzact History</h1>...',
196            self.browser.contents)
197        # Managers can open school fee payment slip
198        self.browser.open(self.payments_path + '/' + sfpt_value)
199        self.browser.getLink("Download payment slip").click()
200        self.assertEqual(self.browser.headers['Status'], '200 Ok')
201        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
202        # If school fee ticket is paid, the student is automatically set to
203        # school fee paid...
204        ticket = self.student['payments'][sfpt_value].approveStudentPayment()
205        self.assertEqual(self.student.state, 'school fee paid')
206        # ... no further school fee ticket can be added.
207        self.browser.open(self.payments_path + '/addop')
208        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
209        self.browser.getControl("Create ticket").click()
210        self.assertMatches('...Wrong state...',
211                           self.browser.contents)
212        self.browser.open(self.payments_path + '/addop')
213        self.browser.getControl(name="form.p_category").value = ['late_registration']
214        self.browser.getControl("Create ticket").click()
215        self.assertMatches('...ticket created...',
216                           self.browser.contents)
217        return
218
219    def test_for_instalment_payments(self):
220
221        configuration_1 = createObject('waeup.SessionConfiguration')
222        configuration_1.academic_session = 2015
223        self.app['configuration'].addSessionConfiguration(configuration_1)
224        self.student['studycourse'].certificate.study_mode = 'ug_pt'
225        self.student['studycourse'].certificate.school_fee_1 = 6666.0
226        self.app['configuration']['2015'].union_fee = 1250.0
227        self.app['configuration']['2015'].welfare_fee = 750.0
228        self.student.nationality = u'NG'
229        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
230        self.browser.open(self.payments_path + '/addop')
231        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
232        self.browser.getControl("Create ticket").click()
233        self.assertTrue(
234            'Part-time students are not allowed' in self.browser.contents)
235        self.student['studycourse'].certificate.study_mode = 'ug_ft'
236        self.browser.open(self.payments_path + '/addop')
237        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
238        self.browser.getControl("Create ticket").click()
239        self.assertTrue('You are not allowed to pay by instalments.'
240            in self.browser.contents)
241        IWorkflowState(self.student).setState('cleared')
242        self.student['studycourse'].entry_session = 2015
243        self.student['studycourse'].current_session = 2015
244        self.browser.open(self.payments_path + '/addop')
245        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
246        self.browser.getControl("Create ticket").click()
247        self.assertTrue('ticket created' in self.browser.contents)
248        # We can't add the 2nd instalment ticket because the
249        # first one has not yet been approved.
250        #self.browser.open(self.payments_path + '/addop')
251        #self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
252        #self.browser.getControl("Create ticket").click()
253        #self.assertMatches('...1st school fee instalment has not yet been paid...',
254        #                   self.browser.contents)
255        # Ok, then we approve the first instalment ...
256        self.browser.open(self.payments_path)
257        ctrl = self.browser.getControl(name='val_id')
258        p_id = ctrl.options[0]
259        self.browser.open(self.payments_path + '/' + p_id + '/approve')
260        # ... add the second instalment ...
261        self.browser.open(self.payments_path + '/addop')
262        self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
263        self.browser.getControl("Create ticket").click()
264        self.assertTrue('ticket created' in self.browser.contents)
265        # ... approve the second instalment ...
266        ctrl = self.browser.getControl(name='val_id')
267        p_id = ctrl.options[1]
268        self.browser.open(self.payments_path + '/' + p_id + '/approve')
269        self.assertEqual(self.student['payments'].values()[0].p_category, 'schoolfee_1')
270        self.assertEqual(self.student['payments'].values()[1].p_category, 'schoolfee_2')
271        # (6666-250)/2 + 1250 + 750 - 500 + 250
272        self.assertEqual(self.student['payments'].values()[0].amount_auth, 4958.0)
273        # (6666-250)/2 + 250
274        self.assertEqual(self.student['payments'].values()[1].amount_auth, 3458.0)
275        # The  two payments belong to the same session and level.
276        self.assertEqual(self.student['payments'].values()[0].p_session, 2015)
277        self.assertEqual(self.student['payments'].values()[0].p_level, 100)
278        self.assertEqual(self.student['payments'].values()[1].p_session, 2015)
279        self.assertEqual(self.student['payments'].values()[1].p_level, 100)
280
281        # Returning student
282        configuration_2 = createObject('waeup.SessionConfiguration')
283        configuration_2.academic_session = 2016
284        self.app['configuration'].addSessionConfiguration(configuration_2)
285        self.student['studycourse'].certificate.school_fee_2 = 5666.0
286        self.app['configuration']['2016'].union_fee = 1250.0
287        self.app['configuration']['2016'].welfare_fee = 750.0
288        self.student.father_name = u'Albert'
289        IWorkflowState(self.student).setState('returning')
290        self.browser.open(self.payments_path + '/addop')
291        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
292        self.browser.getControl("Create ticket").click()
293        self.browser.open(self.payments_path + '/addop')
294        self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
295        self.browser.getControl("Create ticket").click()
296        # Student is still in the first  session.
297        self.assertTrue('This type of payment' in self.browser.contents)
298        self.browser.open(self.payments_path)
299        ctrl = self.browser.getControl(name='val_id')
300        p_id = ctrl.options[2]
301        self.browser.open(self.payments_path + '/' + p_id + '/approve')
302        self.browser.open(self.payments_path + '/addop')
303        self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
304        self.browser.getControl("Create ticket").click()
305        self.assertTrue('ticket created' in self.browser.contents)
306        # (5666-250)/2 + 1250 + 750 - 500 + 250
307        self.assertEqual(self.student['payments'].values()[2].amount_auth, 4458.0)
308        # (5666-250)/2 + 250
309        self.assertEqual(self.student['payments'].values()[3].amount_auth, 2958.0)
310        # The last two payments belong to the same session and level.
311        self.assertEqual(self.student['payments'].values()[2].p_session, 2016)
312        self.assertEqual(self.student['payments'].values()[2].p_level, 200)
313        self.assertEqual(self.student['payments'].values()[3].p_session, 2016)
314        self.assertEqual(self.student['payments'].values()[3].p_level, 200)
315        return
316
317    def test_manage_payments_bypass_ac_creation(self):
318        self.student['studycourse'].certificate.school_fee_1 = 6666.0
319        self.student.nationality = u'NG'
320        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
321        self.browser.open(self.payments_path)
322        IWorkflowState(self.student).setState('cleared')
323        self.browser.getLink("Add current session payment ticket").click()
324        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
325        self.browser.getControl("Create ticket").click()
326        ctrl = self.browser.getControl(name='val_id')
327        value = ctrl.options[0]
328        self.browser.getLink(value).click()
329        payment_url = self.browser.url
330        logfile = os.path.join(
331            self.app['datacenter'].storage, 'logs', 'students.log')
332        # The ticket can be found in the payments_catalog
333        cat = queryUtility(ICatalog, name='payments_catalog')
334        results = list(cat.searchResults(p_state=('unpaid', 'unpaid')))
335        self.assertTrue(len(results), 1)
336        self.assertTrue(results[0] is self.student['payments'][value])
337        # Managers can approve the payment
338        self.browser.open(payment_url)
339        self.browser.getLink("Approve payment").click()
340        self.assertMatches('...Payment approved...',
341                          self.browser.contents)
342        # Approval is logged in students.log ...
343        logcontent = open(logfile).read()
344        self.assertTrue(
345            'zope.mgr - students.browser.OnlinePaymentApproveView '
346            '- E1000000 - schoolfee_incl payment approved'
347            in logcontent)
348        # ... and in payments.log
349        logfile = os.path.join(
350            self.app['datacenter'].storage, 'logs', 'payments.log')
351        logcontent = open(logfile).read()
352        self.assertTrue(
353            '"zope.mgr",E1000000,%s,schoolfee_incl,6666.0,AP,,,,,,\n' % value
354            in logcontent)
355        # Student is in state school fee paid, no activation
356        # code was necessary.
357        self.assertEqual(self.student.state, 'school fee paid')
358        self.assertEqual(len(self.app['accesscodes']['SFE-0']),0)
359        return
360
361    def test_scores_csv_upload_available(self):
362        # lecturers can upload a CSV file to set values.
363        self.login_as_lecturer()
364        # set value to change from
365        self.student['studycourse']['100']['COURSE1'].score = 55
366        self.browser.open(self.edit_scores_url)
367        upload_ctrl = self.browser.getControl(name='uploadfile:file')
368        upload_file = StringIO(UPLOAD_CSV_TEMPLATE % ('65','22'))
369        upload_ctrl.add_file(upload_file, 'text/csv', 'myscores.csv')
370        self.browser.getControl("Update editable scores from").click()
371        # value changed
372        self.assertEqual(
373            self.student['studycourse']['100']['COURSE1'].score, 65)
374        self.assertEqual(
375            self.student['studycourse']['100']['COURSE1'].ca, 22)
376
377    def test_scores_previous_session(self):
378        # lecturers can download a CSV file to set values.
379        self.login_as_lecturer()
380        self.student['studycourse']['100']['COURSE1'].score = 55
381        self.browser.open(self.edit_prev_scores_url)
382        self.assertTrue('No student found' in self.browser.contents)
383        self.student['studycourse']['100'].level_session = 2003
384        notify(grok.ObjectModifiedEvent(self.student['studycourse']['100']['COURSE1']))
385        self.browser.open(self.edit_prev_scores_url)
386        self.browser.getLink("Download csv file").click()
387        self.assertEqual(self.browser.headers['Status'], '200 Ok')
388        self.assertEqual(self.browser.headers['Content-Type'],
389                         'text/csv; charset=UTF-8')
390        self.assertEqual(self.browser.contents, 'matric_number,student_id,'
391            'level,code,level_session,ca,score\r\n234,E1000000,'
392            '100,COURSE1,2003,,55\r\n')
393        self.browser.open(self.edit_prev_scores_url)
394        upload_ctrl = self.browser.getControl(name='uploadfile:file')
395        upload_file = StringIO(UPLOAD_CSV_TEMPLATE % ('65','22'))
396        upload_ctrl.add_file(upload_file, 'text/csv', 'myscores.csv')
397        self.browser.getControl("Update editable scores from").click()
398        # value changed
399        self.assertEqual(
400            self.student['studycourse']['100']['COURSE1'].score, 65)
401        self.assertEqual(
402            self.student['studycourse']['100']['COURSE1'].ca, 22)
403
404    def test_lecturers_can_download_course_tickets(self):
405        # A course ticket slip can be downloaded
406        self.login_as_lecturer()
407        pdf_url = '%s/coursetickets.pdf' % self.course_url
408        self.browser.open(pdf_url)
409        self.assertEqual(self.browser.headers['Status'], '200 Ok')
410        self.assertEqual(
411            self.browser.headers['Content-Type'], 'application/pdf')
412        path = os.path.join(samples_dir(), 'coursetickets.pdf')
413        open(path, 'wb').write(self.browser.contents)
414        print "Sample PDF coursetickets.pdf written to %s" % path
415
416    def test_transcripts(self):
417        studylevel = createObject(u'waeup.StudentStudyLevel')
418        studylevel.level = 100
419        studylevel.level_session = 2005
420        self.student['studycourse'].entry_mode = 'ug_ft'
421        self.student['studycourse'].addStudentStudyLevel(
422            self.certificate, studylevel)
423        studylevel2 = createObject(u'waeup.StudentStudyLevel')
424        studylevel2.level = 200
425        studylevel2.level_session = 2006
426        self.student['studycourse']['100']['COURSE1'].score = 33 # no carry-over!
427        self.student['studycourse']['100']['COURSE1'].ca = 22
428        self.student['studycourse'].addStudentStudyLevel(
429            self.certificate, studylevel2)
430        # Add second course (COURSE has been added automatically)
431        courseticket = createObject('waeup.CourseTicket')
432        courseticket.code = 'ANYCODE'
433        courseticket.title = u'Any TITLE'
434        courseticket.credits = 13
435        courseticket.score = 55
436        courseticket.ca = 11
437        courseticket.semester = 1
438        courseticket.dcode = u'ANYDCODE'
439        courseticket.fcode = u'ANYFCODE'
440        self.student['studycourse']['200']['COURSE2'] = courseticket
441        self.assertEqual(self.student['studycourse']['100'].gpa_params_rectified[0], 3.0)
442        self.assertEqual(self.student['studycourse']['200'].gpa_params_rectified[0], 4.0)
443        # Get transcript data
444        td = self.student['studycourse'].getTranscriptData()
445        self.assertEqual(td[0][0]['level_key'], '100')
446        self.assertEqual(td[0][0]['sgpa'], 3.0)
447        self.assertEqual(td[0][0]['level'].level, 100)
448        self.assertEqual(td[0][0]['level'].level_session, 2005)
449        self.assertEqual(td[0][0]['tickets_1'][0].code, 'COURSE1')
450        self.assertEqual(td[0][1]['level_key'], '200')
451        self.assertEqual(td[0][1]['sgpa'], 4.0)
452        self.assertEqual(td[0][1]['level'].level, 200)
453        self.assertEqual(td[0][1]['level'].level_session, 2006)
454        self.assertEqual(td[0][1]['tickets_1'][0].code, 'ANYCODE')
455        self.assertEqual(td[1], 3.57)
456        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
457        self.browser.open(self.student_path + '/studycourse/transcript')
458        self.assertEqual(self.browser.headers['Status'], '200 Ok')
459        self.assertTrue('Transcript' in self.browser.contents)
460        # Officers can open the pdf transcript
461        self.browser.open(self.student_path + '/studycourse/transcript.pdf')
462        self.assertEqual(self.browser.headers['Status'], '200 Ok')
463        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
464        path = os.path.join(samples_dir(), 'transcript.pdf')
465        open(path, 'wb').write(self.browser.contents)
466        print "Sample PDF transcript.pdf written to %s" % path
467
468    def test_payment_disabled(self):
469        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
470        self.browser.open(self.payments_path)
471        IWorkflowState(self.student).setState('cleared')
472        self.browser.getLink("Add current session payment ticket").click()
473        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
474        self.browser.getControl("Create ticket").click()
475        self.assertMatches('...ticket created...', self.browser.contents)
476        self.app['configuration']['2004'].payment_disabled = ['sf_all']
477        self.browser.getLink("Add current session payment ticket").click()
478        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
479        self.browser.getControl("Create ticket").click()
480        self.assertMatches('...This category of payments has been disabled...',
481                           self.browser.contents)
482
483        self.app['configuration']['2004'].payment_disabled = ['sf_pt']
484        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
485        self.browser.getControl("Create ticket").click()
486        self.assertMatches('...ticket created...', self.browser.contents)
487        self.certificate.study_mode = 'ug_pt'
488        self.browser.getLink("Add current session payment ticket").click()
489        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
490        self.browser.getControl("Create ticket").click()
491        self.assertMatches('...This category of payments has been disabled...',
492                           self.browser.contents)
493
494        self.app['configuration']['2004'].payment_disabled = ['sf_pg']
495        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
496        self.browser.getControl("Create ticket").click()
497        self.assertMatches('...ticket created...', self.browser.contents)
498        self.certificate.study_mode = 'special_pg_ft'
499        self.browser.getLink("Add current session payment ticket").click()
500        self.browser.getControl(name="form.p_category").value = ['schoolfee']
501        self.browser.getControl("Create ticket").click()
502        self.assertMatches('...This category of payments has been disabled...',
503                           self.browser.contents)
504        return
505
506class StudentUITests(StudentsFullSetup):
507    """Tests for customized student class views and pages
508    """
509
510    layer = FunctionalLayer
511
512    def setUp(self):
513        super(StudentUITests, self).setUp()
514
515        bedticket = BedTicket()
516        bedticket.booking_session = 2004
517        bedticket.bed_type = u'any bed type'
518        bedticket.bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
519        bedticket.bed_coordinates = u'My bed coordinates'
520        self.student['accommodation'].addBedTicket(bedticket)
521
522    def test_maintenance_fee_payment(self):
523        self.certificate.study_mode = 'ug_ft'
524        self.student['studycourse'].entry_session = 2013
525        self.student.nationality = u'NG'
526        IWorkflowState(self.student).setState('cleared')
527        self.browser.open(self.login_path)
528        self.browser.getControl(name="form.login").value = self.student_id
529        self.browser.getControl(name="form.password").value = 'spwd'
530        self.browser.getControl("Login").click()
531        self.browser.open(self.student_path + '/payments')
532        self.browser.getLink("Add current session payment ticket").click()
533        self.browser.getControl(name="form.p_category").value = ['hostel_maintenance']
534        self.browser.getControl("Create ticket").click()
535        self.assertTrue('ticket created' in self.browser.contents)
536        value = self.student['payments'].keys()[0]
537        self.browser.getLink(value).click()
538        self.assertTrue('<span>My bed coordinates</span>' in self.browser.contents)
539        self.assertEqual(self.student['payments'][value].amount_auth, 876.0)
540        return
541
542    def test_student_schoolfee_payments(self):
543        configuration_1 = createObject('waeup.SessionConfiguration')
544        configuration_1.academic_session = 2016
545        self.app['configuration'].addSessionConfiguration(configuration_1)
546        self.certificate.study_mode = 'ug_ft'
547        self.student['studycourse'].entry_session = 2016
548        self.student['studycourse'].current_session = 2016
549        self.student['studycourse'].entry_mode = 'ug_ft'
550        self.student['studycourse'].certificate.school_fee_1 = 50250.0
551        self.app['configuration']['2016'].union_fee = 1250.0
552        self.app['configuration']['2016'].welfare_fee = 750.0
553        self.app['configuration']['2016'].id_card_fee = 350.0
554        self.student.nationality = u'NG'
555        # Login
556        IWorkflowState(self.student).setState('cleared')
557        self.browser.open(self.login_path)
558        self.browser.getControl(name="form.login").value = self.student_id
559        self.browser.getControl(name="form.password").value = 'spwd'
560        self.browser.getControl("Login").click()
561        # Test school fee payments
562        self.browser.open(self.student_path + '/payments')
563        self.browser.getLink("Add current session payment ticket").click()
564        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
565        self.browser.getControl("Create ticket").click()
566        self.assertTrue('ticket created' in self.browser.contents)
567        value = self.student['payments'].keys()[0]
568        self.browser.getLink(value).click()
569        self.assertTrue('Amount Authorized' in self.browser.contents)
570        # 50250 + 1000 + 500 + 100 = 51850
571        self.assertEqual(self.student['payments'][value].amount_auth, 51850.0)
572        self.browser.open(self.browser.url + '/payment_slip.pdf')
573        self.assertEqual(self.browser.headers['Status'], '200 Ok')
574        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
575        path = os.path.join(samples_dir(), 'payment_slip.pdf')
576        open(path, 'wb').write(self.browser.contents)
577        print "Sample PDF payment_slip.pdf written to %s" % path
578        # Another school fee payment cannot be added
579        self.student['payments'][value].approve()
580        self.browser.open(self.student_path + '/payments')
581        self.browser.getLink("Add current session payment ticket").click()
582        self.browser.getControl(name="form.p_category").value = ['schoolfee']
583        self.browser.getControl("Create ticket").click()
584        self.assertTrue(
585            'You must choose a payment which includes additional fees'
586            in self.browser.contents)
587        return
588
589    def test_late_registration(self):
590        # Login
591        delta = timedelta(days=10)
592        self.app['configuration'][
593            '2004'].coursereg_deadline = datetime.now(pytz.utc) - delta
594        IWorkflowState(self.student).setState('school fee paid')
595        # Current session is 2004. Here we test course registration for
596        # returning students.
597        self.student['studycourse'].entry_session = 2003
598        self.browser.open(self.login_path)
599        self.browser.getControl(name="form.login").value = self.student_id
600        self.browser.getControl(name="form.password").value = 'spwd'
601        self.browser.getControl("Login").click()
602        self.browser.open(self.payments_path)
603        self.browser.open(self.payments_path + '/addop')
604        self.browser.getControl(name="form.p_category").value = ['late_registration']
605        self.browser.getControl("Create ticket").click()
606        self.assertMatches('...ticket created...',
607                           self.browser.contents)
608        self.browser.getLink("Study Course").click()
609        self.browser.getLink("Add course list").click()
610        self.assertMatches('...Add current level 100 (Year 1)...',
611                           self.browser.contents)
612        self.browser.getControl("Create course list now").click()
613        self.student['studycourse']['100']['COURSE1'].score = 67
614        self.browser.getLink("100").click()
615        # Course results can't be seen
616        self.assertFalse('<td>67</td>' in self.browser.contents)
617        self.browser.getLink("Edit course list").click()
618        self.assertFalse('<td>67</td>' in self.browser.contents)
619        self.browser.getControl("Register course list").click()
620        self.assertTrue('Course registration has ended. Please pay' in self.browser.contents)
621        self.student['payments'].values()[0].approve()
622        self.browser.getControl("Register course list").click()
623        self.assertTrue('Course list has been registered' in self.browser.contents)
624        self.assertEqual(self.student.state, 'courses registered')
625        # Reset student and check if fresh students are always allowed to
626        # register courses.
627        self.student['studycourse'].entry_session = 2004
628        del self.student['payments'][self.student['payments'].keys()[0]]
629        IWorkflowState(self.student).setState('school fee paid')
630        self.browser.open(self.studycourse_path + '/100/edit')
631        self.browser.getControl("Register course list").click()
632        self.assertTrue('Course list has been registered' in self.browser.contents)
633        return
634
635
636    def deactivated_test_student_course_registration(self):
637        # Add more courses
638        self.course2 = createObject('waeup.Course')
639        self.course2.code = 'COURSE2'
640        self.course2.semester = 2
641        self.course2.credits = 10
642        self.course2.passmark = 40
643        self.app['faculties']['fac1']['dep1'].courses.addCourse(
644            self.course2)
645        self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCertCourse(
646            self.course2, level=100)
647        self.course3 = createObject('waeup.Course')
648        self.course3.code = 'COURSE3'
649        self.course3.semester = 3
650        self.course3.credits = 10
651        self.course3.passmark = 40
652        self.app['faculties']['fac1']['dep1'].courses.addCourse(
653            self.course3)
654        self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCertCourse(
655            self.course3, level=100)
656
657        # Login as student
658        self.browser.open(self.login_path)
659        IWorkflowState(self.student).setState('school fee paid')
660        self.browser.open(self.login_path)
661        self.browser.getControl(name="form.login").value = self.student_id
662        self.browser.getControl(name="form.password").value = 'spwd'
663        self.browser.getControl("Login").click()
664        # Students can add the current study level
665        self.browser.getLink("Study Course").click()
666        self.browser.getLink("Add course list").click()
667        self.assertMatches('...Add current level 100 (Year 1)...',
668                           self.browser.contents)
669        self.browser.getControl("Create course list now").click()
670        # Student has not paid second instalment, therefore a level
671        # with two course ticket was created (semester 1 and combined)
672        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 2)
673        self.browser.getLink("100").click()
674        self.browser.getLink("Edit course list").click()
675        self.browser.getControl("Add course ticket").click()
676        # Student can't add second semester course
677        self.assertTrue('<option value="COURSE1">' in self.browser.contents)
678        self.assertTrue('<option value="COURSE3">' in self.browser.contents)
679        self.assertFalse('<option value="COURSE2">' in self.browser.contents)
680
681        # Let's remove level and see what happens after 2nd instalment payment
682        del(self.student['studycourse']['100'])
683        payment2 = createObject('waeup.StudentOnlinePayment')
684        payment2.p_category = u'schoolfee_2'
685        payment2.p_session = self.student.current_session
686        self.student['payments']['anykey'] = payment2
687        self.browser.open(self.studycourse_path)
688        self.browser.getLink("Add course list").click()
689        self.browser.getControl("Create course list now").click()
690        # Still only 2 tickets have been created since payment ticket
691        # was not paid
692        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 2)
693        payment2.p_state = u'paid'
694        del(self.student['studycourse']['100'])
695        self.browser.open(self.studycourse_path)
696        self.browser.getLink("Add course list").click()
697        self.browser.getControl("Create course list now").click()
698        # Now 2nd semester course has been added
699        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 3)
700        # Student can add second semester course
701        self.browser.getLink("100").click()
702        self.browser.getLink("Edit course list").click()
703        self.browser.getControl("Add course ticket").click()
704        self.assertTrue('<option value="COURSE1">' in self.browser.contents)
705        self.assertTrue('<option value="COURSE2">' in self.browser.contents)
706        self.assertTrue('<option value="COURSE3">' in self.browser.contents)
707        return
708
709    def test_set_matric_number(self):
710        #payment = createObject('waeup.StudentOnlinePayment')
711        #payment.p_category = u'concessional'
712        #payment.p_id = u'anyid'
713        #payment.p_state = u'paid'
714        #self.student['payments']['anykey'] = payment
715        # Login as student
716        self.browser.open(self.login_path)
717        IWorkflowState(self.student).setState('school fee paid')
718        self.browser.open(self.login_path)
719        self.browser.getControl(name="form.login").value = self.student_id
720        self.browser.getControl(name="form.password").value = 'spwd'
721        self.browser.getControl("Login").click()
722        self.assertRaises(
723            LinkNotFoundError,
724            self.browser.getLink, 'Get Matriculation Number')
725        self.student.matric_number = None
726        site = grok.getSite()
727        site['configuration'].next_matric_integer = 1
728        self.student['studycourse'].certificate.study_mode = 'ug_pt'
729        self.browser.open(self.student_path)
730        self.assertRaises(
731            LinkNotFoundError,
732            self.browser.getLink, 'Download matriculation number slip')
733        self.browser.getLink("Get Matriculation Number").click()
734        self.assertTrue('Matriculation number PTP/fac1/dep1/04/00001 assigned.'
735            in self.browser.contents)
736        self.assertEqual(self.student.matric_number, 'PTP/fac1/dep1/04/00001')
737        self.assertRaises(
738            LinkNotFoundError,
739            self.browser.getLink, 'Get Matriculation Number')
740        # Setting matric number is logged.
741        logfile = os.path.join(
742            self.app['datacenter'].storage, 'logs', 'students.log')
743        logcontent = open(logfile).read()
744        self.assertTrue('E1000000 - waeup.aaue.students.browser.StudentGetMatricNumberPage - '
745                        'E1000000 - PTP/fac1/dep1/04/00001 assigned' in logcontent)
746        # Matric Number Slip can be downloaded
747        self.browser.getLink("Download matriculation number slip").click()
748        self.assertEqual(self.browser.headers['Status'], '200 Ok')
749        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
750        path = os.path.join(samples_dir(), 'matric_number_slip.pdf')
751        open(path, 'wb').write(self.browser.contents)
752        print "Sample PDF matric_number_slip.pdf written to %s" % path
753        return
754
755    def test_personal_data_slip(self):
756        # Login as student
757        self.browser.open(self.login_path)
758        IWorkflowState(self.student).setState('school fee paid')
759        self.browser.open(self.login_path)
760        self.browser.getControl(name="form.login").value = self.student_id
761        self.browser.getControl(name="form.password").value = 'spwd'
762        self.browser.getControl("Login").click()
763        self.browser.getLink("Personal Data").click()
764        self.assertRaises(
765            LinkNotFoundError,
766            self.browser.getLink, 'Download personal data slip')
767        self.student.father_name = u'Rudolf'
768        self.browser.open(self.personal_path)
769        self.browser.getLink("Download personal data slip").click()
770        self.assertEqual(self.browser.headers['Status'], '200 Ok')
771        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
772        path = os.path.join(samples_dir(), 'personal_data_slip.pdf')
773        open(path, 'wb').write(self.browser.contents)
774        print "Sample PDF personal_data_slip.pdf written to %s" % path
775        return
776
777    def test_student_course_registration(self):
778        IWorkflowState(self.student).setState('school fee paid')
779        self.browser.open(self.login_path)
780        self.browser.getControl(name="form.login").value = self.student_id
781        self.browser.getControl(name="form.password").value = 'spwd'
782        self.browser.getControl("Login").click()
783        # Now students can add the current study level
784        self.browser.getLink("Study Course").click()
785        self.browser.getLink("Add course list").click()
786        self.assertMatches('...Add current level 100 (Year 1)...',
787                           self.browser.contents)
788        self.browser.getControl("Create course list now").click()
789        # Students can't open the customized pdf course registration slip
790        self.browser.open(
791            self.student_path + '/studycourse/100/course_registration_slip.pdf')
792        self.assertTrue('Forbidden' in self.browser.contents)
793        # They can open slips from the previous session ...
794        self.student['studycourse'].current_level = 200
795        self.browser.open(self.student_path + '/studycourse/100')
796        self.browser.getLink("Download course registration slip").click()
797        self.assertEqual(self.browser.headers['Status'], '200 Ok')
798        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
799        # or if they have registered their course list
800        self.student['studycourse'].current_level = 200
801        IWorkflowState(self.student).setState('courses registered')
802        self.browser.open(self.student_path + '/studycourse/100')
803        self.browser.getLink("Download course registration slip").click()
804        self.assertEqual(self.browser.headers['Status'], '200 Ok')
805        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
806        path = os.path.join(samples_dir(), 'ft_course_registration_slip.pdf')
807        open(path, 'wb').write(self.browser.contents)
808        print "Sample PDF ft_course_registration_slip.pdf written to %s" % path
809
810        self.certificate.study_mode = 'ug_pt'
811        self.browser.open(self.student_path + '/studycourse/100')
812        self.browser.getLink("Download course registration slip").click()
813        self.assertEqual(self.browser.headers['Status'], '200 Ok')
814        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
815        path = os.path.join(samples_dir(), 'pt_course_registration_slip.pdf')
816        open(path, 'wb').write(self.browser.contents)
817        print "Sample PDF pt_course_registration_slip.pdf written to %s" % path
818
819        self.certificate.study_mode = 'special_pg_ft'
820        self.student.matric_number = u'AAU/SPS/FLW/LAW/15/PHD/09504'
821        self.browser.open(self.student_path + '/studycourse/100')
822        self.browser.getLink("Download course registration slip").click()
823        self.assertEqual(self.browser.headers['Status'], '200 Ok')
824        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
825        path = os.path.join(samples_dir(), 'pg_course_registration_slip.pdf')
826        open(path, 'wb').write(self.browser.contents)
827        print "Sample PDF pg_course_registration_slip.pdf written to %s" % path
828
829    def test_student_2nd_semester_course_registration(self):
830        IWorkflowState(self.student).setState('school fee paid')
831        self.student['studycourse'].entry_session = 2015
832        self.course.semester = 2
833        self.browser.open(self.login_path)
834        self.browser.getControl(name="form.login").value = self.student_id
835        self.browser.getControl(name="form.password").value = 'spwd'
836        self.browser.getControl("Login").click()
837        self.browser.getLink("Study Course").click()
838        self.browser.getLink("Add course list").click()
839        self.browser.getControl("Create course list now").click()
840        self.assertFalse('COURSE1' in self.browser.contents)
841        # 2nd semester tickets can't be added manually
842        self.browser.getLink("Edit course list").click()
843        self.browser.getLink("here").click()
844        self.browser.getControl(name="form.course").value = ['COURSE1']
845        self.browser.getControl("Add course ticket").click()
846        self.assertTrue(
847            'COURSE1 is a 2nd semester course which can only '
848            'be added if school fees have been fully paid.'
849            in self.browser.contents)
850        # 2nd instalment has to be paid first
851        self.certificate.school_fee_3 = 678.0
852        self.browser.open(self.payments_path + '/addop')
853        self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
854        self.browser.getControl("Create ticket").click()
855        self.student['payments'].values()[0].approve()
856        self.browser.open(self.studycourse_path + '/100/ctadd')
857        self.browser.getControl(name="form.course").value = ['COURSE1']
858        self.browser.getControl("Add course ticket").click()
859        self.assertTrue('Successfully added COURSE1' in self.browser.contents)
860        return
861
862    def test_student_GST_registration(self):
863        configuration_1 = createObject('waeup.SessionConfiguration')
864        configuration_1.academic_session = 2016
865        configuration_1.gst_registration_1_fee = 3333.0
866        configuration_1.gst_text_book_1_fee = 4444.0
867        self.app['configuration'].addSessionConfiguration(configuration_1)
868        course = createObject('waeup.Course')
869        course.code = 'GST101'
870        course.semester = 1
871        course.credits = 10
872        course.passmark = 40
873        self.app['faculties']['fac1']['dep1'].courses.addCourse(
874            course)
875        self.app['faculties']['fac1']['dep1'].certificates[
876            'CERT1'].addCertCourse(course, level=100)
877        IWorkflowState(self.student).setState('school fee paid')
878        self.student['studycourse'].entry_session = 2016
879        self.student['studycourse'].current_session = 2016
880        self.course.semester = 2
881        self.browser.open(self.login_path)
882        self.browser.getControl(name="form.login").value = self.student_id
883        self.browser.getControl(name="form.password").value = 'spwd'
884        self.browser.getControl("Login").click()
885        self.browser.getLink("Study Course").click()
886        self.browser.getLink("Add course list").click()
887        self.browser.getControl("Create course list now").click()
888        self.assertFalse('GST101' in self.browser.contents)
889        # GST101 tickets can't be added manually
890        self.browser.getLink("Edit course list").click()
891        self.browser.getLink("here").click()
892        self.browser.getControl(name="form.course").value = ['GST101']
893        self.browser.getControl("Add course ticket").click()
894        self.assertTrue(
895            'GST101 can only be added if both registration fee and text'
896            in self.browser.contents)
897        # GST fees have to be paid first
898        self.browser.open(self.payments_path + '/addop')
899        self.browser.getControl(name="form.p_category").value = ['gst_registration_1']
900        self.browser.getControl("Create ticket").click()
901        self.student['payments'].values()[0].approve()
902        self.browser.open(self.studycourse_path + '/100/ctadd')
903        self.browser.getControl(name="form.course").value = ['GST101']
904        self.browser.getControl("Add course ticket").click()
905        self.assertTrue(
906            'GST101 can only be added if both registration fee and text'
907            in self.browser.contents)
908        self.browser.open(self.payments_path + '/addop')
909        self.browser.getControl(name="form.p_category").value = ['gst_text_book_1']
910        self.browser.getControl("Create ticket").click()
911        self.student['payments'].values()[1].approve()
912        self.browser.open(self.studycourse_path + '/100/ctadd')
913        self.browser.getControl(name="form.course").value = ['GST101']
914        self.browser.getControl("Add course ticket").click()
915        self.assertTrue('Successfully added GST101' in self.browser.contents)
916        return
917
918    def test_course_registration_forbidden(self):
919        IWorkflowState(self.student).setState('school fee paid')
920        self.student['studycourse'].entry_session = 2016
921        self.student['studycourse'].current_session = 2016
922        self.browser.open(self.login_path)
923        self.browser.getControl(name="form.login").value = self.student_id
924        self.browser.getControl(name="form.password").value = 'spwd'
925        self.browser.getControl("Login").click()
926        self.browser.getLink("Study Course").click()
927        self.browser.getLink("Add course list").click()
928        self.browser.getControl("Create course list now").click()
929        self.browser.getLink("Edit course list").click()
930        self.browser.getControl("Register course list").click()
931        self.assertTrue('Please pay faculty and departmental dues first'
932            in self.browser.contents)
933
934        configuration_1 = createObject('waeup.SessionConfiguration')
935        configuration_1.academic_session = 2016
936        configuration_1.fac_dep_fee = 9999.0
937        self.app['configuration'].addSessionConfiguration(configuration_1)
938
939        self.browser.open(self.payments_path + '/addop')
940        self.browser.getControl(name="form.p_category").value = ['fac_dep']
941        self.browser.getControl("Create ticket").click()
942        self.student['payments'].values()[0].approveStudentPayment()
943        self.browser.open(self.studycourse_path + '/100/edit')
944        self.browser.getControl("Register course list").click()
945        self.assertTrue('Course list has been registered'
946            in self.browser.contents)
947        return
948
949    def test_student_clearance(self):
950        # Student cant login if their password is not set
951        IWorkflowInfo(self.student).fireTransition('admit')
952        self.browser.open(self.login_path)
953        self.browser.getControl(name="form.login").value = self.student_id
954        self.browser.getControl(name="form.password").value = 'spwd'
955        self.browser.getControl("Login").click()
956        self.assertMatches(
957            '...You logged in...', self.browser.contents)
958        # Admitted student can upload a passport picture
959        self.browser.open(self.student_path + '/change_portrait')
960        ctrl = self.browser.getControl(name='passportuploadedit')
961        file_obj = open(SAMPLE_IMAGE, 'rb')
962        file_ctrl = ctrl.mech_control
963        file_ctrl.add_file(file_obj, filename='my_photo.jpg')
964        self.browser.getControl(
965            name='upload_passportuploadedit').click()
966        self.assertTrue(
967            'src="http://localhost/app/students/E1000000/passport.jpg"'
968            in self.browser.contents)
969        # Student is redirected to the personal data form because
970        # personal data form is not properly filled.
971        self.browser.open(self.student_path + '/start_clearance')
972        self.assertMatches('...Personal data form is not properly filled...',
973                           self.browser.contents)
974        self.assertEqual(self.browser.url, self.student_path + '/edit_personal')
975        self.student.father_name = u'Rudolf'
976        self.browser.open(self.student_path + '/start_clearance')
977        self.assertMatches(
978            '...<h1 class="kofa-content-label">Start clearance</h1>...',
979            self.browser.contents)
980
981    def test_student_accommodation(self):
982        del self.student['accommodation']['2004']
983        self.student['studycourse'].certificate.study_mode = 'dp_ft'
984        # All beds can be assigned
985        bed1 = self.app['hostels']['hall-1']['hall-1_A_101_A']
986        bed1.bed_type = u'regular_male_all'
987        bed2 = self.app['hostels']['hall-1']['hall-1_A_101_B']
988        bed2.bed_type = u'regular_female_all'
989        notify(grok.ObjectModifiedEvent(bed1))
990        notify(grok.ObjectModifiedEvent(bed2))
991        # Login
992        self.browser.open(self.login_path)
993        self.browser.getControl(name="form.login").value = self.student_id
994        self.browser.getControl(name="form.password").value = 'spwd'
995        self.browser.getControl("Login").click()
996        # Students can book accommodation without AC ...
997        self.browser.open(self.acco_path)
998        IWorkflowInfo(self.student).fireTransition('admit')
999        self.browser.getControl("Book accommodation").click()
1000        self.assertTrue(
1001            'You are not eligible to book accommodation.'
1002            in self.browser.contents)
1003        self.student['studycourse'].certificate.study_mode = 'ug_ft'
1004        self.app['hostels'].accommodation_states = [PAID]
1005        self.browser.getControl("Book accommodation").click()
1006        self.assertTrue(
1007            'You are in the wrong registration state.'
1008            in self.browser.contents)
1009        IWorkflowState(self.student).setState(PAID)
1010        self.browser.getControl("Book accommodation").click()
1011        self.assertFalse('Activation Code:' in self.browser.contents)
1012        self.browser.getControl("Create bed ticket").click()
1013        # Bed is randomly selected but, since there is only
1014        # one bed for this student, we know that
1015        self.assertEqual(self.student['accommodation']['2004'].bed_coordinates,
1016            'Hall 1, Block A, Room 101, Bed A (regular_male_all)')
1017        # Only the hall name is displayed
1018        self.assertEqual(self.student[
1019            'accommodation']['2004'].display_coordinates,
1020            'Hall 1')
1021        self.assertFalse('Hall 1, Block A, Room 101, Bed A'
1022            in self.browser.contents)
1023        self.assertTrue('<td>Hall 1</td>'
1024            in self.browser.contents)
1025        return
1026
1027    def test_handle_courses_by_lecturer(self):
1028        self.app['users'].addUser('mrslecturer', 'mrslecturersecret')
1029        self.app['users']['mrslecturer'].email = 'mrslecturer@foo.ng'
1030        self.app['users']['mrslecturer'].title = u'Mercedes Benz'
1031        # Add course ticket
1032        studylevel = createObject(u'waeup.StudentStudyLevel')
1033        studylevel.level = 100
1034        studylevel.level_session = 2004
1035        self.student['studycourse'].addStudentStudyLevel(
1036            self.certificate, studylevel)
1037        # Assign local Lecturer role for a certificate.
1038        course = self.app['faculties']['fac1']['dep1'].courses['COURSE1']
1039        prmlocal = IPrincipalRoleManager(course)
1040        prmlocal.assignRoleToPrincipal('waeup.local.Lecturer', 'mrslecturer')
1041        notify(LocalRoleSetEvent(
1042            course, 'waeup.local.Lecturer', 'mrslecturer', granted=True))
1043        # Login as lecturer.
1044        self.browser.open(self.login_path)
1045        self.browser.getControl(name="form.login").value = 'mrslecturer'
1046        self.browser.getControl(name="form.password").value = 'mrslecturersecret'
1047        self.browser.getControl("Login").click()
1048        self.browser.getLink("My Courses").click()
1049        self.browser.getLink("COURSE1").click()
1050        # Course results can be batch edited via the edit_courses view.
1051        self.app['faculties']['fac1']['dep1'].score_editing_disabled = False
1052        self.app['configuration'].current_academic_session = 2004
1053        IWorkflowState(self.student).setState('courses validated')
1054        self.browser.open(
1055            "http://localhost/app/faculties/fac1/dep1/courses/COURSE1/edit_scores")
1056        self.assertTrue(
1057            'input type="text" name="scores:list"'
1058            in self.browser.contents)
1059        self.browser.getControl(name="scores:list", index=0).value = '55'
1060        self.browser.getControl(name="cas:list", index=0).value = '22'
1061        self.browser.getControl("Update scores from").click()
1062        # New score and ca has been set.
1063        self.assertEqual(
1064            self.student['studycourse']['100']['COURSE1'].score, 55)
1065        self.assertEqual(
1066            self.student['studycourse']['100']['COURSE1'].ca, 22)
1067        # Score editing has been logged.
1068        logfile = os.path.join(
1069            self.app['datacenter'].storage, 'logs', 'students.log')
1070        logcontent = open(logfile).read()
1071        self.assertTrue('mrslecturer - waeup.aaue.students.browser.CustomEditScoresPage - '
1072                        'E1000000 100/COURSE1 score updated (55)' in logcontent)
1073        self.assertTrue('mrslecturer - waeup.aaue.students.browser.CustomEditScoresPage - '
1074                        'E1000000 100/COURSE1 ca updated (22)' in logcontent)
1075        # Non-integer scores won't be accepted.
1076        self.browser.open(
1077            "http://localhost/app/faculties/fac1/dep1/courses/COURSE1/edit_scores")
1078        self.assertTrue('value="55" />' in self.browser.contents)
1079        self.browser.getControl(name="scores:list", index=0).value = 'abc'
1080        self.browser.getControl("Update scores").click()
1081        self.assertTrue('Error: Score(s) and CA(s) of TESTER, Anna have not be updated.'
1082            in self.browser.contents)
1083        # Scores can be removed.
1084        self.browser.open(
1085            "http://localhost/app/faculties/fac1/dep1/courses/COURSE1/edit_scores")
1086        self.browser.getControl(name="scores:list", index=0).value = ''
1087        self.browser.getControl("Update scores").click()
1088        self.assertEqual(
1089            self.student['studycourse']['100']['COURSE1'].score, None)
1090        logcontent = open(logfile).read()
1091        self.assertTrue('mrslecturer - waeup.aaue.students.browser.CustomEditScoresPage - '
1092                        'E1000000 100/COURSE1 score updated (None)' in logcontent)
1093
1094
1095    def test_student_view_transcript(self):
1096        # Student cant login if their password is not set
1097        IWorkflowInfo(self.student).fireTransition('admit')
1098        self.browser.open(self.login_path)
1099        self.browser.getControl(name="form.login").value = self.student_id
1100        self.browser.getControl(name="form.password").value = 'spwd'
1101        self.browser.getControl("Login").click()
1102        self.assertMatches(
1103            '...You logged in...', self.browser.contents)
1104        # Students can view the transcript
1105        self.browser.open(self.studycourse_path)
1106        self.browser.getLink("Transcript").click()
1107        self.browser.getLink("Academic Transcript").click()
1108        self.assertEqual(self.browser.headers['Status'], '200 Ok')
1109        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
1110
1111    def test_alumni_request_pw(self):
1112        # Add an applicants container
1113        applicantscontainer = ApplicantsContainer()
1114        applicantscontainer.code = u'trans2017'
1115        applicantscontainer.prefix = 'trans'
1116        applicantscontainer.year = 2017
1117        applicantscontainer.title = u'This is the trans2017 container'
1118        applicantscontainer.application_category = 'no'
1119        applicantscontainer.mode = 'create'
1120        applicantscontainer.strict_deadline = True
1121        delta = timedelta(days=10)
1122        applicantscontainer.startdate = datetime.now(pytz.utc) - delta
1123        applicantscontainer.enddate = datetime.now(pytz.utc) + delta
1124        self.app['applicants']['trans2017'] = applicantscontainer
1125        self.applicantscontainer = self.app['applicants']['trans2017']
1126        # Student with wrong number can't be found.
1127        # Applicant is redirected to application section.
1128        self.browser.open('http://localhost/app/alumni_requestpw')
1129        self.browser.getControl(name="form.lastname").value = 'Tester'
1130        self.browser.getControl(name="form.number").value = 'anynumber'
1131        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
1132        self.browser.getControl("Send login credentials").click()
1133        self.assertTrue('No student record found.'
1134            in self.browser.contents)
1135        self.assertEqual(self.browser.url,
1136            'http://localhost/app/applicants/trans2017/register')
Note: See TracBrowser for help on using the repository browser.