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

Last change on this file since 15980 was 15919, checked in by Henrik Bettermann, 5 years ago

Add officer_1 signature if student is not graduated.

  • Property svn:keywords set to Id
File size: 72.6 KB
Line 
1## $Id: test_browser.py 15919 2020-01-13 17:20:37Z 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, ItemNotFoundError
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,imported_ts\r\n'
49    '234,E1000000,Anna Tester,100,COURSE1,2004,%s,%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', 'mrslecturerSecret1')
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 = 'mrslecturerSecret1'
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.30')
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.course.passmark = 40
136        self.student['studycourse'].entry_mode = 'ug_ft'
137        self.student['studycourse'].addStudentStudyLevel(
138            self.certificate, studylevel)
139        studylevel['COURSE1'].score = 42
140        studylevel['COURSE1'].ca = 0
141        courseticket = createObject('waeup.CourseTicket')
142        self.assertEqual(studylevel['COURSE1'].weight, 1)
143        self.assertEqual(studylevel['COURSE1'].grade, 'E')
144        self.assertEqual(studylevel['COURSE1'].weight, 1)
145        self.assertEqual(studylevel['COURSE1'].grade, 'E')
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.student['payments'][sfpt_value].r_company = u'interswitch'
187        self.browser.open(self.payments_path + '/' + sfpt_value)
188
189        # eTranzact payments deactivated on 01/03/2019
190        #self.browser.getLink("Query eTranzact History").click()
191        #self.assertMatches('...alert-danger">Please pay acceptance fee first...',
192        #                   self.browser.contents)
193        # If clearance/acceptance fee is paid ...
194        self.student['payments'][cpt_value].approveStudentPayment()
195        #self.browser.getLink("Query eTranzact History").click()
196        ## ... query_history page is accessible.
197        #self.assertMatches(
198        #    '...<h1 class="kofa-content-label">Requery eTranzact History</h1>...',
199        #    self.browser.contents)
200
201        # Managers can open school fee payment slip
202        self.browser.open(self.payments_path + '/' + sfpt_value)
203        self.browser.getLink("Download payment slip").click()
204        self.assertEqual(self.browser.headers['Status'], '200 Ok')
205        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
206        # If school fee ticket is paid, the student is automatically set to
207        # school fee paid...
208        ticket = self.student['payments'][sfpt_value].approveStudentPayment()
209        self.assertEqual(self.student.state, 'school fee paid')
210        # ... no further school fee ticket can be added.
211        self.browser.open(self.payments_path + '/addop')
212        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
213        self.browser.getControl("Create ticket").click()
214        self.assertMatches('...Wrong state...',
215                           self.browser.contents)
216        self.browser.open(self.payments_path + '/addop')
217        self.browser.getControl(name="form.p_category").value = ['late_registration']
218        self.browser.getControl("Create ticket").click()
219        self.assertMatches('...ticket created...',
220                           self.browser.contents)
221        return
222
223    def test_for_instalment_payments(self):
224        configuration_1 = createObject('waeup.SessionConfiguration')
225        configuration_1.academic_session = 2015
226        self.app['configuration'].addSessionConfiguration(configuration_1)
227        self.student['studycourse'].certificate.study_mode = 'ug_pt'
228        self.student['studycourse'].certificate.school_fee_1 = 6666.0
229        self.app['configuration']['2015'].union_fee = 1250.0
230        self.app['configuration']['2015'].welfare_fee = 750.0
231        self.student.nationality = u'NG'
232        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
233        self.browser.open(self.payments_path + '/addop')
234        self.assertFalse('schoolfee_1' in self.browser.contents)
235        #self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
236        #self.browser.getControl("Create ticket").click()
237        #self.assertTrue(
238        #    'Part-time students are not allowed' in self.browser.contents)
239        self.student['studycourse'].certificate.study_mode = 'ug_ft'
240        self.browser.open(self.payments_path + '/addop')
241        self.assertTrue('schoolfee_1' in self.browser.contents)
242        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
243        self.browser.getControl("Create ticket").click()
244        self.assertTrue('You are not allowed to pay by instalments.'
245            in self.browser.contents)
246        IWorkflowState(self.student).setState('cleared')
247        self.student['studycourse'].entry_session = 2015
248        self.student['studycourse'].current_session = 2015
249        self.browser.open(self.payments_path + '/addop')
250        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
251        self.browser.getControl("Create ticket").click()
252        self.assertTrue('ticket created' in self.browser.contents)
253        # We can't add the 2nd instalment ticket because the
254        # first one has not yet been approved.
255        #self.browser.open(self.payments_path + '/addop')
256        #self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
257        #self.browser.getControl("Create ticket").click()
258        #self.assertMatches('...1st school fee instalment has not yet been paid...',
259        #                   self.browser.contents)
260        # Ok, then we approve the first instalment ...
261        self.browser.open(self.payments_path)
262        ctrl = self.browser.getControl(name='val_id')
263        p_id = ctrl.options[0]
264        self.browser.open(self.payments_path + '/' + p_id + '/approve')
265        # ... add the second instalment ...
266        self.browser.open(self.payments_path + '/addop')
267        self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
268        self.browser.getControl("Create ticket").click()
269        self.assertTrue('ticket created' in self.browser.contents)
270        # ... approve the second instalment ...
271        ctrl = self.browser.getControl(name='val_id')
272        p_id = ctrl.options[1]
273        self.browser.open(self.payments_path + '/' + p_id + '/approve')
274        self.assertEqual(self.student['payments'].values()[0].p_category, 'schoolfee_1')
275        self.assertEqual(self.student['payments'].values()[1].p_category, 'schoolfee_2')
276        # (6666-200)/2 + 1250 + 750 - 400 + 200
277        self.assertEqual(self.student['payments'].values()[0].amount_auth, 5033.0)
278        # (6666-200)/2 + 200
279        self.assertEqual(self.student['payments'].values()[1].amount_auth, 3433.0)
280        # The  two payments belong to the same session and level.
281        self.assertEqual(self.student['payments'].values()[0].p_session, 2015)
282        self.assertEqual(self.student['payments'].values()[0].p_level, 100)
283        self.assertEqual(self.student['payments'].values()[1].p_session, 2015)
284        self.assertEqual(self.student['payments'].values()[1].p_level, 100)
285
286        # Returning student
287        configuration_2 = createObject('waeup.SessionConfiguration')
288        configuration_2.academic_session = 2016
289        self.app['configuration'].addSessionConfiguration(configuration_2)
290        self.student['studycourse'].certificate.school_fee_2 = 5666.0
291        self.app['configuration']['2016'].union_fee = 1250.0
292        self.app['configuration']['2016'].welfare_fee = 750.0
293        self.student.father_name = u'Albert'
294        IWorkflowState(self.student).setState('returning')
295        self.browser.open(self.payments_path + '/addop')
296        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
297        self.browser.getControl("Create ticket").click()
298        self.browser.open(self.payments_path + '/addop')
299        self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
300        self.browser.getControl("Create ticket").click()
301        # Student is still in the first  session.
302        self.assertTrue('This type of payment' in self.browser.contents)
303        self.browser.open(self.payments_path)
304        ctrl = self.browser.getControl(name='val_id')
305        p_id = ctrl.options[2]
306        self.browser.open(self.payments_path + '/' + p_id + '/approve')
307        self.browser.open(self.payments_path + '/addop')
308        self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
309        self.browser.getControl("Create ticket").click()
310        self.assertTrue('ticket created' in self.browser.contents)
311        # (5666-200)/2 + 1250 + 750 - 400 + 200
312        self.assertEqual(self.student['payments'].values()[2].amount_auth, 4533.0)
313        # (5666-200)/2 + 200
314        self.assertEqual(self.student['payments'].values()[3].amount_auth, 2933.0)
315        # The last two payments belong to the same session and level.
316        self.assertEqual(self.student['payments'].values()[2].p_session, 2016)
317        self.assertEqual(self.student['payments'].values()[2].p_level, 200)
318        self.assertEqual(self.student['payments'].values()[3].p_session, 2016)
319        self.assertEqual(self.student['payments'].values()[3].p_level, 200)
320        return
321
322    def test_manage_payments_bypass_ac_creation(self):
323        self.student['studycourse'].certificate.school_fee_1 = 6666.0
324        self.student.nationality = u'NG'
325        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
326        self.browser.open(self.payments_path)
327        IWorkflowState(self.student).setState('cleared')
328        self.browser.getLink("Add current session payment ticket").click()
329        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
330        self.browser.getControl("Create ticket").click()
331        ctrl = self.browser.getControl(name='val_id')
332        value = ctrl.options[0]
333        self.browser.getLink(value).click()
334        payment_url = self.browser.url
335        logfile = os.path.join(
336            self.app['datacenter'].storage, 'logs', 'students.log')
337        # The ticket can be found in the payments_catalog
338        cat = queryUtility(ICatalog, name='payments_catalog')
339        results = list(cat.searchResults(p_state=('unpaid', 'unpaid')))
340        self.assertTrue(len(results), 1)
341        self.assertTrue(results[0] is self.student['payments'][value])
342        # Managers can approve the payment
343        self.browser.open(payment_url)
344        self.browser.getLink("Approve payment").click()
345        self.assertMatches('...Payment approved...',
346                          self.browser.contents)
347        # Approval is logged in students.log ...
348        logcontent = open(logfile).read()
349        self.assertTrue(
350            'zope.mgr - students.browser.OnlinePaymentApproveView '
351            '- E1000000 - schoolfee_incl payment approved'
352            in logcontent)
353        # ... and in payments.log
354        logfile = os.path.join(
355            self.app['datacenter'].storage, 'logs', 'payments.log')
356        logcontent = open(logfile).read()
357        self.assertTrue(
358            '"zope.mgr",E1000000,%s,schoolfee_incl,6666.0,AP,,,,,,\n' % value
359            in logcontent)
360        # Student is in state school fee paid, no activation
361        # code was necessary.
362        self.assertEqual(self.student.state, 'school fee paid')
363        self.assertEqual(len(self.app['accesscodes']['SFE-0']),0)
364        return
365
366    def test_scores_csv_upload_available(self):
367        # lecturers can upload a CSV file to set values.
368        self.login_as_lecturer()
369        # set value to change from
370        self.student['studycourse']['100']['COURSE1'].score = 55
371        self.app['configuration']['2004'].score_editing_enabled = ['ug_ft']
372        self.browser.open(self.edit_scores_url)
373        upload_ctrl = self.browser.getControl(name='uploadfile:file')
374        upload_file = StringIO(UPLOAD_CSV_TEMPLATE % ('65','22','77'))
375        upload_ctrl.add_file(upload_file, 'text/csv', 'myscores.csv')
376        self.browser.getControl("Update editable scores from").click()
377        # value changed
378        self.assertEqual(
379            self.student['studycourse']['100']['COURSE1'].score, 65)
380        self.assertEqual(
381            self.student['studycourse']['100']['COURSE1'].ca, 22)
382        self.assertEqual(
383            self.student['studycourse']['100']['COURSE1'].imported_ts, 77)
384
385    def test_scores_previous_session(self):
386        # lecturers can download a CSV file to set values.
387        self.login_as_lecturer()
388        self.student['studycourse']['100']['COURSE1'].score = 55
389        self.browser.open(self.edit_prev_scores_url)
390        self.assertTrue('No student found' in self.browser.contents)
391        configuration = createObject('waeup.SessionConfiguration')
392        configuration.academic_session = 2003
393        self.app['configuration'].addSessionConfiguration(configuration)
394        self.app['configuration']['2003'].score_editing_enabled = ['ug_ft']
395        self.student['studycourse']['100'].level_session = 2003
396        notify(grok.ObjectModifiedEvent(self.student['studycourse']['100']['COURSE1']))
397        self.browser.open(self.edit_prev_scores_url)
398        self.browser.getLink("Download csv file").click()
399        self.assertEqual(self.browser.headers['Status'], '200 Ok')
400        self.assertEqual(self.browser.headers['Content-Type'],
401                         'text/csv; charset=UTF-8')
402        self.assertEqual(self.browser.contents,
403            'matric_number,student_id,display_fullname,'
404            'depcode,faccode,level,code,level_session,ca,score,'
405            'total_score,grade,imported_ts\r\n234,E1000000,"TESTER, Anna",dep1,fac1,'
406            '100,COURSE1,2003,,55,,,\r\n')
407        self.browser.open(self.edit_prev_scores_url)
408        upload_ctrl = self.browser.getControl(name='uploadfile:file')
409        upload_file = StringIO(UPLOAD_CSV_TEMPLATE % ('65','22','77'))
410        upload_ctrl.add_file(upload_file, 'text/csv', 'myscores.csv')
411        self.browser.getControl("Update editable scores from").click()
412        # value changed
413        self.assertEqual(
414            self.student['studycourse']['100']['COURSE1'].score, 65)
415        self.assertEqual(
416            self.student['studycourse']['100']['COURSE1'].ca, 22)
417        self.assertEqual(
418            self.student['studycourse']['100']['COURSE1'].imported_ts, 77)
419
420    def test_lecturers_can_download_course_tickets(self):
421        # A course ticket slip can be downloaded
422        self.login_as_lecturer()
423        self.course.title = (u'Lorem ipsum dolor sit amet, consectetur '
424                            u'adipisici elit, sed eiusmod tempor incidunt')
425        self.student['studycourse']['100']['COURSE1'].score = 55
426        self.student['studycourse']['100']['COURSE1'].ca = 11
427        self.student.matric_number = u'CMS/FBM/NSG/16/28838'
428        self.app['configuration']['2004'].score_editing_enabled = ['ug_ft']
429        pdf_url = '%s/coursetickets.pdf' % self.course_url
430        self.browser.open(pdf_url)
431        self.assertEqual(self.browser.headers['Status'], '200 Ok')
432        self.assertEqual(
433            self.browser.headers['Content-Type'], 'application/pdf')
434        path = os.path.join(samples_dir(), 'coursetickets.pdf')
435        open(path, 'wb').write(self.browser.contents)
436        print "Sample PDF coursetickets.pdf written to %s" % path
437        # The CA column is not shown if CA is not used
438        self.student['studycourse']['100']['COURSE1'].ca = 0
439        self.browser.open(pdf_url)
440        path = os.path.join(samples_dir(), 'coursetickets_wo_ca.pdf')
441        open(path, 'wb').write(self.browser.contents)
442        print "Sample PDF coursetickets_wo_ca.pdf written to %s" % path
443
444    def test_lecturers_do_only_see_selected_students(self):
445        # A course ticket slip can be downloaded
446        self.login_as_lecturer()
447        self.student['studycourse']['100']['COURSE1'].score = 55
448        self.student['studycourse']['100']['COURSE1'].ca = 11
449        self.browser.open(self.edit_scores_url)
450        self.assertTrue('No student found' in self.browser.contents)
451        pdf_url = '%s/coursetickets.pdf' % self.course_url
452        self.browser.open(pdf_url)
453        self.assertEqual(self.browser.headers['Status'], '200 Ok')
454        self.assertEqual(
455            self.browser.headers['Content-Type'], 'application/pdf')
456        path = os.path.join(samples_dir(), 'coursetickets_filtered.pdf')
457        open(path, 'wb').write(self.browser.contents)
458        print "Sample PDF coursetickets_filtered.pdf written to %s" % path
459        self.app['configuration']['2004'].score_editing_enabled = ['ug_ft']
460        self.browser.open(self.edit_scores_url)
461        self.assertFalse('No student found' in self.browser.contents)
462        self.assertTrue('TESTER, Anna' in self.browser.contents)
463
464    def test_lecturers_can_download_attendance_sheet(self):
465        # A course ticket slip can be downloaded
466        self.course.title = (u'Lorem ipsum     dolor sit amet, consectetur     adipisici, '
467                             u'sed         eiusmod tempor    incidunt ut  labore et dolore')
468        self.student.firstname = u'Emmanuella Woyengifigha Mercy Onosemudiana'
469        self.student.lastname = u'OYAKEMIEGBEGHA'
470        self.student.matric_number = u'CMS/FBM/NSG/17/38186'
471        self.login_as_lecturer()
472        pdf_url = '%s/attendance.pdf' % self.course_url
473        self.browser.open(pdf_url)
474        self.assertEqual(self.browser.headers['Status'], '200 Ok')
475        self.assertEqual(
476            self.browser.headers['Content-Type'], 'application/pdf')
477        path = os.path.join(samples_dir(), 'attendance.pdf')
478        open(path, 'wb').write(self.browser.contents)
479        print "Sample PDF attendance.pdf written to %s" % path
480
481    def test_transcripts(self):
482        studylevel = createObject(u'waeup.StudentStudyLevel')
483        studylevel.level = 100
484        studylevel.level_session = 2005
485        self.student['studycourse'].entry_mode = 'ug_ft'
486        self.student['studycourse'].addStudentStudyLevel(
487            self.certificate, studylevel)
488        studylevel2 = createObject(u'waeup.StudentStudyLevel')
489        studylevel2.level = 200
490        studylevel2.level_session = 2006
491        self.student['studycourse']['100']['COURSE1'].score = 33 # no carry-over!
492        self.student['studycourse']['100']['COURSE1'].ca = 22
493        self.student['studycourse'].addStudentStudyLevel(
494            self.certificate, studylevel2)
495        # Add second course (COURSE has been added automatically)
496        courseticket = createObject('waeup.CourseTicket')
497        courseticket.code = 'ANYCODE'
498        courseticket.title = u'Any TITLE'
499        courseticket.credits = 13
500        courseticket.score = 55
501        courseticket.ca = 11
502        courseticket.semester = 1
503        courseticket.dcode = u'ANYDCODE'
504        courseticket.fcode = u'ANYFCODE'
505        self.student['studycourse']['200']['COURSE2'] = courseticket
506        self.assertEqual(self.student['studycourse']['100'].gpa_params_rectified[0], 3.0)
507        self.assertEqual(self.student['studycourse']['200'].gpa_params_rectified[0], 4.0)
508        # Get transcript data
509        td = self.student['studycourse'].getTranscriptData()
510        self.assertEqual(td[0][0]['level_key'], '100')
511        self.assertEqual(td[0][0]['sgpa'], 3.0)
512        self.assertEqual(td[0][0]['level'].level, 100)
513        self.assertEqual(td[0][0]['level'].level_session, 2005)
514        self.assertEqual(td[0][0]['tickets_1'][0].code, 'COURSE1')
515        self.assertEqual(td[0][1]['level_key'], '200')
516        self.assertEqual(td[0][1]['sgpa'], 4.0)
517        self.assertEqual(td[0][1]['level'].level, 200)
518        self.assertEqual(td[0][1]['level'].level_session, 2006)
519        self.assertEqual(td[0][1]['tickets_1'][0].code, 'ANYCODE')
520        self.assertEqual(td[1], 3.5652173913043477)
521        # Set Officer 1
522        self.app['faculties']['fac1']['dep1'].officer_1 = u'Transcript Boss'
523        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
524        self.browser.open(self.student_path + '/studycourse/transcript')
525        self.assertEqual(self.browser.headers['Status'], '200 Ok')
526        self.assertTrue('Transcript' in self.browser.contents)
527        # Officers can open the pdf transcript
528        self.browser.open(self.student_path + '/studycourse/transcript.pdf')
529        self.assertEqual(self.browser.headers['Status'], '200 Ok')
530        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
531        path = os.path.join(samples_dir(), 'transcript.pdf')
532        open(path, 'wb').write(self.browser.contents)
533        print "Sample PDF transcript.pdf written to %s" % path
534
535    def test_payment_disabled(self):
536        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
537        self.browser.open(self.payments_path)
538        IWorkflowState(self.student).setState('cleared')
539        self.browser.getLink("Add current session payment ticket").click()
540        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
541        self.browser.getControl("Create ticket").click()
542        self.assertMatches('...ticket created...', self.browser.contents)
543        self.app['configuration']['2004'].payment_disabled = ['sf_all']
544        self.browser.getLink("Add current session payment ticket").click()
545        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
546        self.browser.getControl("Create ticket").click()
547        self.assertMatches('...This category of payments has been disabled...',
548                           self.browser.contents)
549
550        self.app['configuration']['2004'].payment_disabled = ['sf_ug_pt']
551        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
552        self.browser.getControl("Create ticket").click()
553        self.assertMatches('...ticket created...', self.browser.contents)
554        self.certificate.study_mode = 'ug_pt'
555        self.browser.getLink("Add current session payment ticket").click()
556        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
557        self.browser.getControl("Create ticket").click()
558        self.assertMatches('...This category of payments has been disabled...',
559                           self.browser.contents)
560
561        self.app['configuration']['2004'].payment_disabled = ['sf_pg']
562        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
563        self.browser.getControl("Create ticket").click()
564        self.assertMatches('...ticket created...', self.browser.contents)
565        self.certificate.study_mode = 'special_pg_ft'
566        self.browser.getLink("Add current session payment ticket").click()
567        self.browser.getControl(name="form.p_category").value = ['schoolfee']
568        self.browser.getControl("Create ticket").click()
569        self.assertMatches('...This category of payments has been disabled...',
570                           self.browser.contents)
571        return
572
573class StudentUITests(StudentsFullSetup):
574    """Tests for customized student class views and pages
575    """
576
577    layer = FunctionalLayer
578
579    def setUp(self):
580        super(StudentUITests, self).setUp()
581
582        bedticket = BedTicket()
583        bedticket.booking_session = 2004
584        bedticket.bed_type = u'any bed type'
585        bedticket.bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
586        bedticket.bed_coordinates = u'My bed coordinates'
587        self.student['accommodation'].addBedTicket(bedticket)
588
589    def test_maintenance_fee_payment(self):
590        self.certificate.study_mode = 'ug_ft'
591        self.student['studycourse'].entry_session = 2013
592        self.student.nationality = u'NG'
593        IWorkflowState(self.student).setState('cleared')
594        self.browser.open(self.login_path)
595        self.browser.getControl(name="form.login").value = self.student_id
596        self.browser.getControl(name="form.password").value = 'spwd'
597        self.browser.getControl("Login").click()
598        self.browser.open(self.student_path + '/payments')
599        self.browser.getLink("Add current session payment ticket").click()
600        self.browser.getControl(name="form.p_category").value = ['hostel_maintenance']
601        self.browser.getControl("Create ticket").click()
602        self.assertTrue('ticket created' in self.browser.contents)
603        value = self.student['payments'].keys()[0]
604        self.browser.getLink(value).click()
605        self.assertTrue('<span>My bed coordinates</span>' in self.browser.contents)
606        self.assertEqual(self.student['payments'][value].amount_auth, 876.0)
607        return
608
609    def test_student_schoolfee_payments(self):
610        configuration_1 = createObject('waeup.SessionConfiguration')
611        configuration_1.academic_session = 2016
612        self.app['configuration'].addSessionConfiguration(configuration_1)
613        self.certificate.study_mode = 'ug_ft'
614        self.student['studycourse'].entry_session = 2016
615        self.student['studycourse'].current_session = 2016
616        self.student['studycourse'].entry_mode = 'ug_ft'
617        self.student['studycourse'].certificate.school_fee_1 = 50200.0
618        self.app['configuration']['2016'].union_fee = 1200.0
619        self.app['configuration']['2016'].welfare_fee = 700.0
620        self.app['configuration']['2016'].id_card_fee = 300.0
621        self.student.nationality = u'NG'
622        # Login
623        IWorkflowState(self.student).setState('cleared')
624        self.browser.open(self.login_path)
625        self.browser.getControl(name="form.login").value = self.student_id
626        self.browser.getControl(name="form.password").value = 'spwd'
627        self.browser.getControl("Login").click()
628        # Test school fee payments
629        self.browser.open(self.student_path + '/payments')
630        self.browser.getLink("Add current session payment ticket").click()
631        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
632        self.browser.getControl("Create ticket").click()
633        self.assertTrue('ticket created' in self.browser.contents)
634        value = self.student['payments'].keys()[0]
635        self.browser.getLink(value).click()
636        self.assertTrue('Amount Authorized' in self.browser.contents)
637        # 50200 + 1200 + 700 + 300 - 600 = 51800
638        self.assertEqual(self.student['payments'][value].amount_auth, 51800.0)
639        self.student['payments'][value].r_company = u'interswitch'
640        self.browser.open(self.browser.url + '/payment_slip.pdf')
641        self.assertEqual(self.browser.headers['Status'], '200 Ok')
642        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
643        path = os.path.join(samples_dir(), 'payment_slip.pdf')
644        open(path, 'wb').write(self.browser.contents)
645        print "Sample PDF payment_slip.pdf written to %s" % path
646        # Another school fee payment cannot be added
647        self.student['payments'][value].approve()
648        self.browser.open(self.student_path + '/payments')
649        self.browser.getLink("Add current session payment ticket").click()
650        self.browser.getControl(name="form.p_category").value = ['schoolfee']
651        self.browser.getControl("Create ticket").click()
652        self.assertTrue(
653            'You must choose a payment which includes additional fees'
654            in self.browser.contents)
655        return
656
657    def test_late_registration(self):
658        delta = timedelta(days=10)
659        self.app['configuration'][
660            '2004'].coursereg_deadline = datetime.now(pytz.utc) - delta
661        IWorkflowState(self.student).setState('school fee paid')
662        # Current session is 2004. Here we test course registration for
663        # returning students.
664        self.student['studycourse'].entry_session = 2003
665        self.student['studycourse'].current_session = 2016
666        # Login
667        self.browser.open(self.login_path)
668        self.browser.getControl(name="form.login").value = self.student_id
669        self.browser.getControl(name="form.password").value = 'spwd'
670        self.browser.getControl("Login").click()
671        # Make restitution fee payment
672        # Ivie: The restitution was only for returning students of 2016/2017.
673        # Hence, it is only valid for 2016 payment session returning students.
674        configuration = createObject('waeup.SessionConfiguration')
675        configuration.academic_session = 2016
676        self.app['configuration'].addSessionConfiguration(configuration)
677        self.app['configuration']['2016'].restitution_fee = 9999.0
678        self.browser.open(self.payments_path + '/addop')
679        self.browser.getControl(name="form.p_category").value = ['restitution']
680        self.browser.getControl("Create ticket").click()
681        self.student['payments'].values()[0].approveStudentPayment()
682        # Make late registration fee payment
683        self.student['studycourse'].current_session = 2004
684        self.browser.open(self.payments_path + '/addop')
685        self.browser.getControl(name="form.p_category").value = ['late_registration']
686        self.browser.getControl("Create ticket").click()
687        self.assertMatches('...ticket created...',
688                           self.browser.contents)
689        self.browser.getLink("Study Course").click()
690        self.browser.getLink("Add course list").click()
691        self.assertMatches('...Add current level 100 (Year 1)...',
692                           self.browser.contents)
693        self.browser.getControl("Create course list now").click()
694        self.student['studycourse']['100']['COURSE1'].score = 67
695        self.browser.getLink("100").click()
696        # Course results can't be seen
697        self.assertFalse('<td>67</td>' in self.browser.contents)
698        self.browser.getLink("Edit course list").click()
699        self.assertFalse('<td>67</td>' in self.browser.contents)
700        self.app['configuration']['2004'].late_registration_fee = 0.0
701        self.browser.getControl("Register course list").click()
702        self.assertTrue('Course registration has been disabled.' in self.browser.contents)
703        self.app['configuration']['2004'].late_registration_fee = 345.0
704        self.browser.getControl("Register course list").click()
705        self.assertTrue('Course registration has ended. Please pay' in self.browser.contents)
706        self.student['payments'].values()[1].approve()
707        self.browser.getControl("Register course list").click()
708        self.assertTrue('Course list has been registered' in self.browser.contents)
709        self.assertEqual(self.student.state, 'courses registered')
710        # Reset student and check if fresh students are always allowed to
711        # register courses.
712        #self.student['studycourse'].entry_session = 2004
713        #del self.student['payments'][self.student['payments'].keys()[1]]
714        #IWorkflowState(self.student).setState('school fee paid')
715        #self.browser.open(self.studycourse_path + '/100/edit')
716        #self.browser.getControl("Register course list").click()
717        #self.assertTrue('Course list has been registered' in self.browser.contents)
718        return
719
720
721    def deactivated_test_student_course_registration(self):
722        # Add more courses
723        self.course2 = createObject('waeup.Course')
724        self.course2.code = 'COURSE2'
725        self.course2.semester = 2
726        self.course2.credits = 10
727        self.course2.passmark = 40
728        self.app['faculties']['fac1']['dep1'].courses.addCourse(
729            self.course2)
730        self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCertCourse(
731            self.course2, level=100)
732        self.course3 = createObject('waeup.Course')
733        self.course3.code = 'COURSE3'
734        self.course3.semester = 3
735        self.course3.credits = 10
736        self.course3.passmark = 40
737        self.app['faculties']['fac1']['dep1'].courses.addCourse(
738            self.course3)
739        self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCertCourse(
740            self.course3, level=100)
741
742        # Login as student
743        self.browser.open(self.login_path)
744        IWorkflowState(self.student).setState('school fee paid')
745        self.browser.open(self.login_path)
746        self.browser.getControl(name="form.login").value = self.student_id
747        self.browser.getControl(name="form.password").value = 'spwd'
748        self.browser.getControl("Login").click()
749        # Students can add the current study level
750        self.browser.getLink("Study Course").click()
751        self.browser.getLink("Add course list").click()
752        self.assertMatches('...Add current level 100 (Year 1)...',
753                           self.browser.contents)
754        self.browser.getControl("Create course list now").click()
755        # Student has not paid second instalment, therefore a level
756        # with two course ticket was created (semester 1 and combined)
757        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 2)
758        self.browser.getLink("100").click()
759        self.browser.getLink("Edit course list").click()
760        self.browser.getControl("Add course ticket").click()
761        # Student can't add second semester course
762        self.assertTrue('<option value="COURSE1">' in self.browser.contents)
763        self.assertTrue('<option value="COURSE3">' in self.browser.contents)
764        self.assertFalse('<option value="COURSE2">' in self.browser.contents)
765
766        # Let's remove level and see what happens after 2nd instalment payment
767        del(self.student['studycourse']['100'])
768        payment2 = createObject('waeup.StudentOnlinePayment')
769        payment2.p_category = u'schoolfee_2'
770        payment2.p_session = self.student.current_session
771        self.student['payments']['anykey'] = payment2
772        self.browser.open(self.studycourse_path)
773        self.browser.getLink("Add course list").click()
774        self.browser.getControl("Create course list now").click()
775        # Still only 2 tickets have been created since payment ticket
776        # was not paid
777        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 2)
778        payment2.p_state = u'paid'
779        del(self.student['studycourse']['100'])
780        self.browser.open(self.studycourse_path)
781        self.browser.getLink("Add course list").click()
782        self.browser.getControl("Create course list now").click()
783        # Now 2nd semester course has been added
784        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 3)
785        # Student can add second semester course
786        self.browser.getLink("100").click()
787        self.browser.getLink("Edit course list").click()
788        self.browser.getControl("Add course ticket").click()
789        self.assertTrue('<option value="COURSE1">' in self.browser.contents)
790        self.assertTrue('<option value="COURSE2">' in self.browser.contents)
791        self.assertTrue('<option value="COURSE3">' in self.browser.contents)
792        return
793
794    def test_set_matric_number(self):
795        #payment = createObject('waeup.StudentOnlinePayment')
796        #payment.p_category = u'concessional'
797        #payment.p_id = u'anyid'
798        #payment.p_state = u'paid'
799        #self.student['payments']['anykey'] = payment
800        # Login as student
801        self.browser.open(self.login_path)
802        IWorkflowState(self.student).setState('school fee paid')
803        self.browser.open(self.login_path)
804        self.browser.getControl(name="form.login").value = self.student_id
805        self.browser.getControl(name="form.password").value = 'spwd'
806        self.browser.getControl("Login").click()
807        self.assertRaises(
808            LinkNotFoundError,
809            self.browser.getLink, 'Get Matriculation Number')
810        self.student.matric_number = None
811        site = grok.getSite()
812        site['configuration'].next_matric_integer = 1
813        self.student['studycourse'].certificate.study_mode = 'ug_pt'
814        self.browser.open(self.student_path)
815        self.assertRaises(
816            LinkNotFoundError,
817            self.browser.getLink, 'Download matriculation number slip')
818        self.browser.getLink("Get Matriculation Number").click()
819        self.assertTrue('Matriculation number PTP/fac1/dep1/04/00001 assigned.'
820            in self.browser.contents)
821        self.assertEqual(self.student.matric_number, 'PTP/fac1/dep1/04/00001')
822        self.assertRaises(
823            LinkNotFoundError,
824            self.browser.getLink, 'Get Matriculation Number')
825        # Setting matric number is logged.
826        logfile = os.path.join(
827            self.app['datacenter'].storage, 'logs', 'students.log')
828        logcontent = open(logfile).read()
829        self.assertTrue('E1000000 - waeup.aaue.students.browser.StudentGetMatricNumberPage - '
830                        'E1000000 - PTP/fac1/dep1/04/00001 assigned' in logcontent)
831        # Matric Number Slip can be downloaded
832        self.browser.getLink("Download matriculation number slip").click()
833        self.assertEqual(self.browser.headers['Status'], '200 Ok')
834        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
835        path = os.path.join(samples_dir(), 'matric_number_slip.pdf')
836        open(path, 'wb').write(self.browser.contents)
837        print "Sample PDF matric_number_slip.pdf written to %s" % path
838        return
839
840    def test_personal_data_slip(self):
841        # Login as student
842        self.browser.open(self.login_path)
843        IWorkflowState(self.student).setState('school fee paid')
844        self.browser.open(self.login_path)
845        self.browser.getControl(name="form.login").value = self.student_id
846        self.browser.getControl(name="form.password").value = 'spwd'
847        self.browser.getControl("Login").click()
848        self.browser.getLink("Personal Data").click()
849        self.assertRaises(
850            LinkNotFoundError,
851            self.browser.getLink, 'Download personal data slip')
852        self.student.father_name = u'Rudolf'
853        self.browser.open(self.personal_path)
854        self.browser.getLink("Download personal data slip").click()
855        self.assertEqual(self.browser.headers['Status'], '200 Ok')
856        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
857        path = os.path.join(samples_dir(), 'personal_data_slip.pdf')
858        open(path, 'wb').write(self.browser.contents)
859        print "Sample PDF personal_data_slip.pdf written to %s" % path
860        return
861
862    def test_student_course_registration(self):
863        IWorkflowState(self.student).setState('school fee paid')
864        self.browser.open(self.login_path)
865        self.browser.getControl(name="form.login").value = self.student_id
866        self.browser.getControl(name="form.password").value = 'spwd'
867        self.browser.getControl("Login").click()
868        # Now students can add the current study level
869        self.browser.getLink("Study Course").click()
870        self.browser.getLink("Add course list").click()
871        self.assertMatches('...Add current level 100 (Year 1)...',
872                           self.browser.contents)
873        self.browser.getControl("Create course list now").click()
874        # Students can't open the customized pdf course registration slip
875        self.browser.open(
876            self.student_path + '/studycourse/100/course_registration_slip.pdf')
877        self.assertTrue('Forbidden' in self.browser.contents)
878        # They can open slips from the previous session ...
879        self.student['studycourse'].current_level = 200
880        self.browser.open(self.student_path + '/studycourse/100')
881        self.browser.getLink("Download course registration slip").click()
882        self.assertEqual(self.browser.headers['Status'], '200 Ok')
883        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
884        # or if they have registered their course list
885        self.student['studycourse'].current_level = 200
886        IWorkflowState(self.student).setState('courses registered')
887        self.browser.open(self.student_path + '/studycourse/100')
888        self.browser.getLink("Download course registration slip").click()
889        self.assertEqual(self.browser.headers['Status'], '200 Ok')
890        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
891        path = os.path.join(samples_dir(), 'ft_course_registration_slip.pdf')
892        open(path, 'wb').write(self.browser.contents)
893        print "Sample PDF ft_course_registration_slip.pdf written to %s" % path
894
895        self.certificate.study_mode = 'ug_pt'
896        self.browser.open(self.student_path + '/studycourse/100')
897        self.browser.getLink("Download course registration slip").click()
898        self.assertEqual(self.browser.headers['Status'], '200 Ok')
899        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
900        path = os.path.join(samples_dir(), 'pt_course_registration_slip.pdf')
901        open(path, 'wb').write(self.browser.contents)
902        print "Sample PDF pt_course_registration_slip.pdf written to %s" % path
903
904        self.certificate.study_mode = 'special_pg_ft'
905        self.student.matric_number = u'AAU/SPS/FLW/LAW/15/PHD/09504'
906        self.browser.open(self.student_path + '/studycourse/100')
907        self.browser.getLink("Download course registration slip").click()
908        self.assertEqual(self.browser.headers['Status'], '200 Ok')
909        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
910        path = os.path.join(samples_dir(), 'pg_course_registration_slip.pdf')
911        open(path, 'wb').write(self.browser.contents)
912        print "Sample PDF pg_course_registration_slip.pdf written to %s" % path
913
914        # Students cant' view scores, cas and grades.
915        self.browser.open(self.student_path + '/studycourse/100')
916        self.assertFalse('Score' in self.browser.contents)
917        self.assertFalse('CA' in self.browser.contents)
918        self.assertFalse('Grade' in self.browser.contents)
919        self.browser.getLink("COURSE1").click()
920        self.browser.open(self.student_path + '/studycourse/100')
921        self.assertFalse('Score' in self.browser.contents)
922        self.assertFalse('CA' in self.browser.contents)
923        self.assertFalse('Grade' in self.browser.contents)
924
925    def test_student_2nd_semester_course_registration(self):
926        IWorkflowState(self.student).setState('school fee paid')
927        self.student['studycourse'].entry_session = 2015
928        self.course.semester = 2
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.assertFalse('COURSE1' in self.browser.contents)
937        # 2nd semester tickets can't be added manually
938        self.browser.getLink("Edit course list").click()
939        self.browser.getLink("here").click()
940        self.browser.getControl(name="form.course").value = ['COURSE1']
941        self.browser.getControl("Add course ticket").click()
942        self.assertTrue(
943            'COURSE1 is a 2nd semester course which can only '
944            'be added if school fees have been fully paid.'
945            in self.browser.contents)
946        # 2nd instalment has to be paid first
947        self.certificate.school_fee_3 = 678.0
948        self.browser.open(self.payments_path + '/addop')
949        self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
950        self.browser.getControl("Create ticket").click()
951        self.student['payments'].values()[0].approve()
952        self.browser.open(self.studycourse_path + '/100/ctadd')
953        self.browser.getControl(name="form.course").value = ['COURSE1']
954        self.browser.getControl("Add course ticket").click()
955        self.assertTrue('Successfully added COURSE1' in self.browser.contents)
956        return
957
958    def test_student_GST_registration(self):
959        configuration_1 = createObject('waeup.SessionConfiguration')
960        configuration_1.academic_session = 2016
961        configuration_1.gst_registration_1_fee = 3333.0
962        configuration_1.gst_text_book_1_fee = 4444.0
963        configuration_1.gst_text_book_0_fee = 2222.0
964        self.app['configuration'].addSessionConfiguration(configuration_1)
965        course = createObject('waeup.Course')
966        course.code = 'GST101'
967        course.semester = 1
968        course.credits = 10
969        course.passmark = 40
970        self.app['faculties']['fac1']['dep1'].courses.addCourse(
971            course)
972        self.app['faculties']['fac1']['dep1'].certificates[
973            'CERT1'].addCertCourse(course, level=100)
974        IWorkflowState(self.student).setState('school fee paid')
975        self.student['studycourse'].entry_session = 2016
976        self.student['studycourse'].current_session = 2016
977        self.course.semester = 2
978        self.browser.open(self.login_path)
979        self.browser.getControl(name="form.login").value = self.student_id
980        self.browser.getControl(name="form.password").value = 'spwd'
981        self.browser.getControl("Login").click()
982        self.browser.getLink("Study Course").click()
983        self.browser.getLink("Add course list").click()
984        self.browser.getControl("Create course list now").click()
985        self.assertFalse('GST101' in self.browser.contents)
986        # GST101 tickets can't be added manually
987        self.browser.getLink("Edit course list").click()
988        self.browser.getLink("here").click()
989        self.browser.getControl(name="form.course").value = ['GST101']
990        self.browser.getControl("Add course ticket").click()
991        self.assertTrue(
992            'GST101 can only be added if both registration fee and text'
993            in self.browser.contents)
994        # GST fees have to be paid first
995        self.browser.open(self.payments_path + '/addop')
996        self.browser.getControl(name="form.p_category").value = ['gst_registration_1']
997        self.browser.getControl("Create ticket").click()
998        self.student['payments'].values()[0].approve()
999        self.browser.open(self.studycourse_path + '/100/ctadd')
1000        self.browser.getControl(name="form.course").value = ['GST101']
1001        self.browser.getControl("Add course ticket").click()
1002        self.assertTrue(
1003            'GST101 can only be added if both registration fee and text'
1004            in self.browser.contents)
1005        self.browser.open(self.payments_path + '/addop')
1006        self.browser.getControl(name="form.p_category").value = ['gst_text_book_0']
1007        self.browser.getControl("Create ticket").click()
1008        self.student['payments'].values()[1].approve()
1009        self.browser.open(self.studycourse_path + '/100/ctadd')
1010        self.browser.getControl(name="form.course").value = ['GST101']
1011        self.browser.getControl("Add course ticket").click()
1012        self.assertTrue('Successfully added GST101' in self.browser.contents)
1013        return
1014
1015    def test_course_registration_forbidden(self):
1016        IWorkflowState(self.student).setState('school fee paid')
1017        self.student['studycourse'].entry_session = 2016
1018        self.student['studycourse'].current_session = 2016
1019        self.browser.open(self.login_path)
1020        self.browser.getControl(name="form.login").value = self.student_id
1021        self.browser.getControl(name="form.password").value = 'spwd'
1022        self.browser.getControl("Login").click()
1023        self.browser.getLink("Study Course").click()
1024        self.browser.getLink("Add course list").click()
1025        self.browser.getControl("Create course list now").click()
1026        self.browser.getLink("Edit course list").click()
1027        self.browser.getControl("Register course list").click()
1028        #self.assertTrue('Please pay faculty and departmental dues first'
1029        #    in self.browser.contents)
1030        #configuration_1 = createObject('waeup.SessionConfiguration')
1031        #configuration_1.academic_session = 2016
1032        #configuration_1.fac_dep_fee = 9999.0
1033        #self.app['configuration'].addSessionConfiguration(configuration_1)
1034        #self.browser.open(self.payments_path + '/addop')
1035        #self.browser.getControl(name="form.p_category").value = ['fac_dep']
1036        #self.browser.getControl("Create ticket").click()
1037        #self.student['payments'].values()[0].approveStudentPayment()
1038        #self.browser.open(self.studycourse_path + '/100/edit')
1039        #self.browser.getControl("Register course list").click()
1040
1041        ######################################################
1042        # Temporarily disabled ug_ft course registration
1043        #self.assertTrue('Course registration has been disabled'
1044        #    in self.browser.contents)
1045        #return
1046        ######################################################
1047
1048        self.assertTrue('Course list has been registered'
1049            in self.browser.contents)
1050        return
1051
1052    def test_course_registration_forbidden_2(self):
1053        IWorkflowState(self.student).setState('school fee paid')
1054        self.student['studycourse'].entry_session = 2004
1055        self.student['studycourse'].current_session = 2016
1056        self.browser.open(self.login_path)
1057        self.browser.getControl(name="form.login").value = self.student_id
1058        self.browser.getControl(name="form.password").value = 'spwd'
1059        self.browser.getControl("Login").click()
1060        self.browser.getLink("Study Course").click()
1061        self.browser.getLink("Add course list").click()
1062        self.browser.getControl("Create course list now").click()
1063        self.browser.getLink("Edit course list").click()
1064        self.browser.getControl("Register course list").click()
1065
1066        ######################################################
1067        # Temporarily disabled ug_ft course registration
1068        #self.assertTrue('Course registration has been disabled'
1069        #    in self.browser.contents)
1070        #return
1071        ######################################################
1072
1073        self.assertTrue('Please pay restitution fee first'
1074            in self.browser.contents)
1075        configuration = createObject('waeup.SessionConfiguration')
1076        configuration.academic_session = 2016
1077        self.app['configuration'].addSessionConfiguration(configuration)
1078        self.app['configuration']['2016'].restitution_fee = 9999.0
1079        self.browser.open(self.payments_path + '/addop')
1080        self.browser.getControl(name="form.p_category").value = ['restitution']
1081        self.browser.getControl("Create ticket").click()
1082        self.student['payments'].values()[0].approveStudentPayment()
1083        self.browser.open(self.studycourse_path + '/100/edit')
1084        self.browser.getControl("Register course list").click()
1085        self.assertTrue('Course list has been registered'
1086            in self.browser.contents)
1087        return
1088
1089    def test_student_access_course_results(self):
1090        IWorkflowState(self.student).setState('school fee paid')
1091        self.student['studycourse'].entry_session = 2004
1092        self.student['studycourse'].current_session = 2004
1093        self.browser.open(self.login_path)
1094        self.browser.getControl(name="form.login").value = self.student_id
1095        self.browser.getControl(name="form.password").value = 'spwd'
1096        self.browser.getControl("Login").click()
1097        self.browser.getLink("Study Course").click()
1098        self.browser.getLink("Add course list").click()
1099        self.browser.getControl("Create course list now").click()
1100        self.assertFalse('Score' in self.browser.contents)
1101        IWorkflowState(self.student).setState('returning')
1102        self.browser.open(self.studycourse_path + '/100')
1103        self.assertFalse('Score' in self.browser.contents)
1104        self.app['configuration']['2004'].show_results = ['ug_ft']
1105        self.browser.open(self.studycourse_path + '/100')
1106        self.assertTrue('Score' in self.browser.contents)
1107        return
1108
1109    def test_repair_course_list(self):
1110        IWorkflowState(self.student).setState('school fee paid')
1111        self.student['studycourse'].entry_session = 2016
1112        self.student['studycourse'].current_session = 2016
1113        self.browser.open(self.login_path)
1114        self.browser.getControl(name="form.login").value = self.student_id
1115        self.browser.getControl(name="form.password").value = 'spwd'
1116        self.browser.getControl("Login").click()
1117        self.browser.getLink("Study Course").click()
1118        self.browser.getLink("Add course list").click()
1119        self.browser.getControl("Create course list now").click()
1120        self.assertTrue('Edit course list' in self.browser.contents)
1121        self.assertFalse('Repair course list' in self.browser.contents)
1122        self.student['studycourse'].current_level = 200
1123        self.browser.open(self.studycourse_path + '/100')
1124        self.assertFalse('Edit course list' in self.browser.contents)
1125        self.assertFalse('Repair course list' in self.browser.contents)
1126        configuration = createObject('waeup.SessionConfiguration')
1127        configuration.academic_session = 2016
1128        self.app['configuration'].addSessionConfiguration(configuration)
1129        self.app['configuration']['2016'].studylevel_repair_enabled = True
1130        self.browser.open(self.studycourse_path + '/100')
1131        self.assertFalse('Edit course list' in self.browser.contents)
1132        self.assertTrue('Repair course list' in self.browser.contents)
1133        self.browser.getLink("Repair").click()
1134        self.assertEqual(self.browser.url, self.studycourse_path + '/100/repair')
1135        self.assertTrue('Repair course list of 100' in self.browser.contents)
1136        return
1137
1138    def test_student_clearance(self):
1139        # Student cant login if their password is not set
1140        IWorkflowInfo(self.student).fireTransition('admit')
1141        self.browser.open(self.login_path)
1142        self.browser.getControl(name="form.login").value = self.student_id
1143        self.browser.getControl(name="form.password").value = 'spwd'
1144        self.browser.getControl("Login").click()
1145        self.assertMatches(
1146            '...You logged in...', self.browser.contents)
1147        # Admitted student can upload a passport picture
1148        self.browser.open(self.student_path + '/change_portrait')
1149        ctrl = self.browser.getControl(name='passportuploadedit')
1150        file_obj = open(SAMPLE_IMAGE, 'rb')
1151        file_ctrl = ctrl.mech_control
1152        file_ctrl.add_file(file_obj, filename='my_photo.jpg')
1153        self.browser.getControl(
1154            name='upload_passportuploadedit').click()
1155        self.assertTrue(
1156            'src="http://localhost/app/students/E1000000/passport.jpg"'
1157            in self.browser.contents)
1158        # Student is redirected to the personal data form because
1159        # personal data form is not properly filled.
1160        self.browser.open(self.student_path + '/start_clearance')
1161        self.assertMatches('...Personal data form is not properly filled...',
1162                           self.browser.contents)
1163        self.assertEqual(self.browser.url, self.student_path + '/edit_personal')
1164        self.student.father_name = u'Rudolf'
1165        self.browser.open(self.student_path + '/start_clearance')
1166        self.assertMatches(
1167            '...<h1 class="kofa-content-label">Start clearance</h1>...',
1168            self.browser.contents)
1169
1170    def test_student_accommodation(self):
1171        del self.student['accommodation']['2004']
1172        self.student['studycourse'].certificate.study_mode = 'dp_ft'
1173        # All beds can be assigned
1174        bed1 = self.app['hostels']['hall-1']['hall-1_A_101_A']
1175        bed1.bed_type = u'regular_male_all'
1176        bed2 = self.app['hostels']['hall-1']['hall-1_A_101_B']
1177        bed2.bed_type = u'regular_female_all'
1178        notify(grok.ObjectModifiedEvent(bed1))
1179        notify(grok.ObjectModifiedEvent(bed2))
1180        # Login
1181        self.browser.open(self.login_path)
1182        self.browser.getControl(name="form.login").value = self.student_id
1183        self.browser.getControl(name="form.password").value = 'spwd'
1184        self.browser.getControl("Login").click()
1185        # Students can book accommodation without AC ...
1186        self.browser.open(self.acco_path)
1187        IWorkflowInfo(self.student).fireTransition('admit')
1188        self.browser.getControl("Book accommodation").click()
1189        self.assertTrue(
1190            'You are not eligible to book accommodation.'
1191            in self.browser.contents)
1192        self.student['studycourse'].certificate.study_mode = 'ug_ft'
1193        self.app['hostels'].accommodation_states = [PAID]
1194        self.browser.getControl("Book accommodation").click()
1195        self.assertTrue(
1196            'You are in the wrong registration state.'
1197            in self.browser.contents)
1198        IWorkflowState(self.student).setState(PAID)
1199        self.browser.getControl("Book accommodation").click()
1200        self.assertFalse('Activation Code:' in self.browser.contents)
1201        self.browser.getControl("Create bed ticket").click()
1202        # Bed is randomly selected but, since there is only
1203        # one bed for this student, we know that
1204        self.assertEqual(self.student['accommodation']['2004'].bed_coordinates,
1205            'Hall 1, Block A, Room 101, Bed A (regular_male_all)')
1206        # Only the hall name is displayed
1207        self.assertEqual(self.student[
1208            'accommodation']['2004'].display_coordinates,
1209            'Hall 1')
1210        self.assertFalse('Hall 1, Block A, Room 101, Bed A'
1211            in self.browser.contents)
1212        self.assertTrue('<td>Hall 1</td>'
1213            in self.browser.contents)
1214        return
1215
1216    def test_handle_courses_by_lecturer(self):
1217        self.app['users'].addUser('mrslecturer', 'mrslecturerSecret1')
1218        self.app['users']['mrslecturer'].email = 'mrslecturer@foo.ng'
1219        self.app['users']['mrslecturer'].title = u'Mercedes Benz'
1220        # Add course ticket
1221        studylevel = createObject(u'waeup.StudentStudyLevel')
1222        studylevel.level = 100
1223        studylevel.level_session = 2004
1224        self.student['studycourse'].addStudentStudyLevel(
1225            self.certificate, studylevel)
1226        # Assign local Lecturer role for a certificate.
1227        course = self.app['faculties']['fac1']['dep1'].courses['COURSE1']
1228        prmlocal = IPrincipalRoleManager(course)
1229        prmlocal.assignRoleToPrincipal('waeup.local.Lecturer', 'mrslecturer')
1230        notify(LocalRoleSetEvent(
1231            course, 'waeup.local.Lecturer', 'mrslecturer', granted=True))
1232        # Login as lecturer.
1233        self.browser.open(self.login_path)
1234        self.browser.getControl(name="form.login").value = 'mrslecturer'
1235        self.browser.getControl(name="form.password").value = 'mrslecturerSecret1'
1236        self.browser.getControl("Login").click()
1237        self.browser.getLink("My Courses").click()
1238        self.browser.getLink("COURSE1").click()
1239        # Course results can be batch edited via the edit_courses view.
1240        self.app['faculties']['fac1']['dep1'].score_editing_disabled = False
1241        self.app['configuration'].current_academic_session = 2004
1242        self.app['configuration']['2004'].score_editing_enabled = ['ug_ft']
1243        IWorkflowState(self.student).setState('courses validated')
1244        self.browser.open(
1245            "http://localhost/app/faculties/fac1/dep1/courses/COURSE1/edit_scores")
1246        self.assertTrue(
1247            'input type="text" name="scores:list"'
1248            in self.browser.contents)
1249        self.browser.getControl(name="scores:list", index=0).value = '55'
1250        self.browser.getControl(name="cas:list", index=0).value = '22'
1251        self.browser.getControl("Update scores from").click()
1252        # New score and ca has been set.
1253        self.assertEqual(
1254            self.student['studycourse']['100']['COURSE1'].score, 55)
1255        self.assertEqual(
1256            self.student['studycourse']['100']['COURSE1'].ca, 22)
1257        # Score editing has been logged.
1258        logfile = os.path.join(
1259            self.app['datacenter'].storage, 'logs', 'students.log')
1260        logcontent = open(logfile).read()
1261        self.assertTrue('mrslecturer - waeup.aaue.students.browser.CustomEditScoresPage - '
1262                        'E1000000 100/COURSE1 score updated (55)' in logcontent)
1263        self.assertTrue('mrslecturer - waeup.aaue.students.browser.CustomEditScoresPage - '
1264                        'E1000000 100/COURSE1 ca updated (22)' in logcontent)
1265        # Non-integer scores won't be accepted.
1266        self.browser.open(
1267            "http://localhost/app/faculties/fac1/dep1/courses/COURSE1/edit_scores")
1268        self.assertTrue('value="55" />' in self.browser.contents)
1269        self.browser.getControl(name="scores:list", index=0).value = 'abc'
1270        self.browser.getControl("Update scores").click()
1271        self.assertTrue('Error: Score(s), CA(s) and Imported TS(s) of TESTER, Anna have not be updated.'
1272            in self.browser.contents)
1273        # Scores can be removed.
1274        self.browser.open(
1275            "http://localhost/app/faculties/fac1/dep1/courses/COURSE1/edit_scores")
1276        self.browser.getControl(name="scores:list", index=0).value = ''
1277        self.browser.getControl("Update scores").click()
1278        self.assertEqual(
1279            self.student['studycourse']['100']['COURSE1'].score, None)
1280        logcontent = open(logfile).read()
1281        self.assertTrue('mrslecturer - waeup.aaue.students.browser.CustomEditScoresPage - '
1282                        'E1000000 100/COURSE1 score updated (None)' in logcontent)
1283
1284
1285    def disabled_test_student_view_transcript(self):
1286        # Student cant login if their password is not set
1287        IWorkflowInfo(self.student).fireTransition('admit')
1288        self.browser.open(self.login_path)
1289        self.browser.getControl(name="form.login").value = self.student_id
1290        self.browser.getControl(name="form.password").value = 'spwd'
1291        self.browser.getControl("Login").click()
1292        self.assertMatches(
1293            '...You logged in...', self.browser.contents)
1294        # Students can view the transcript
1295        self.browser.open(self.studycourse_path)
1296        self.browser.getLink("Transcript").click()
1297        self.browser.getLink("Academic Transcript").click()
1298        self.assertEqual(self.browser.headers['Status'], '200 Ok')
1299        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
1300
1301    def test_alumni_request_pw(self):
1302        # Add an applicants container
1303        applicantscontainer = ApplicantsContainer()
1304        applicantscontainer.code = u'trans2017'
1305        applicantscontainer.prefix = 'trans'
1306        applicantscontainer.year = 2017
1307        applicantscontainer.title = u'This is the trans2017 container'
1308        applicantscontainer.application_category = 'no'
1309        applicantscontainer.mode = 'create'
1310        applicantscontainer.strict_deadline = True
1311        delta = timedelta(days=10)
1312        applicantscontainer.startdate = datetime.now(pytz.utc) - delta
1313        applicantscontainer.enddate = datetime.now(pytz.utc) + delta
1314        self.app['applicants']['trans2017'] = applicantscontainer
1315        self.applicantscontainer = self.app['applicants']['trans2017']
1316        # Student with wrong number can't be found.
1317        # Applicant is redirected to application section.
1318        self.browser.open('http://localhost/app/alumni_requestpw')
1319        self.browser.getControl(name="form.lastname").value = 'Tester'
1320        self.browser.getControl(name="form.number").value = 'anynumber'
1321        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
1322        self.browser.getControl("Send login credentials").click()
1323        self.assertTrue('No student record found.'
1324            in self.browser.contents)
1325        self.assertEqual(self.browser.url,
1326            'http://localhost/app/applicants/trans2017/register')
1327
1328    def test_student_course_registration_outstanding(self):
1329        self.course = createObject('waeup.Course')
1330        self.course.code = 'COURSE2'
1331        self.course.semester = 1
1332        self.course.credits = 39
1333        self.course.passmark = 40
1334        self.app['faculties']['fac1']['dep1'].courses.addCourse(
1335            self.course)
1336        IWorkflowState(self.student).setState('school fee paid')
1337        self.browser.open(self.login_path)
1338        self.browser.getControl(name="form.login").value = self.student_id
1339        self.browser.getControl(name="form.password").value = 'spwd'
1340        self.browser.getControl("Login").click()
1341        self.browser.open(self.student_path + '/studycourse/add')
1342        self.browser.getControl("Create course list now").click()
1343        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 1)
1344        self.student['studycourse'].current_level = 200
1345        self.browser.getLink("Study Course").click()
1346        self.browser.getLink("Add course list").click()
1347        self.assertMatches('...Add current level 200 (Year 2)...',
1348                           self.browser.contents)
1349        self.browser.getControl("Create course list now").click()
1350        self.browser.getLink("200").click()
1351        self.browser.getLink("Edit course list").click()
1352        self.browser.getLink("here").click()
1353        self.browser.getControl(name="form.course").value = ['COURSE2']
1354        self.browser.getControl("Add course ticket").click()
1355        # Carryover COURSE1 in level 200 already has 10 credits
1356        self.assertMatches(
1357            '...Maximum credits exceeded...', self.browser.contents)
1358        # If COURSE1 is outstanding, its credits won't be considered
1359        self.student['studycourse']['200']['COURSE1'].outstanding = True
1360        self.browser.getControl("Add course ticket").click()
1361        # Corresponding certificate course is missing
1362        self.assertTrue(
1363            'COURSE2 is not part of the CERT1 curriculum.'
1364            in self.browser.contents)
1365        self.app['faculties']['fac1']['dep1'].certificates[
1366            'CERT1'].addCertCourse(self.course, level=100)
1367        self.browser.getControl("Add course ticket").click()
1368        self.assertTrue(
1369            'Successfully added COURSE2' in self.browser.contents)
1370        return
1371
1372    def test_examination_schedule_slip(self):
1373        self.student.flash_notice = u'My Examination Date'
1374        self.browser.open(self.login_path)
1375        self.browser.getControl(name="form.login").value = self.student_id
1376        self.browser.getControl(name="form.password").value = 'spwd'
1377        self.browser.getControl("Login").click()
1378        self.browser.getLink("Download examination schedule slip").click()
1379        self.assertEqual(self.browser.headers['Status'], '200 Ok')
1380        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
1381        path = os.path.join(samples_dir(), 'examination_schedule_slip.pdf')
1382        open(path, 'wb').write(self.browser.contents)
1383        print "Sample PDF examination_schedule_slip.pdf written to %s" % path
1384        # If flash_notive does not contain exam' the button does not show up.
1385        self.student.flash_notice = u'anything'
1386        self.browser.open(self.student_path)
1387        self.assertFalse('examination schedule slip' in self.browser.contents)
Note: See TracBrowser for help on using the repository browser.