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

Last change on this file since 14933 was 14931, checked in by Henrik Bettermann, 7 years ago

Change fees.

  • Property svn:keywords set to Id
File size: 21.1 KB
Line 
1## $Id: test_browser.py 14931 2017-12-21 23:02:33Z 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
111        self.browser.getLink("Download payment slip").click()
112        self.assertEqual(self.browser.headers['Status'], '200 Ok')
113        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
114        # Set ticket paid
115        ticket = self.student['payments'].items()[0][1]
116        ticket.p_state = 'paid'
117        self.browser.open(self.payments_path + '/addop')
118        self.browser.getControl(name="form.p_category").value = ['schoolfee']
119        self.browser.getControl("Create ticket").click()
120        self.assertMatches('...This type of payment has already been made...',
121                           self.browser.contents)
122        # Remove all payments so that we can add a school fee payment again
123        keys = [i for i in self.student['payments'].keys()]
124        for payment in keys:
125            del self.student['payments'][payment]
126        self.browser.open(self.payments_path + '/addop')
127        self.browser.getControl(name="form.p_category").value = ['schoolfee']
128        self.browser.getControl("Create ticket").click()
129        self.assertMatches('...ticket created...',
130                           self.browser.contents)
131        self.certificate.study_mode = 'nce_sw'
132        self.browser.open(self.payments_path + '/addop')
133        self.browser.getControl(name="form.p_category").value = ['third_semester']
134        self.browser.getControl("Create ticket").click()
135        self.assertMatches('...could not be determined...',
136                           self.browser.contents)
137        self.certificate.study_mode = 'nce_ft'
138        self.browser.open(self.payments_path + '/addop')
139        self.browser.getControl(name="form.p_category").value = ['third_semester']
140        self.browser.getControl("Create ticket").click()
141        self.assertMatches('...ticket created...', self.browser.contents)
142        self.browser.open(self.payments_path + '/addop')
143        self.browser.getControl(
144            name="form.p_category").value = ['bed_allocation']
145        self.browser.getControl("Create ticket").click()
146        self.assertMatches('...ticket created...',
147                           self.browser.contents)
148        self.browser.open(self.payments_path + '/addop')
149        self.browser.getControl(
150            name="form.p_category").value = ['hostel_maintenance']
151        self.browser.getControl("Create ticket").click()
152        self.assertMatches('...ticket created...',
153                           self.browser.contents)
154        self.browser.open(self.payments_path + '/addop')
155        self.browser.getControl(name="form.p_category").value = ['clearance']
156        self.browser.getControl("Create ticket").click()
157        self.assertMatches('...ticket created...',
158                           self.browser.contents)
159        self.certificate.study_mode = 'pd_ft'
160        self.browser.open(self.payments_path + '/addop')
161        self.browser.getControl(name="form.p_category").value = ['schoolfee']
162        self.browser.getControl("Create ticket").click()
163        self.assertMatches('...ticket created...',
164                           self.browser.contents)
165        # In state returning we can add a new school fee ticket since
166        # p_session and p_level is different
167        IWorkflowState(self.student).setState('returning')
168        self.browser.open(self.payments_path + '/addop')
169        self.browser.getControl(name="form.p_category").value = ['schoolfee']
170        self.browser.getControl("Create ticket").click()
171        # Uups, we forgot to add a session configuration for next session
172        self.assertTrue('Session configuration object is not available.'
173            in self.browser.contents)
174        configuration = createObject('waeup.SessionConfiguration')
175        configuration.academic_session = 2005
176        self.app['configuration'].addSessionConfiguration(configuration)
177        self.browser.getControl(name="form.p_category").value = ['schoolfee']
178        self.browser.getControl("Create ticket").click()
179        self.assertMatches('...ticket created...',
180                           self.browser.contents)
181
182        # In state admitted school fee can't be determined
183        IWorkflowState(self.student).setState('admitted')
184        self.browser.open(self.payments_path + '/addop')
185        self.browser.getControl(name="form.p_category").value = ['schoolfee']
186        self.browser.getControl("Create ticket").click()
187        self.assertMatches('...Wrong state...',
188                           self.browser.contents)
189
190    def test_student_payments(self):
191        # Login
192        IWorkflowState(self.student).setState('returning')
193        self.browser.open(self.login_path)
194        self.browser.getControl(name="form.login").value = self.student_id
195        self.browser.getControl(name="form.password").value = 'spwd'
196        self.browser.getControl("Login").click()
197        self.browser.open(self.student_path + '/payments')
198        self.assertTrue(
199          'Add current session payment ticket' in self.browser.contents)
200        self.assertFalse(
201          'Add previous session payment ticket' in self.browser.contents)
202        return
203
204    def test_get_returning_data(self):
205        # Student is in level 100, session 2004 with verdict A
206        utils = getUtility(IStudentsUtils)
207        self.assertEqual(utils.getReturningData(self.student),(2005, 200))
208        self.student['studycourse'].current_verdict = 'C'
209        self.assertEqual(utils.getReturningData(self.student),(2005, 110))
210        self.student['studycourse'].current_verdict = 'D'
211        self.assertEqual(utils.getReturningData(self.student),(2005, 100))
212        self.student['studycourse'].current_verdict = 'O'
213        self.assertEqual(utils.getReturningData(self.student),(2004, 110))
214        return
215
216    def test_set_payment_details(self):
217        self.app['configuration']['2004'].booking_fee = 150.0
218        self.app['configuration']['2004'].maint_fee = 180.0
219        self.app['configuration']['2004'].clearance_fee = 120.0
220        utils = getUtility(IStudentsUtils)
221
222        error, payment = utils.setPaymentDetails('schoolfee',self.student)
223        self.assertEqual(payment, None)
224        self.assertEqual(error, u'Wrong state.')
225
226        IWorkflowState(self.student).setState('cleared')
227        self.certificate.study_mode = 'pd_ft'
228        error, payment = utils.setPaymentDetails('schoolfee',self.student)
229        self.assertEqual(payment.p_level, 100)
230        self.assertEqual(payment.p_session, 2004)
231        self.assertEqual(payment.amount_auth, 70450.0)
232        self.assertEqual(payment.p_item, u'CERT1')
233        self.assertEqual(error, None)
234
235        IWorkflowState(self.student).setState('returning')
236        error, payment = utils.setPaymentDetails('schoolfee',self.student)
237        self.assertEqual('Session configuration object is not available.', error)
238        configuration = createObject('waeup.SessionConfiguration')
239        configuration.academic_session = 2005
240        self.app['configuration'].addSessionConfiguration(configuration)
241        error, payment = utils.setPaymentDetails('schoolfee',self.student)
242        self.assertEqual(payment.p_level, 200)
243        self.assertEqual(payment.p_session, 2005)
244        self.assertEqual(payment.amount_auth, 35450.0)
245        self.assertEqual(payment.p_item, u'CERT1')
246        self.assertEqual(error, None)
247
248        # UG returning students pay 56150
249        self.certificate.study_mode = 'ug_ft'
250        error, payment = utils.setPaymentDetails('schoolfee',self.student)
251        self.assertEqual(payment.amount_auth,  56300.0)
252        self.assertEqual(error, None)
253        # UG cleared students pay 65650
254        IWorkflowState(self.student).setState('cleared')
255        error, payment = utils.setPaymentDetails('schoolfee',self.student)
256        self.assertEqual(payment.amount_auth, 65800.0)
257        self.assertEqual(error, None)
258
259        # NCE student payment can be disabled by
260        # setting the base school fee to -1
261        IWorkflowState(self.student).setState('returning')
262        configuration = createObject('waeup.SessionConfiguration')
263        self.app['configuration']['2004'].school_fee_base = -1.0
264        self.certificate.study_mode = 'nce_ft'
265        error, payment = utils.setPaymentDetails('schoolfee',self.student)
266        self.assertEqual(error, u'School fee payment is disabled.')
267
268        error, payment = utils.setPaymentDetails('clearance',self.student)
269        self.assertEqual(error, u'Acceptance Fee payments not allowed.')
270        IWorkflowState(self.student).setState('cleared')
271        error, payment = utils.setPaymentDetails('clearance',self.student)
272        self.assertEqual(payment.p_level, 100)
273        self.assertEqual(payment.p_session, 2004)
274        self.assertEqual(payment.amount_auth, 270.0)
275        self.assertEqual(payment.p_item, u'CERT1')
276        self.assertEqual(error, None)
277
278        self.student['studycourse'].current_session = 2005
279        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
280        self.assertEqual(payment, None)
281        self.assertEqual(error, 'No bed space allocated.')
282        self.student['studycourse'].current_session = 2004
283
284        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
285        self.assertEqual(payment.p_level, 100)
286        self.assertEqual(payment.p_session, 2004)
287        self.assertEqual(payment.amount_auth, 1026.0)
288        self.assertEqual(payment.p_item, u'My bed coordinates')
289        self.assertEqual(error, None)
290
291        error, payment = utils.setPaymentDetails('third_semester',self.student)
292        self.assertEqual(payment.p_level, 100)
293        self.assertEqual(payment.p_session, 2004)
294        self.assertEqual(payment.amount_auth, 8088.0)
295        self.assertEqual(payment.p_item, u'')
296        self.assertEqual(error, None)
297
298        self.certificate.study_mode = u'nce_sw'
299        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
300        self.assertEqual(payment.p_level, 100)
301        self.assertEqual(payment.p_session, 2004)
302        self.assertEqual(payment.amount_auth, 697.5)  # 62.5% * 876 + 150
303        self.assertEqual(payment.p_item, u'My bed coordinates')
304        self.assertEqual(error, None)
305
306        error, payment = utils.setPaymentDetails('bed_allocation',self.student)
307        self.assertEqual(payment.p_level, 100)
308        self.assertEqual(payment.p_session, 2004)
309        self.assertEqual(payment.amount_auth, 300.0)
310        self.assertEqual(payment.p_item, u'')
311        self.assertEqual(error, None)
312
313        error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100)
314        self.assertEqual(error, u'Previous session payment not yet implemented.')
315        return
316
317    def test_student_start_clearance(self):
318        self.browser.open(self.login_path)
319        self.browser.getControl(name="form.login").value = self.student_id
320        self.browser.getControl(name="form.password").value = 'spwd'
321        self.browser.getControl("Login").click()
322
323        IWorkflowInfo(self.student).fireTransition('admit')
324        self.browser.open(self.student_path + '/change_portrait')
325        image = open(SAMPLE_IMAGE, 'rb')
326        ctrl = self.browser.getControl(name='passportuploadedit')
327        file_ctrl = ctrl.mech_control
328        file_ctrl.add_file(image, filename='my_photo.jpg')
329        self.browser.getControl(
330            name='upload_passportuploadedit').click()
331        self.browser.open(self.student_path + '/start_clearance')
332        # In Okene the ug students start clearance with activation code ...
333        self.assertTrue('Activation Code:' in self.browser.contents)
334        self.browser.getControl("Start clearance now").click()
335        self.assertTrue('Activation code is invalid' in self.browser.contents)
336        # ... and nce students without.
337        self.certificate.study_mode = 'nce_ft'
338        self.browser.open(self.student_path + '/start_clearance')
339        self.assertFalse('Activation Code:' in self.browser.contents)
340        self.browser.getControl("Start clearance now").click()
341        self.assertTrue(
342            'Clearance process has been started' in self.browser.contents)
343
344    def test_open_slips(self):
345        # Managers can open clearance slip
346        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
347        self.browser.open(self.student_path + '/view_clearance')
348        self.browser.getLink("Download clearance slip").click()
349        self.assertEqual(self.browser.headers['Status'], '200 Ok')
350        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
351
352    def test_student_accommodation(self):
353        del self.student['accommodation']['2004']
354        self.certificate.study_mode = 'ug_pt'
355        # Login
356        self.browser.open(self.login_path)
357        self.browser.getControl(name="form.login").value = self.student_id
358        self.browser.getControl(name="form.password").value = 'spwd'
359        self.browser.getControl("Login").click()
360
361        # Students can book accommodation without AC ...
362        self.browser.open(self.acco_path)
363        IWorkflowInfo(self.student).fireTransition('admit')
364        self.browser.getControl("Book accommodation").click()
365        self.assertFalse('Activation Code:' in self.browser.contents)
366        self.browser.getControl("Create bed ticket").click()
367        # Bed is randomly selected but, since there is only
368        # one bed for this student, we know that
369        self.assertEqual(self.student['accommodation']['2004'].bed_coordinates,
370            'Hall 1, Block A, Room 101, Bed A (regular_male_fr)')
371        self.assertEqual(self.student['accommodation']['2004'].display_coordinates,
372            '(see payment slip)')
373        # But the bed coordinates are hidden.
374        self.assertFalse('Hall 1, Block A, Room 101, Bed A'
375            in self.browser.contents)
376        self.assertTrue('<td>(see payment slip)</td>'
377            in self.browser.contents)
378        return
379
380    def test_admission_slip_link(self):
381        # Login
382        IWorkflowState(self.student).setState('admitted')
383        self.browser.open(self.login_path)
384        self.browser.getControl(name="form.login").value = self.student_id
385        self.browser.getControl(name="form.password").value = 'spwd'
386        self.browser.getControl("Login").click()
387        self.assertFalse(
388          'Download admission letter' in self.browser.contents)
389        IWorkflowState(self.student).setState('clearance started')
390        self.browser.open(self.student_path)
391        self.assertTrue(
392          'Download admission letter' in self.browser.contents)
393        return
394
395    def test_payment_disabled(self):
396        self.certificate.study_mode = 'nce_ft'
397        IWorkflowState(self.student).setState('cleared')
398        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
399        self.browser.open(self.payments_path)
400        self.browser.getLink("Add current session payment ticket").click()
401        self.browser.getControl(name="form.p_category").value = ['schoolfee']
402        self.browser.getControl("Create ticket").click()
403        self.assertMatches('...ticket created...',
404                           self.browser.contents)
405        self.app['configuration']['2004'].payment_disabled = ['sf_nce1']
406        self.browser.getLink("Add current session payment ticket").click()
407        self.browser.getControl(name="form.p_category").value = ['schoolfee']
408        self.browser.getControl("Create ticket").click()
409        self.assertMatches('...This category of payments has been disabled...',
410                           self.browser.contents)
411        self.certificate.study_mode = 'ug_ft'
412        self.browser.open(self.payments_path)
413        self.browser.getLink("Add current session payment ticket").click()
414        self.browser.getControl(name="form.p_category").value = ['schoolfee']
415        self.browser.getControl("Create ticket").click()
416        self.assertMatches('...ticket created...',
417                           self.browser.contents)
418        return
419
420    def test_student_course_registration(self):
421        IWorkflowState(self.student).setState('school fee paid')
422        self.browser.open(self.login_path)
423        self.browser.getControl(name="form.login").value = self.student_id
424        self.browser.getControl(name="form.password").value = 'spwd'
425        self.browser.getControl("Login").click()
426        # Now students can add the current study level
427        self.browser.getLink("Study Course").click()
428        self.browser.getLink("Add course list").click()
429        self.assertMatches('...Add current level 100 (Year 1)...',
430                           self.browser.contents)
431        self.browser.getControl("Create course list now").click()
432        # Students can't open the customized pdf course registration slip
433        self.browser.open(
434            self.student_path + '/studycourse/100/course_registration_slip.pdf')
435        self.assertEqual(self.browser.headers['Status'], '200 Ok')
436        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
437        path = os.path.join(samples_dir(), 'course_registration_slip.pdf')
438        open(path, 'wb').write(self.browser.contents)
439        print "Sample PDF course_registration_slip.pdf written to %s" % path
Note: See TracBrowser for help on using the repository browser.