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

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

Exchange level and session on report slips.

Use string formatting for displaying GPA values.

  • Property svn:keywords set to Id
File size: 60.6 KB
Line 
1## $Id: test_browser.py 14384 2017-01-10 18:41:09Z 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.5652173913043477)
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,display_fullname,'
391            'level,code,level_session,ca,score\r\n234,E1000000,"TESTER, Anna",'
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.5652173913043477)
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        self.app['configuration']['2004'].restitution_fee = 9999.0
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        # Login
599        self.browser.open(self.login_path)
600        self.browser.getControl(name="form.login").value = self.student_id
601        self.browser.getControl(name="form.password").value = 'spwd'
602        self.browser.getControl("Login").click()
603        # Make restitution fee payment
604        self.browser.open(self.payments_path + '/addop')
605        self.browser.getControl(name="form.p_category").value = ['restitution']
606        self.browser.getControl("Create ticket").click()
607        self.student['payments'].values()[0].approveStudentPayment()
608        # Make late registration fee fee payment
609        self.browser.open(self.payments_path + '/addop')
610        self.browser.getControl(name="form.p_category").value = ['late_registration']
611        self.browser.getControl("Create ticket").click()
612        self.assertMatches('...ticket created...',
613                           self.browser.contents)
614        self.browser.getLink("Study Course").click()
615        self.browser.getLink("Add course list").click()
616        self.assertMatches('...Add current level 100 (Year 1)...',
617                           self.browser.contents)
618        self.browser.getControl("Create course list now").click()
619        self.student['studycourse']['100']['COURSE1'].score = 67
620        self.browser.getLink("100").click()
621        # Course results can't be seen
622        self.assertFalse('<td>67</td>' in self.browser.contents)
623        self.browser.getLink("Edit course list").click()
624        self.assertFalse('<td>67</td>' in self.browser.contents)
625        self.browser.getControl("Register course list").click()
626        self.assertTrue('Course registration has ended. Please pay' in self.browser.contents)
627        self.student['payments'].values()[1].approve()
628        self.browser.getControl("Register course list").click()
629        self.assertTrue('Course list has been registered' in self.browser.contents)
630        self.assertEqual(self.student.state, 'courses registered')
631        # Reset student and check if fresh students are always allowed to
632        # register courses.
633        self.student['studycourse'].entry_session = 2004
634        del self.student['payments'][self.student['payments'].keys()[1]]
635        IWorkflowState(self.student).setState('school fee paid')
636        self.browser.open(self.studycourse_path + '/100/edit')
637        self.browser.getControl("Register course list").click()
638        self.assertTrue('Course list has been registered' in self.browser.contents)
639        return
640
641
642    def deactivated_test_student_course_registration(self):
643        # Add more courses
644        self.course2 = createObject('waeup.Course')
645        self.course2.code = 'COURSE2'
646        self.course2.semester = 2
647        self.course2.credits = 10
648        self.course2.passmark = 40
649        self.app['faculties']['fac1']['dep1'].courses.addCourse(
650            self.course2)
651        self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCertCourse(
652            self.course2, level=100)
653        self.course3 = createObject('waeup.Course')
654        self.course3.code = 'COURSE3'
655        self.course3.semester = 3
656        self.course3.credits = 10
657        self.course3.passmark = 40
658        self.app['faculties']['fac1']['dep1'].courses.addCourse(
659            self.course3)
660        self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCertCourse(
661            self.course3, level=100)
662
663        # Login as student
664        self.browser.open(self.login_path)
665        IWorkflowState(self.student).setState('school fee paid')
666        self.browser.open(self.login_path)
667        self.browser.getControl(name="form.login").value = self.student_id
668        self.browser.getControl(name="form.password").value = 'spwd'
669        self.browser.getControl("Login").click()
670        # Students can add the current study level
671        self.browser.getLink("Study Course").click()
672        self.browser.getLink("Add course list").click()
673        self.assertMatches('...Add current level 100 (Year 1)...',
674                           self.browser.contents)
675        self.browser.getControl("Create course list now").click()
676        # Student has not paid second instalment, therefore a level
677        # with two course ticket was created (semester 1 and combined)
678        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 2)
679        self.browser.getLink("100").click()
680        self.browser.getLink("Edit course list").click()
681        self.browser.getControl("Add course ticket").click()
682        # Student can't add second semester course
683        self.assertTrue('<option value="COURSE1">' in self.browser.contents)
684        self.assertTrue('<option value="COURSE3">' in self.browser.contents)
685        self.assertFalse('<option value="COURSE2">' in self.browser.contents)
686
687        # Let's remove level and see what happens after 2nd instalment payment
688        del(self.student['studycourse']['100'])
689        payment2 = createObject('waeup.StudentOnlinePayment')
690        payment2.p_category = u'schoolfee_2'
691        payment2.p_session = self.student.current_session
692        self.student['payments']['anykey'] = payment2
693        self.browser.open(self.studycourse_path)
694        self.browser.getLink("Add course list").click()
695        self.browser.getControl("Create course list now").click()
696        # Still only 2 tickets have been created since payment ticket
697        # was not paid
698        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 2)
699        payment2.p_state = u'paid'
700        del(self.student['studycourse']['100'])
701        self.browser.open(self.studycourse_path)
702        self.browser.getLink("Add course list").click()
703        self.browser.getControl("Create course list now").click()
704        # Now 2nd semester course has been added
705        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 3)
706        # Student can add second semester course
707        self.browser.getLink("100").click()
708        self.browser.getLink("Edit course list").click()
709        self.browser.getControl("Add course ticket").click()
710        self.assertTrue('<option value="COURSE1">' in self.browser.contents)
711        self.assertTrue('<option value="COURSE2">' in self.browser.contents)
712        self.assertTrue('<option value="COURSE3">' in self.browser.contents)
713        return
714
715    def test_set_matric_number(self):
716        #payment = createObject('waeup.StudentOnlinePayment')
717        #payment.p_category = u'concessional'
718        #payment.p_id = u'anyid'
719        #payment.p_state = u'paid'
720        #self.student['payments']['anykey'] = payment
721        # Login as student
722        self.browser.open(self.login_path)
723        IWorkflowState(self.student).setState('school fee paid')
724        self.browser.open(self.login_path)
725        self.browser.getControl(name="form.login").value = self.student_id
726        self.browser.getControl(name="form.password").value = 'spwd'
727        self.browser.getControl("Login").click()
728        self.assertRaises(
729            LinkNotFoundError,
730            self.browser.getLink, 'Get Matriculation Number')
731        self.student.matric_number = None
732        site = grok.getSite()
733        site['configuration'].next_matric_integer = 1
734        self.student['studycourse'].certificate.study_mode = 'ug_pt'
735        self.browser.open(self.student_path)
736        self.assertRaises(
737            LinkNotFoundError,
738            self.browser.getLink, 'Download matriculation number slip')
739        self.browser.getLink("Get Matriculation Number").click()
740        self.assertTrue('Matriculation number PTP/fac1/dep1/04/00001 assigned.'
741            in self.browser.contents)
742        self.assertEqual(self.student.matric_number, 'PTP/fac1/dep1/04/00001')
743        self.assertRaises(
744            LinkNotFoundError,
745            self.browser.getLink, 'Get Matriculation Number')
746        # Setting matric number is logged.
747        logfile = os.path.join(
748            self.app['datacenter'].storage, 'logs', 'students.log')
749        logcontent = open(logfile).read()
750        self.assertTrue('E1000000 - waeup.aaue.students.browser.StudentGetMatricNumberPage - '
751                        'E1000000 - PTP/fac1/dep1/04/00001 assigned' in logcontent)
752        # Matric Number Slip can be downloaded
753        self.browser.getLink("Download matriculation number slip").click()
754        self.assertEqual(self.browser.headers['Status'], '200 Ok')
755        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
756        path = os.path.join(samples_dir(), 'matric_number_slip.pdf')
757        open(path, 'wb').write(self.browser.contents)
758        print "Sample PDF matric_number_slip.pdf written to %s" % path
759        return
760
761    def test_personal_data_slip(self):
762        # Login as student
763        self.browser.open(self.login_path)
764        IWorkflowState(self.student).setState('school fee paid')
765        self.browser.open(self.login_path)
766        self.browser.getControl(name="form.login").value = self.student_id
767        self.browser.getControl(name="form.password").value = 'spwd'
768        self.browser.getControl("Login").click()
769        self.browser.getLink("Personal Data").click()
770        self.assertRaises(
771            LinkNotFoundError,
772            self.browser.getLink, 'Download personal data slip')
773        self.student.father_name = u'Rudolf'
774        self.browser.open(self.personal_path)
775        self.browser.getLink("Download personal data slip").click()
776        self.assertEqual(self.browser.headers['Status'], '200 Ok')
777        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
778        path = os.path.join(samples_dir(), 'personal_data_slip.pdf')
779        open(path, 'wb').write(self.browser.contents)
780        print "Sample PDF personal_data_slip.pdf written to %s" % path
781        return
782
783    def test_student_course_registration(self):
784        IWorkflowState(self.student).setState('school fee paid')
785        self.browser.open(self.login_path)
786        self.browser.getControl(name="form.login").value = self.student_id
787        self.browser.getControl(name="form.password").value = 'spwd'
788        self.browser.getControl("Login").click()
789        # Now students can add the current study level
790        self.browser.getLink("Study Course").click()
791        self.browser.getLink("Add course list").click()
792        self.assertMatches('...Add current level 100 (Year 1)...',
793                           self.browser.contents)
794        self.browser.getControl("Create course list now").click()
795        # Students can't open the customized pdf course registration slip
796        self.browser.open(
797            self.student_path + '/studycourse/100/course_registration_slip.pdf')
798        self.assertTrue('Forbidden' in self.browser.contents)
799        # They can open slips from the previous session ...
800        self.student['studycourse'].current_level = 200
801        self.browser.open(self.student_path + '/studycourse/100')
802        self.browser.getLink("Download course registration slip").click()
803        self.assertEqual(self.browser.headers['Status'], '200 Ok')
804        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
805        # or if they have registered their course list
806        self.student['studycourse'].current_level = 200
807        IWorkflowState(self.student).setState('courses registered')
808        self.browser.open(self.student_path + '/studycourse/100')
809        self.browser.getLink("Download course registration slip").click()
810        self.assertEqual(self.browser.headers['Status'], '200 Ok')
811        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
812        path = os.path.join(samples_dir(), 'ft_course_registration_slip.pdf')
813        open(path, 'wb').write(self.browser.contents)
814        print "Sample PDF ft_course_registration_slip.pdf written to %s" % path
815
816        self.certificate.study_mode = 'ug_pt'
817        self.browser.open(self.student_path + '/studycourse/100')
818        self.browser.getLink("Download course registration slip").click()
819        self.assertEqual(self.browser.headers['Status'], '200 Ok')
820        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
821        path = os.path.join(samples_dir(), 'pt_course_registration_slip.pdf')
822        open(path, 'wb').write(self.browser.contents)
823        print "Sample PDF pt_course_registration_slip.pdf written to %s" % path
824
825        self.certificate.study_mode = 'special_pg_ft'
826        self.student.matric_number = u'AAU/SPS/FLW/LAW/15/PHD/09504'
827        self.browser.open(self.student_path + '/studycourse/100')
828        self.browser.getLink("Download course registration slip").click()
829        self.assertEqual(self.browser.headers['Status'], '200 Ok')
830        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
831        path = os.path.join(samples_dir(), 'pg_course_registration_slip.pdf')
832        open(path, 'wb').write(self.browser.contents)
833        print "Sample PDF pg_course_registration_slip.pdf written to %s" % path
834
835    def test_student_2nd_semester_course_registration(self):
836        IWorkflowState(self.student).setState('school fee paid')
837        self.student['studycourse'].entry_session = 2015
838        self.course.semester = 2
839        self.browser.open(self.login_path)
840        self.browser.getControl(name="form.login").value = self.student_id
841        self.browser.getControl(name="form.password").value = 'spwd'
842        self.browser.getControl("Login").click()
843        self.browser.getLink("Study Course").click()
844        self.browser.getLink("Add course list").click()
845        self.browser.getControl("Create course list now").click()
846        self.assertFalse('COURSE1' in self.browser.contents)
847        # 2nd semester tickets can't be added manually
848        self.browser.getLink("Edit course list").click()
849        self.browser.getLink("here").click()
850        self.browser.getControl(name="form.course").value = ['COURSE1']
851        self.browser.getControl("Add course ticket").click()
852        self.assertTrue(
853            'COURSE1 is a 2nd semester course which can only '
854            'be added if school fees have been fully paid.'
855            in self.browser.contents)
856        # 2nd instalment has to be paid first
857        self.certificate.school_fee_3 = 678.0
858        self.browser.open(self.payments_path + '/addop')
859        self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
860        self.browser.getControl("Create ticket").click()
861        self.student['payments'].values()[0].approve()
862        self.browser.open(self.studycourse_path + '/100/ctadd')
863        self.browser.getControl(name="form.course").value = ['COURSE1']
864        self.browser.getControl("Add course ticket").click()
865        self.assertTrue('Successfully added COURSE1' in self.browser.contents)
866        return
867
868    def test_student_GST_registration(self):
869        configuration_1 = createObject('waeup.SessionConfiguration')
870        configuration_1.academic_session = 2016
871        configuration_1.gst_registration_1_fee = 3333.0
872        configuration_1.gst_text_book_1_fee = 4444.0
873        configuration_1.gst_text_book_0_fee = 2222.0
874        self.app['configuration'].addSessionConfiguration(configuration_1)
875        course = createObject('waeup.Course')
876        course.code = 'GST101'
877        course.semester = 1
878        course.credits = 10
879        course.passmark = 40
880        self.app['faculties']['fac1']['dep1'].courses.addCourse(
881            course)
882        self.app['faculties']['fac1']['dep1'].certificates[
883            'CERT1'].addCertCourse(course, level=100)
884        IWorkflowState(self.student).setState('school fee paid')
885        self.student['studycourse'].entry_session = 2016
886        self.student['studycourse'].current_session = 2016
887        self.course.semester = 2
888        self.browser.open(self.login_path)
889        self.browser.getControl(name="form.login").value = self.student_id
890        self.browser.getControl(name="form.password").value = 'spwd'
891        self.browser.getControl("Login").click()
892        self.browser.getLink("Study Course").click()
893        self.browser.getLink("Add course list").click()
894        self.browser.getControl("Create course list now").click()
895        self.assertFalse('GST101' in self.browser.contents)
896        # GST101 tickets can't be added manually
897        self.browser.getLink("Edit course list").click()
898        self.browser.getLink("here").click()
899        self.browser.getControl(name="form.course").value = ['GST101']
900        self.browser.getControl("Add course ticket").click()
901        self.assertTrue(
902            'GST101 can only be added if both registration fee and text'
903            in self.browser.contents)
904        # GST fees have to be paid first
905        self.browser.open(self.payments_path + '/addop')
906        self.browser.getControl(name="form.p_category").value = ['gst_registration_1']
907        self.browser.getControl("Create ticket").click()
908        self.student['payments'].values()[0].approve()
909        self.browser.open(self.studycourse_path + '/100/ctadd')
910        self.browser.getControl(name="form.course").value = ['GST101']
911        self.browser.getControl("Add course ticket").click()
912        self.assertTrue(
913            'GST101 can only be added if both registration fee and text'
914            in self.browser.contents)
915        self.browser.open(self.payments_path + '/addop')
916        self.browser.getControl(name="form.p_category").value = ['gst_text_book_0']
917        self.browser.getControl("Create ticket").click()
918        self.student['payments'].values()[1].approve()
919        self.browser.open(self.studycourse_path + '/100/ctadd')
920        self.browser.getControl(name="form.course").value = ['GST101']
921        self.browser.getControl("Add course ticket").click()
922        self.assertTrue('Successfully added GST101' in self.browser.contents)
923        return
924
925    def test_course_registration_forbidden(self):
926        IWorkflowState(self.student).setState('school fee paid')
927        self.student['studycourse'].entry_session = 2016
928        self.student['studycourse'].current_session = 2016
929        self.browser.open(self.login_path)
930        self.browser.getControl(name="form.login").value = self.student_id
931        self.browser.getControl(name="form.password").value = 'spwd'
932        self.browser.getControl("Login").click()
933        self.browser.getLink("Study Course").click()
934        self.browser.getLink("Add course list").click()
935        self.browser.getControl("Create course list now").click()
936        self.browser.getLink("Edit course list").click()
937        self.browser.getControl("Register course list").click()
938        self.assertTrue('Please pay faculty and departmental dues first'
939            in self.browser.contents)
940        configuration_1 = createObject('waeup.SessionConfiguration')
941        configuration_1.academic_session = 2016
942        configuration_1.fac_dep_fee = 9999.0
943        self.app['configuration'].addSessionConfiguration(configuration_1)
944        self.browser.open(self.payments_path + '/addop')
945        self.browser.getControl(name="form.p_category").value = ['fac_dep']
946        self.browser.getControl("Create ticket").click()
947        self.student['payments'].values()[0].approveStudentPayment()
948        self.browser.open(self.studycourse_path + '/100/edit')
949        self.browser.getControl("Register course list").click()
950        self.assertTrue('Course list has been registered'
951            in self.browser.contents)
952        return
953
954    def test_course_registration_forbidden_2(self):
955        IWorkflowState(self.student).setState('school fee paid')
956        self.student['studycourse'].entry_session = 2004
957        self.student['studycourse'].current_session = 2004
958        self.browser.open(self.login_path)
959        self.browser.getControl(name="form.login").value = self.student_id
960        self.browser.getControl(name="form.password").value = 'spwd'
961        self.browser.getControl("Login").click()
962        self.browser.getLink("Study Course").click()
963        self.browser.getLink("Add course list").click()
964        self.browser.getControl("Create course list now").click()
965        self.browser.getLink("Edit course list").click()
966        self.browser.getControl("Register course list").click()
967        self.assertTrue('Please pay restitution fee first'
968            in self.browser.contents)
969        self.app['configuration']['2004'].restitution_fee = 9999.0
970        self.browser.open(self.payments_path + '/addop')
971        self.browser.getControl(name="form.p_category").value = ['restitution']
972        self.browser.getControl("Create ticket").click()
973        self.student['payments'].values()[0].approveStudentPayment()
974        self.browser.open(self.studycourse_path + '/100/edit')
975        self.browser.getControl("Register course list").click()
976        self.assertTrue('Course list has been registered'
977            in self.browser.contents)
978        return
979
980    def test_student_clearance(self):
981        # Student cant login if their password is not set
982        IWorkflowInfo(self.student).fireTransition('admit')
983        self.browser.open(self.login_path)
984        self.browser.getControl(name="form.login").value = self.student_id
985        self.browser.getControl(name="form.password").value = 'spwd'
986        self.browser.getControl("Login").click()
987        self.assertMatches(
988            '...You logged in...', self.browser.contents)
989        # Admitted student can upload a passport picture
990        self.browser.open(self.student_path + '/change_portrait')
991        ctrl = self.browser.getControl(name='passportuploadedit')
992        file_obj = open(SAMPLE_IMAGE, 'rb')
993        file_ctrl = ctrl.mech_control
994        file_ctrl.add_file(file_obj, filename='my_photo.jpg')
995        self.browser.getControl(
996            name='upload_passportuploadedit').click()
997        self.assertTrue(
998            'src="http://localhost/app/students/E1000000/passport.jpg"'
999            in self.browser.contents)
1000        # Student is redirected to the personal data form because
1001        # personal data form is not properly filled.
1002        self.browser.open(self.student_path + '/start_clearance')
1003        self.assertMatches('...Personal data form is not properly filled...',
1004                           self.browser.contents)
1005        self.assertEqual(self.browser.url, self.student_path + '/edit_personal')
1006        self.student.father_name = u'Rudolf'
1007        self.browser.open(self.student_path + '/start_clearance')
1008        self.assertMatches(
1009            '...<h1 class="kofa-content-label">Start clearance</h1>...',
1010            self.browser.contents)
1011
1012    def test_student_accommodation(self):
1013        del self.student['accommodation']['2004']
1014        self.student['studycourse'].certificate.study_mode = 'dp_ft'
1015        # All beds can be assigned
1016        bed1 = self.app['hostels']['hall-1']['hall-1_A_101_A']
1017        bed1.bed_type = u'regular_male_all'
1018        bed2 = self.app['hostels']['hall-1']['hall-1_A_101_B']
1019        bed2.bed_type = u'regular_female_all'
1020        notify(grok.ObjectModifiedEvent(bed1))
1021        notify(grok.ObjectModifiedEvent(bed2))
1022        # Login
1023        self.browser.open(self.login_path)
1024        self.browser.getControl(name="form.login").value = self.student_id
1025        self.browser.getControl(name="form.password").value = 'spwd'
1026        self.browser.getControl("Login").click()
1027        # Students can book accommodation without AC ...
1028        self.browser.open(self.acco_path)
1029        IWorkflowInfo(self.student).fireTransition('admit')
1030        self.browser.getControl("Book accommodation").click()
1031        self.assertTrue(
1032            'You are not eligible to book accommodation.'
1033            in self.browser.contents)
1034        self.student['studycourse'].certificate.study_mode = 'ug_ft'
1035        self.app['hostels'].accommodation_states = [PAID]
1036        self.browser.getControl("Book accommodation").click()
1037        self.assertTrue(
1038            'You are in the wrong registration state.'
1039            in self.browser.contents)
1040        IWorkflowState(self.student).setState(PAID)
1041        self.browser.getControl("Book accommodation").click()
1042        self.assertFalse('Activation Code:' in self.browser.contents)
1043        self.browser.getControl("Create bed ticket").click()
1044        # Bed is randomly selected but, since there is only
1045        # one bed for this student, we know that
1046        self.assertEqual(self.student['accommodation']['2004'].bed_coordinates,
1047            'Hall 1, Block A, Room 101, Bed A (regular_male_all)')
1048        # Only the hall name is displayed
1049        self.assertEqual(self.student[
1050            'accommodation']['2004'].display_coordinates,
1051            'Hall 1')
1052        self.assertFalse('Hall 1, Block A, Room 101, Bed A'
1053            in self.browser.contents)
1054        self.assertTrue('<td>Hall 1</td>'
1055            in self.browser.contents)
1056        return
1057
1058    def test_handle_courses_by_lecturer(self):
1059        self.app['users'].addUser('mrslecturer', 'mrslecturersecret')
1060        self.app['users']['mrslecturer'].email = 'mrslecturer@foo.ng'
1061        self.app['users']['mrslecturer'].title = u'Mercedes Benz'
1062        # Add course ticket
1063        studylevel = createObject(u'waeup.StudentStudyLevel')
1064        studylevel.level = 100
1065        studylevel.level_session = 2004
1066        self.student['studycourse'].addStudentStudyLevel(
1067            self.certificate, studylevel)
1068        # Assign local Lecturer role for a certificate.
1069        course = self.app['faculties']['fac1']['dep1'].courses['COURSE1']
1070        prmlocal = IPrincipalRoleManager(course)
1071        prmlocal.assignRoleToPrincipal('waeup.local.Lecturer', 'mrslecturer')
1072        notify(LocalRoleSetEvent(
1073            course, 'waeup.local.Lecturer', 'mrslecturer', granted=True))
1074        # Login as lecturer.
1075        self.browser.open(self.login_path)
1076        self.browser.getControl(name="form.login").value = 'mrslecturer'
1077        self.browser.getControl(name="form.password").value = 'mrslecturersecret'
1078        self.browser.getControl("Login").click()
1079        self.browser.getLink("My Courses").click()
1080        self.browser.getLink("COURSE1").click()
1081        # Course results can be batch edited via the edit_courses view.
1082        self.app['faculties']['fac1']['dep1'].score_editing_disabled = False
1083        self.app['configuration'].current_academic_session = 2004
1084        IWorkflowState(self.student).setState('courses validated')
1085        self.browser.open(
1086            "http://localhost/app/faculties/fac1/dep1/courses/COURSE1/edit_scores")
1087        self.assertTrue(
1088            'input type="text" name="scores:list"'
1089            in self.browser.contents)
1090        self.browser.getControl(name="scores:list", index=0).value = '55'
1091        self.browser.getControl(name="cas:list", index=0).value = '22'
1092        self.browser.getControl("Update scores from").click()
1093        # New score and ca has been set.
1094        self.assertEqual(
1095            self.student['studycourse']['100']['COURSE1'].score, 55)
1096        self.assertEqual(
1097            self.student['studycourse']['100']['COURSE1'].ca, 22)
1098        # Score editing has been logged.
1099        logfile = os.path.join(
1100            self.app['datacenter'].storage, 'logs', 'students.log')
1101        logcontent = open(logfile).read()
1102        self.assertTrue('mrslecturer - waeup.aaue.students.browser.CustomEditScoresPage - '
1103                        'E1000000 100/COURSE1 score updated (55)' in logcontent)
1104        self.assertTrue('mrslecturer - waeup.aaue.students.browser.CustomEditScoresPage - '
1105                        'E1000000 100/COURSE1 ca updated (22)' in logcontent)
1106        # Non-integer scores won't be accepted.
1107        self.browser.open(
1108            "http://localhost/app/faculties/fac1/dep1/courses/COURSE1/edit_scores")
1109        self.assertTrue('value="55" />' in self.browser.contents)
1110        self.browser.getControl(name="scores:list", index=0).value = 'abc'
1111        self.browser.getControl("Update scores").click()
1112        self.assertTrue('Error: Score(s) and CA(s) of TESTER, Anna have not be updated.'
1113            in self.browser.contents)
1114        # Scores can be removed.
1115        self.browser.open(
1116            "http://localhost/app/faculties/fac1/dep1/courses/COURSE1/edit_scores")
1117        self.browser.getControl(name="scores:list", index=0).value = ''
1118        self.browser.getControl("Update scores").click()
1119        self.assertEqual(
1120            self.student['studycourse']['100']['COURSE1'].score, None)
1121        logcontent = open(logfile).read()
1122        self.assertTrue('mrslecturer - waeup.aaue.students.browser.CustomEditScoresPage - '
1123                        'E1000000 100/COURSE1 score updated (None)' in logcontent)
1124
1125
1126    def disabled_test_student_view_transcript(self):
1127        # Student cant login if their password is not set
1128        IWorkflowInfo(self.student).fireTransition('admit')
1129        self.browser.open(self.login_path)
1130        self.browser.getControl(name="form.login").value = self.student_id
1131        self.browser.getControl(name="form.password").value = 'spwd'
1132        self.browser.getControl("Login").click()
1133        self.assertMatches(
1134            '...You logged in...', self.browser.contents)
1135        # Students can view the transcript
1136        self.browser.open(self.studycourse_path)
1137        self.browser.getLink("Transcript").click()
1138        self.browser.getLink("Academic Transcript").click()
1139        self.assertEqual(self.browser.headers['Status'], '200 Ok')
1140        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
1141
1142    def test_alumni_request_pw(self):
1143        # Add an applicants container
1144        applicantscontainer = ApplicantsContainer()
1145        applicantscontainer.code = u'trans2017'
1146        applicantscontainer.prefix = 'trans'
1147        applicantscontainer.year = 2017
1148        applicantscontainer.title = u'This is the trans2017 container'
1149        applicantscontainer.application_category = 'no'
1150        applicantscontainer.mode = 'create'
1151        applicantscontainer.strict_deadline = True
1152        delta = timedelta(days=10)
1153        applicantscontainer.startdate = datetime.now(pytz.utc) - delta
1154        applicantscontainer.enddate = datetime.now(pytz.utc) + delta
1155        self.app['applicants']['trans2017'] = applicantscontainer
1156        self.applicantscontainer = self.app['applicants']['trans2017']
1157        # Student with wrong number can't be found.
1158        # Applicant is redirected to application section.
1159        self.browser.open('http://localhost/app/alumni_requestpw')
1160        self.browser.getControl(name="form.lastname").value = 'Tester'
1161        self.browser.getControl(name="form.number").value = 'anynumber'
1162        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
1163        self.browser.getControl("Send login credentials").click()
1164        self.assertTrue('No student record found.'
1165            in self.browser.contents)
1166        self.assertEqual(self.browser.url,
1167            'http://localhost/app/applicants/trans2017/register')
Note: See TracBrowser for help on using the repository browser.