source: main/waeup.fceokene/trunk/src/waeup/fceokene/students/tests/test_browser.py @ 16250

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

Only NCE 3 students pay third semester fee.

  • Property svn:keywords set to Id
File size: 23.7 KB
Line 
1## $Id: test_browser.py 16011 2020-02-23 20:15:50Z 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
21from StringIO import StringIO
22from hurry.workflow.interfaces import IWorkflowState, IWorkflowInfo
23from zope.component.hooks import setSite, clearSite
24from zope.component import getUtility, createObject
25from zope.interface import verify
26from waeup.kofa.app import University
27from waeup.kofa.students.tests.test_browser import (
28    StudentsFullSetup, SAMPLE_IMAGE)
29from waeup.kofa.students.accommodation import BedTicket
30from waeup.kofa.testing import FunctionalTestCase
31from waeup.kofa.browser.tests.test_pdf import samples_dir
32from waeup.kofa.interfaces import (
33    IExtFileStore, IFileStoreNameChooser)
34from waeup.kofa.students.interfaces import IStudentsUtils
35from waeup.fceokene.testing import FunctionalLayer
36
37
38class StudentProcessorTest(FunctionalTestCase):
39    """Perform some batching tests.
40    """
41
42    layer = FunctionalLayer
43
44    def setUp(self):
45        super(StudentProcessorTest, self).setUp()
46        # Setup a sample site for each test
47        app = University()
48        self.dc_root = tempfile.mkdtemp()
49        app['datacenter'].setStoragePath(self.dc_root)
50
51        # Prepopulate the ZODB...
52        self.getRootFolder()['app'] = app
53        # we add the site immediately after creation to the
54        # ZODB. Catalogs and other local utilities are not setup
55        # before that step.
56        self.app = self.getRootFolder()['app']
57        # Set site here. Some of the following setup code might need
58        # to access grok.getSite() and should get our new app then
59        setSite(app)
60
61
62    def tearDown(self):
63        super(StudentProcessorTest, self).tearDown()
64        shutil.rmtree(self.workdir)
65        shutil.rmtree(self.dc_root)
66        clearSite()
67        return
68
69class StudentUITests(StudentsFullSetup):
70    """Tests for customized student class views and pages
71    """
72
73    layer = FunctionalLayer
74
75    def setUp(self):
76        super(StudentUITests, self).setUp()
77
78        bedticket = BedTicket()
79        bedticket.booking_session = 2004
80        bedticket.bed_type = u'any bed type'
81        bedticket.bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
82        bedticket.bed_coordinates = u'My bed coordinates'
83        self.student['accommodation'].addBedTicket(bedticket)
84
85    def test_manage_payments(self):
86        # Add missing configuration data
87        self.app['configuration']['2004'].clearance_fee = 120.0
88        self.app['configuration']['2004'].booking_fee = 150.0
89        self.app['configuration']['2004'].maint_fee = 180.0
90
91        # Managers can add online payment tickets
92        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
93        self.browser.open(self.payments_path)
94        self.browser.getLink("Add current session payment ticket").click()
95        self.browser.getControl(name="form.p_category").value = ['schoolfee']
96        self.browser.getControl("Create ticket").click()
97        self.assertMatches('...Wrong state...',
98                           self.browser.contents)
99        IWorkflowState(self.student).setState('cleared')
100        self.browser.open(self.payments_path + '/addop')
101        self.browser.getControl(name="form.p_category").value = ['schoolfee']
102        self.browser.getControl("Create ticket").click()
103        self.assertMatches('...ticket created...',
104                           self.browser.contents)
105        ctrl = self.browser.getControl(name='val_id')
106        value = ctrl.options[0]
107        self.browser.getLink(value).click()
108        self.assertMatches('...Amount Authorized...',
109                           self.browser.contents)
110        # Managers can open payment slip because we did not proceed to
111        # any payment gateway
112        self.assertFalse('Download payment slip' in self.browser.contents)
113        # Set ticket paid
114        ticket = self.student['payments'].items()[0][1]
115        ticket.p_state = 'paid'
116        self.browser.open(self.payments_path + '/addop')
117        self.browser.getControl(name="form.p_category").value = ['schoolfee']
118        self.browser.getControl("Create ticket").click()
119        self.assertMatches('...This type of payment has already been made...',
120                           self.browser.contents)
121        # Remove all payments so that we can add a school fee payment again
122        keys = [i for i in self.student['payments'].keys()]
123        for payment in keys:
124            del self.student['payments'][payment]
125        self.browser.open(self.payments_path + '/addop')
126        self.browser.getControl(name="form.p_category").value = ['schoolfee']
127        self.browser.getControl("Create ticket").click()
128        self.assertMatches('...ticket created...',
129                           self.browser.contents)
130        self.certificate.study_mode = 'nce_sw'
131        self.browser.open(self.payments_path + '/addop')
132        self.browser.getControl(name="form.p_category").value = ['third_semester']
133        self.browser.getControl("Create ticket").click()
134        self.assertMatches('...could not be determined...',
135                           self.browser.contents)
136        self.certificate.study_mode = 'nce_ft'
137        self.browser.open(self.payments_path + '/addop')
138        self.browser.getControl(name="form.p_category").value = ['third_semester']
139        self.browser.getControl("Create ticket").click()
140        self.assertMatches('...Make NCE 3 school fee payment first...', self.browser.contents)
141        self.browser.open(self.payments_path + '/addop')
142        self.browser.getControl(
143            name="form.p_category").value = ['bed_allocation']
144        self.browser.getControl("Create ticket").click()
145        self.assertMatches('...ticket created...',
146                           self.browser.contents)
147        self.browser.open(self.payments_path + '/addop')
148        self.browser.getControl(
149            name="form.p_category").value = ['hostel_maintenance']
150        self.browser.getControl("Create ticket").click()
151        self.assertMatches('...ticket created...',
152                           self.browser.contents)
153        self.browser.open(self.payments_path + '/addop')
154        self.browser.getControl(name="form.p_category").value = ['clearance']
155        self.browser.getControl("Create ticket").click()
156        self.assertMatches('...ticket created...',
157                           self.browser.contents)
158        self.certificate.study_mode = 'pd_ft'
159        self.browser.open(self.payments_path + '/addop')
160        self.browser.getControl(name="form.p_category").value = ['schoolfee']
161        self.browser.getControl("Create ticket").click()
162        self.assertMatches('...ticket created...',
163                           self.browser.contents)
164        # In state returning we can add a new school fee ticket since
165        # p_session and p_level is different
166        IWorkflowState(self.student).setState('returning')
167        self.browser.open(self.payments_path + '/addop')
168        self.browser.getControl(name="form.p_category").value = ['schoolfee']
169        self.browser.getControl("Create ticket").click()
170        # Uups, we forgot to add a session configuration for next session
171        self.assertTrue('Session configuration object is not available.'
172            in self.browser.contents)
173        configuration = createObject('waeup.SessionConfiguration')
174        configuration.academic_session = 2005
175        self.app['configuration'].addSessionConfiguration(configuration)
176        self.browser.getControl(name="form.p_category").value = ['schoolfee']
177        self.browser.getControl("Create ticket").click()
178        self.assertMatches('...ticket created...',
179                           self.browser.contents)
180
181        # In state admitted school fee can't be determined
182        IWorkflowState(self.student).setState('admitted')
183        self.browser.open(self.payments_path + '/addop')
184        self.browser.getControl(name="form.p_category").value = ['schoolfee']
185        self.browser.getControl("Create ticket").click()
186        self.assertMatches('...Wrong state...',
187                           self.browser.contents)
188
189    def test_student_payments(self):
190        # Login
191        IWorkflowState(self.student).setState('returning')
192        self.browser.open(self.login_path)
193        self.browser.getControl(name="form.login").value = self.student_id
194        self.browser.getControl(name="form.password").value = 'spwd'
195        self.browser.getControl("Login").click()
196        self.browser.open(self.student_path + '/payments')
197        self.assertTrue(
198          'Add current session payment ticket' in self.browser.contents)
199        self.assertFalse(
200          'Add previous session payment ticket' in self.browser.contents)
201        return
202
203    def test_get_returning_data(self):
204        # Student is in level 100, session 2004 with verdict A
205        utils = getUtility(IStudentsUtils)
206        self.assertEqual(utils.getReturningData(self.student),(2005, 200))
207        self.student['studycourse'].current_verdict = 'C'
208        self.assertEqual(utils.getReturningData(self.student),(2005, 110))
209        self.student['studycourse'].current_verdict = 'D'
210        self.assertEqual(utils.getReturningData(self.student),(2005, 100))
211        self.student['studycourse'].current_verdict = 'O'
212        self.assertEqual(utils.getReturningData(self.student),(2004, 110))
213        return
214
215    def test_set_payment_details(self):
216        self.app['configuration']['2004'].booking_fee = 150.0
217        self.app['configuration']['2004'].maint_fee = 180.0
218        self.app['configuration']['2004'].clearance_fee = 120.0
219        utils = getUtility(IStudentsUtils)
220
221        error, payment = utils.setPaymentDetails('schoolfee',self.student)
222        self.assertEqual(payment, None)
223        self.assertEqual(error, u'Wrong state.')
224
225        IWorkflowState(self.student).setState('cleared')
226        self.certificate.study_mode = 'pd_ft'
227        error, payment = utils.setPaymentDetails('schoolfee',self.student)
228        self.assertEqual(payment.p_level, 100)
229        self.assertEqual(payment.p_session, 2004)
230        self.assertEqual(payment.amount_auth, 70000)
231        self.assertEqual(payment.p_item, u'CERT1')
232        self.assertEqual(error, None)
233
234        IWorkflowState(self.student).setState('returning')
235        error, payment = utils.setPaymentDetails('schoolfee',self.student)
236        self.assertEqual('Session configuration object is not available.', error)
237        configuration = createObject('waeup.SessionConfiguration')
238        configuration.academic_session = 2005
239        self.app['configuration'].addSessionConfiguration(configuration)
240        error, payment = utils.setPaymentDetails('schoolfee',self.student)
241        self.assertEqual(payment.p_level, 200)
242        self.assertEqual(payment.p_session, 2005)
243        self.assertEqual(payment.amount_auth, 35300)
244        self.assertEqual(payment.p_item, u'CERT1')
245        self.assertEqual(error, None)
246
247        # UG returning students pay 56150
248        self.certificate.study_mode = 'ug_ft'
249        error, payment = utils.setPaymentDetails('schoolfee',self.student)
250        self.assertEqual(payment.amount_auth,  56150)
251        self.assertEqual(error, None)
252        # UG cleared students pay 65650
253        IWorkflowState(self.student).setState('cleared')
254        error, payment = utils.setPaymentDetails('schoolfee',self.student)
255        self.assertEqual(payment.amount_auth, 65650)
256        self.assertEqual(error, None)
257
258        # NCE student payment can be disabled by
259        # setting the base school fee to -1
260        IWorkflowState(self.student).setState('returning')
261        configuration = createObject('waeup.SessionConfiguration')
262        self.app['configuration']['2004'].school_fee_base = -1.0
263        self.certificate.study_mode = 'nce_ft'
264        error, payment = utils.setPaymentDetails('schoolfee',self.student)
265        self.assertEqual(error, u'School fee payment is disabled.')
266
267        error, payment = utils.setPaymentDetails('clearance',self.student)
268        self.assertEqual(error, u'Acceptance Fee payments not allowed.')
269        IWorkflowState(self.student).setState('cleared')
270        error, payment = utils.setPaymentDetails('clearance',self.student)
271        self.assertEqual(payment.p_level, 100)
272        self.assertEqual(payment.p_session, 2004)
273        self.assertEqual(payment.amount_auth, 120)
274        self.assertEqual(payment.p_item, u'CERT1')
275        self.assertEqual(error, None)
276
277        self.student['studycourse'].current_session = 2005
278        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
279        self.assertEqual(payment, None)
280        self.assertEqual(error, 'No bed space allocated.')
281        self.student['studycourse'].current_session = 2004
282
283        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
284        self.assertEqual(payment.p_level, 100)
285        self.assertEqual(payment.p_session, 2004)
286        self.assertEqual(payment.amount_auth, 876)
287        self.assertEqual(payment.p_item, u'My bed coordinates')
288        self.assertEqual(error, None)
289
290        error, payment = utils.setPaymentDetails('third_semester',self.student)
291        self.assertEqual(error, u'Amount could not be determined.')
292        self.student['studycourse'].current_level = 300
293        error, payment = utils.setPaymentDetails('third_semester',self.student)
294        self.assertEqual(error, u'Make NCE 3 school fee payment first.')
295        payment = createObject('waeup.StudentOnlinePayment')
296        payment.p_category = u'schoolfee'
297        payment.p_session = self.student.current_session
298        payment.p_item = u'My Certificate'
299        payment.p_id = u'anyid'
300        self.student['payments']['anykey'] = payment
301        payment.p_state = 'paid'
302        payment.p_level = 300
303        error, payment = utils.setPaymentDetails('third_semester',self.student)
304        self.assertEqual(payment.p_level, 300)
305        self.assertEqual(payment.p_session, 2004)
306        self.assertEqual(payment.amount_auth, 7938)
307        self.assertEqual(payment.p_item, u'')
308        self.assertEqual(error, None)
309
310        self.certificate.study_mode = u'nce_sw'
311        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
312        self.assertEqual(payment.p_level, 300)
313        self.assertEqual(payment.p_session, 2004)
314        self.assertEqual(payment.amount_auth, 547.5)  # 62.5% * 876
315        self.assertEqual(payment.p_item, u'My bed coordinates')
316        self.assertEqual(error, None)
317
318        error, payment = utils.setPaymentDetails('bed_allocation',self.student)
319        self.assertEqual(payment.p_level, 300)
320        self.assertEqual(payment.p_session, 2004)
321        self.assertEqual(payment.amount_auth, 150)
322        self.assertEqual(payment.p_item, u'')
323        self.assertEqual(error, None)
324
325        error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100)
326        self.assertEqual(error, u'Previous session payment not yet implemented.')
327        return
328
329    def test_student_start_clearance(self):
330        self.browser.open(self.login_path)
331        self.browser.getControl(name="form.login").value = self.student_id
332        self.browser.getControl(name="form.password").value = 'spwd'
333        self.browser.getControl("Login").click()
334
335        IWorkflowInfo(self.student).fireTransition('admit')
336        self.browser.open(self.student_path + '/change_portrait')
337        image = open(SAMPLE_IMAGE, 'rb')
338        ctrl = self.browser.getControl(name='passportuploadedit')
339        file_ctrl = ctrl.mech_control
340        file_ctrl.add_file(image, filename='my_photo.jpg')
341        self.browser.getControl(
342            name='upload_passportuploadedit').click()
343        self.browser.open(self.student_path + '/start_clearance')
344        # In Okene the ug students start clearance with activation code ...
345        self.assertTrue('Activation Code:' in self.browser.contents)
346        self.browser.getControl("Start clearance now").click()
347        self.assertTrue('Activation code is invalid' in self.browser.contents)
348        # ... and nce students without.
349        self.certificate.study_mode = 'nce_ft'
350        self.browser.open(self.student_path + '/start_clearance')
351        self.assertFalse('Activation Code:' in self.browser.contents)
352        self.browser.getControl("Start clearance now").click()
353        self.assertTrue(
354            'Clearance process has been started' in self.browser.contents)
355
356    def test_open_slips(self):
357        # Managers can open clearance slip
358        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
359        self.browser.open(self.student_path + '/view_clearance')
360        self.browser.getLink("Download clearance slip").click()
361        self.assertEqual(self.browser.headers['Status'], '200 Ok')
362        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
363
364    def test_student_accommodation(self):
365        del self.student['accommodation']['2004']
366        self.certificate.study_mode = 'ug_pt'
367        # Login
368        self.browser.open(self.login_path)
369        self.browser.getControl(name="form.login").value = self.student_id
370        self.browser.getControl(name="form.password").value = 'spwd'
371        self.browser.getControl("Login").click()
372
373        # Students can book accommodation without AC ...
374        self.browser.open(self.acco_path)
375        IWorkflowInfo(self.student).fireTransition('admit')
376        self.browser.getControl("Book accommodation").click()
377        self.assertFalse('Activation Code:' in self.browser.contents)
378        self.browser.getControl("Create bed ticket").click()
379        # Bed is randomly selected but, since there is only
380        # one bed for this student, we know that
381        self.assertEqual(self.student['accommodation']['2004'].bed_coordinates,
382            'Hall 1, Block A, Room 101, Bed A (regular_male_fr)')
383        self.assertEqual(self.student['accommodation']['2004'].display_coordinates,
384            '(see payment slip)')
385        # But the bed coordinates are hidden.
386        self.assertFalse('Hall 1, Block A, Room 101, Bed A'
387            in self.browser.contents)
388        self.assertTrue('<td>(see payment slip)</td>'
389            in self.browser.contents)
390        return
391
392    def test_admission_slip(self):
393        # Login
394        IWorkflowState(self.student).setState('admitted')
395        self.browser.open(self.login_path)
396        self.browser.getControl(name="form.login").value = self.student_id
397        self.browser.getControl(name="form.password").value = 'spwd'
398        self.browser.getControl("Login").click()
399        self.assertFalse(
400          'Download admission letter' in self.browser.contents)
401        IWorkflowState(self.student).setState('clearance started')
402        self.browser.open(self.student_path)
403        self.assertTrue(
404          'Download admission letter' in self.browser.contents)
405        # Students can open admission letter
406        self.browser.getLink("Download admission letter").click()
407        self.assertEqual(self.browser.headers['Status'], '200 Ok')
408        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
409        path = os.path.join(samples_dir(), 'admission_slip_combined.pdf')
410        open(path, 'wb').write(self.browser.contents)
411        print "Sample PDF admission_slip_combined.pdf written to %s" % path
412        self.certificate.study_mode = 'pd_ft'
413        self.browser.open(self.student_path)
414        self.browser.getLink("Download admission letter").click()
415        path = os.path.join(samples_dir(), 'admission_slip.pdf')
416        open(path, 'wb').write(self.browser.contents)
417        print "Sample PDF admission_slip.pdf written to %s" % path
418        return
419
420    def test_payment_disabled(self):
421        self.certificate.study_mode = 'nce_ft'
422        IWorkflowState(self.student).setState('cleared')
423        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
424        self.browser.open(self.payments_path)
425        self.browser.getLink("Add current session payment ticket").click()
426        self.browser.getControl(name="form.p_category").value = ['schoolfee']
427        self.browser.getControl("Create ticket").click()
428        self.assertMatches('...ticket created...',
429                           self.browser.contents)
430        self.app['configuration']['2004'].payment_disabled = ['sf_nce1']
431        self.browser.getLink("Add current session payment ticket").click()
432        self.browser.getControl(name="form.p_category").value = ['schoolfee']
433        self.browser.getControl("Create ticket").click()
434        self.assertMatches('...This category of payments has been disabled...',
435                           self.browser.contents)
436        self.certificate.study_mode = 'ug_ft'
437        self.browser.open(self.payments_path)
438        self.browser.getLink("Add current session payment ticket").click()
439        self.browser.getControl(name="form.p_category").value = ['schoolfee']
440        self.browser.getControl("Create ticket").click()
441        self.assertMatches('...ticket created...',
442                           self.browser.contents)
443        return
444
445    def test_student_course_registration(self):
446        IWorkflowState(self.student).setState('school fee paid')
447        self.browser.open(self.login_path)
448        self.browser.getControl(name="form.login").value = self.student_id
449        self.browser.getControl(name="form.password").value = 'spwd'
450        self.browser.getControl("Login").click()
451        # Now students can add the current study level
452        self.browser.getLink("Study Course").click()
453        self.browser.getLink("Add course list").click()
454        self.assertMatches('...Add current level 100 (Year 1)...',
455                           self.browser.contents)
456        self.browser.getControl("Create course list now").click()
457        # Students can open the customized pdf course registration slip
458        self.browser.open(
459            self.student_path + '/studycourse/100/course_registration_slip.pdf')
460        self.assertEqual(self.browser.headers['Status'], '200 Ok')
461        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
462        path = os.path.join(samples_dir(), 'course_registration_slip.pdf')
463        open(path, 'wb').write(self.browser.contents)
464        print "Sample PDF course_registration_slip.pdf written to %s" % path
465
466        # Students can open the examination clearance slip if they are
467        # in state courses validated
468        IWorkflowState(self.student).setState('courses validated')
469        self.browser.open(self.student_path + '/studycourse/100')
470        self.browser.getLink("Download 1st semester examination clearance slip").click()
471        self.assertEqual(self.browser.headers['Status'], '200 Ok')
472        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
473        path = os.path.join(samples_dir(), 'examination_clearance_slip_1.pdf')
474        open(path, 'wb').write(self.browser.contents)
475        print "Sample PDF examination_clearance_slip_1.pdf written to %s" % path
476        self.browser.open(self.student_path + '/studycourse/100')
477        self.browser.getLink("Download 2nd semester examination clearance slip").click()
478        self.assertEqual(self.browser.headers['Status'], '200 Ok')
479        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
480        path = os.path.join(samples_dir(), 'examination_clearance_slip_2.pdf')
481        open(path, 'wb').write(self.browser.contents)
482        print "Sample PDF examination_clearance_slip_2.pdf written to %s" % path
Note: See TracBrowser for help on using the repository browser.