source: main/waeup.uniben/trunk/src/waeup/uniben/students/tests/test_browser.py @ 9206

Last change on this file since 9206 was 9206, checked in by Henrik Bettermann, 12 years ago

Previous session must be valid.

  • Property svn:keywords set to Id
File size: 16.8 KB
Line 
1## $Id: test_browser.py 9206 2012-09-19 14:24:46Z 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
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 StudentsFullSetup
28from waeup.kofa.testing import FunctionalTestCase
29from waeup.kofa.interfaces import (
30    IExtFileStore, IFileStoreNameChooser)
31from waeup.kofa.students.interfaces import IStudentsUtils
32from waeup.uniben.testing import FunctionalLayer
33
34
35class StudentProcessorTest(FunctionalTestCase):
36    """Perform some batching tests.
37    """
38
39    layer = FunctionalLayer
40
41    def setUp(self):
42        super(StudentProcessorTest, self).setUp()
43        # Setup a sample site for each test
44        app = University()
45        self.dc_root = tempfile.mkdtemp()
46        app['datacenter'].setStoragePath(self.dc_root)
47
48        # Prepopulate the ZODB...
49        self.getRootFolder()['app'] = app
50        # we add the site immediately after creation to the
51        # ZODB. Catalogs and other local utilities are not setup
52        # before that step.
53        self.app = self.getRootFolder()['app']
54        # Set site here. Some of the following setup code might need
55        # to access grok.getSite() and should get our new app then
56        setSite(app)
57
58
59    def tearDown(self):
60        super(StudentProcessorTest, self).tearDown()
61        shutil.rmtree(self.workdir)
62        shutil.rmtree(self.dc_root)
63        clearSite()
64        return
65
66class StudentUITests(StudentsFullSetup):
67    """Tests for customized student class views and pages
68    """
69
70    layer = FunctionalLayer
71
72    def test_manage_payments(self):
73        # Add missing configuration data
74        self.app['configuration']['2004'].gown_fee = 150.0
75        self.app['configuration']['2004'].transfer_fee = 90.0
76        #self.app['configuration']['2004'].clearance_fee = 120.0
77        self.app['configuration']['2004'].booking_fee = 150.0
78        self.app['configuration']['2004'].maint_fee = 180.0
79
80        # Managers can add online payment tickets
81        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
82        self.browser.open(self.payments_path)
83        self.browser.getControl("Add online payment ticket").click()
84        self.browser.getControl("Create ticket").click()
85        self.assertMatches('...Amount could not be determined...',
86                           self.browser.contents)
87        IWorkflowState(self.student).setState('cleared')
88        self.student.nationality = u'NG'
89        self.browser.open(self.payments_path + '/addop')
90        self.browser.getControl("Create ticket").click()
91        self.assertMatches('...ticket created...',
92                           self.browser.contents)
93        ctrl = self.browser.getControl(name='val_id')
94        value = ctrl.options[0]
95        self.browser.getLink(value).click()
96        self.assertMatches('...Amount Authorized...',
97                           self.browser.contents)
98        # Managers can open payment slip
99        self.browser.getLink("Download payment slip").click()
100        self.assertEqual(self.browser.headers['Status'], '200 Ok')
101        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
102        # Set ticket paid
103        ticket = self.student['payments'].items()[0][1]
104        ticket.p_state = 'paid'
105        self.browser.open(self.payments_path + '/addop')
106        self.browser.getControl("Create ticket").click()
107        self.assertMatches('...This type of payment has already been made...',
108                           self.browser.contents)
109        # Remove all payments so that we can add a school fee payment again
110        keys = [i for i in self.student['payments'].keys()]
111        for payment in keys:
112            del self.student['payments'][payment]
113        self.browser.open(self.payments_path + '/addop')
114        self.browser.getControl("Create ticket").click()
115        self.assertMatches('...ticket created...',
116                           self.browser.contents)
117        self.browser.open(self.payments_path + '/addop')
118        self.browser.getControl(name="form.p_category").value = ['gown']
119        self.browser.getControl("Create ticket").click()
120        self.assertMatches('...ticket created...',
121                           self.browser.contents)
122        self.browser.open(self.payments_path + '/addop')
123        self.browser.getControl(name="form.p_category").value = ['transfer']
124        self.browser.getControl("Create ticket").click()
125        self.assertMatches('...ticket created...',
126                           self.browser.contents)
127        self.browser.open(self.payments_path + '/addop')
128        self.browser.getControl(
129            name="form.p_category").value = ['bed_allocation']
130        self.browser.getControl("Create ticket").click()
131        self.assertMatches('...ticket created...',
132                           self.browser.contents)
133        self.browser.open(self.payments_path + '/addop')
134        self.browser.getControl(
135            name="form.p_category").value = ['hostel_maintenance']
136        self.browser.getControl("Create ticket").click()
137        self.assertMatches('...ticket created...',
138                           self.browser.contents)
139        self.browser.open(self.payments_path + '/addop')
140        self.browser.getControl(name="form.p_category").value = ['clearance']
141        self.browser.getControl("Create ticket").click()
142        self.assertMatches('...ticket created...',
143                           self.browser.contents)
144        self.browser.open(self.payments_path + '/addop')
145        self.browser.getControl(name="form.p_category").value = ['schoolfee']
146        self.browser.getControl("Create ticket").click()
147        self.assertMatches('...ticket created...',
148                           self.browser.contents)
149        # In state returning we can add a new school fee ticket since
150        # p_session and p_level is different
151        IWorkflowState(self.student).setState('returning')
152        self.browser.open(self.payments_path + '/addop')
153        self.browser.getControl(name="form.p_category").value = ['schoolfee']
154        self.browser.getControl("Create ticket").click()
155        self.assertMatches('...Session configuration object is not...',
156                           self.browser.contents)
157        # Uups, we forgot to add a session configuration for next session
158        configuration = createObject('waeup.SessionConfiguration')
159        configuration.academic_session = 2005
160        self.app['configuration'].addSessionConfiguration(configuration)
161        self.browser.open(self.payments_path + '/addop')
162        self.browser.getControl(name="form.p_category").value = ['schoolfee']
163        self.browser.getControl("Create ticket").click()
164        self.assertMatches('...ticket created...',
165                           self.browser.contents)
166        # In state admitted school fee can't be determined
167        IWorkflowState(self.student).setState('admitted')
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        self.assertMatches('...Amount could not be determined...',
172                           self.browser.contents)
173
174        # If the session configuration doesn't exist an error message will
175        # be shown. No other requirement is being checked.
176        del self.app['configuration']['2004']
177        self.browser.open(self.payments_path)
178        self.browser.getControl("Add online payment ticket").click()
179        self.browser.getControl("Create ticket").click()
180        self.assertMatches('...Session configuration object is not...',
181                           self.browser.contents)
182
183    def test_get_returning_data(self):
184        # Student is in level 100, session 2004 with verdict A
185        utils = getUtility(IStudentsUtils)
186        self.assertEqual(utils.getReturningData(self.student),(2005, 200))
187        self.student['studycourse'].current_verdict = 'C'
188        self.assertEqual(utils.getReturningData(self.student),(2005, 110))
189        self.student['studycourse'].current_verdict = 'D'
190        self.assertEqual(utils.getReturningData(self.student),(2005, 100))
191        return
192
193    def test_set_returning_data(self):
194        # Student is in level 100, session 2004 with verdict A
195        utils = getUtility(IStudentsUtils)
196
197        utils.setReturningData(self.student)
198        self.assertEqual(self.student['studycourse'].current_session, 2005)
199        self.assertEqual(self.student['studycourse'].current_level, 200)
200
201        self.student['studycourse'].current_session = 2004
202        self.student['studycourse'].current_level = 100
203        self.student['studycourse'].current_verdict = 'C'
204        utils.setReturningData(self.student)
205        self.assertEqual(self.student['studycourse'].current_session, 2005)
206        self.assertEqual(self.student['studycourse'].current_level, 110)
207
208        self.student['studycourse'].current_session = 2004
209        self.student['studycourse'].current_level = 100
210        self.student['studycourse'].current_verdict = 'D'
211        utils.setReturningData(self.student)
212        self.assertEqual(self.student['studycourse'].current_session, 2005)
213        self.assertEqual(self.student['studycourse'].current_level, 100)
214        return
215
216    def test_set_payment_details(self):
217        self.app['configuration']['2004'].gown_fee = 150.0
218        self.app['configuration']['2004'].transfer_fee = 90.0
219        self.app['configuration']['2004'].booking_fee = 150.0
220        self.app['configuration']['2004'].maint_fee = 180.0
221
222        configuration = createObject('waeup.SessionConfiguration')
223        configuration.academic_session = 2000
224        self.app['configuration'].addSessionConfiguration(configuration)
225        configuration2 = createObject('waeup.SessionConfiguration')
226        configuration2.academic_session = 2002
227        self.app['configuration'].addSessionConfiguration(configuration2)
228        configuration3 = createObject('waeup.SessionConfiguration')
229        configuration3.academic_session = 2003
230        self.app['configuration'].addSessionConfiguration(configuration3)
231
232        utils = getUtility(IStudentsUtils)
233
234        self.student['studycourse'].entry_session = 2002
235        self.student.nationality = u'NG'
236
237        configuration = createObject('waeup.SessionConfiguration')
238        configuration.academic_session = 2005
239        self.app['configuration'].addSessionConfiguration(configuration)
240
241        error, payment = utils.setPaymentDetails('schoolfee',
242            self.student, None, None)
243        self.assertEqual(payment, None)
244        self.assertTrue(u'Amount could not be determined.' in error)
245
246        # Previous session must be valid.
247        error, payment = utils.setPaymentDetails('schoolfee',
248            self.student, 2000, 300)
249        self.assertEqual(payment, None)
250        self.assertTrue(u'The previous session must not fall below' in error)
251        error, payment = utils.setPaymentDetails('schoolfee',
252            self.student, 2004, 300)
253        self.assertEqual(payment, None)
254        self.assertTrue(u'This is not a previous session' in error)
255
256        # Previous session payment; fresh and returning
257        # are distinguished by their entry_level
258        error, payment = utils.setPaymentDetails('schoolfee',
259            self.student, 2002, 300)
260        self.assertEqual(payment.amount_auth, 40000.0)
261        self.assertEqual(payment.p_session, 2002)
262        self.assertEqual(payment.p_level, 300)
263        self.assertFalse(payment.p_current)
264        error, payment = utils.setPaymentDetails('schoolfee',
265            self.student, 2003, 300)
266        self.assertEqual(payment.amount_auth, 20000.0)
267        self.assertEqual(payment.p_session, 2003)
268        self.assertEqual(payment.p_level, 300)
269        self.assertFalse(payment.p_current)
270
271        # Current payment; fresh and returning
272        # are distinguished by their state
273        IWorkflowState(self.student).setState('cleared')
274        error, payment = utils.setPaymentDetails('schoolfee',
275            self.student, None, None)
276        self.assertEqual(payment.p_level, 100)
277        self.assertEqual(payment.p_session, 2004)
278        self.assertEqual(payment.amount_auth, 40000.0)
279        self.assertEqual(payment.p_item, u'CERT1')
280        self.assertEqual(error, None)
281        self.assertTrue(payment.p_current)
282
283        # Add penalty fee ...
284        # ... for cleared
285        self.app['configuration']['2004'].penalty_ug = 99.0
286        # ... for returning
287        self.app['configuration']['2005'].penalty_ug = 88.0
288        error, payment = utils.setPaymentDetails('schoolfee',
289            self.student, None, None)
290        self.assertEqual(payment.amount_auth, 40099.0)
291
292        IWorkflowState(self.student).setState('returning')
293        error, payment = utils.setPaymentDetails('schoolfee',
294            self.student, None, None)
295        self.assertEqual(payment.p_level, 200)
296        self.assertEqual(payment.p_session, 2005)
297        self.assertEqual(payment.amount_auth, 20088.0)
298        self.assertEqual(payment.p_item, u'CERT1')
299        self.assertEqual(error, None)
300
301        self.student.is_staff = True
302        error, payment = utils.setPaymentDetails('schoolfee',
303            self.student, None, None)
304        self.assertEqual(payment.p_level, 200)
305        self.assertEqual(payment.p_session, 2005)
306        self.assertEqual(payment.amount_auth, 10088.0)
307        self.assertEqual(payment.p_item, u'CERT1')
308        self.assertEqual(error, None)
309
310        IWorkflowState(self.student).setState('cleared')
311        self.student.is_staff = False
312        self.student.nationality = u'DE'
313        self.certificate.school_fee_3 = 60000.0
314        error, payment = utils.setPaymentDetails(
315            'schoolfee', self.student, None, None)
316        self.assertEqual(payment.p_level, 100)
317        self.assertEqual(payment.p_session, 2004)
318        self.assertEqual(payment.amount_auth, 60099.0)
319        self.assertEqual(payment.p_item, u'CERT1')
320        self.assertEqual(error, None)
321
322        IWorkflowState(self.student).setState('returning')
323        self.student.is_staff = False
324        self.student.nationality = u'DE'
325        self.certificate.school_fee_4 = 20000.0
326        error, payment = utils.setPaymentDetails(
327            'schoolfee', self.student, None, None)
328        self.assertEqual(payment.p_level, 200)
329        self.assertEqual(payment.p_session, 2005)
330        self.assertEqual(payment.amount_auth, 20088.0)
331        self.assertEqual(payment.p_item, u'CERT1')
332        self.assertEqual(error, None)
333
334        error, payment = utils.setPaymentDetails('clearance',
335            self.student, None, None)
336        self.assertEqual(payment.p_level, 100)
337        self.assertEqual(payment.p_session, 2004)
338        self.assertEqual(payment.amount_auth, 34250.0)
339        self.assertEqual(payment.p_item, u'CERT1')
340        self.assertEqual(error, None)
341
342        error, payment = utils.setPaymentDetails('gown',
343            self.student, None, None)
344        self.assertEqual(payment.p_level, 100)
345        self.assertEqual(payment.p_session, 2004)
346        self.assertEqual(payment.amount_auth, 150.0)
347        self.assertEqual(payment.p_item, u'')
348        self.assertEqual(error, None)
349
350        error, payment = utils.setPaymentDetails('hostel_maintenance',
351            self.student, None, None)
352        self.assertEqual(payment.p_level, 100)
353        self.assertEqual(payment.p_session, 2004)
354        self.assertEqual(payment.amount_auth, 180.0)
355        self.assertEqual(payment.p_item, u'')
356        self.assertEqual(error, None)
357
358        error, payment = utils.setPaymentDetails('bed_allocation',
359            self.student, None, None)
360        self.assertEqual(payment.p_level, 100)
361        self.assertEqual(payment.p_session, 2004)
362        self.assertEqual(payment.amount_auth, 150.0)
363        self.assertEqual(payment.p_item, u'')
364        self.assertEqual(error, None)
365
366        error, payment = utils.setPaymentDetails('transfer',
367            self.student, None, None)
368        self.assertEqual(payment.p_level, 100)
369        self.assertEqual(payment.p_session, 2004)
370        self.assertEqual(payment.amount_auth, 90.0)
371        self.assertEqual(payment.p_item, u'')
372        self.assertEqual(error, None)
373        return
Note: See TracBrowser for help on using the repository browser.