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

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

Prepare for previous session payments.

  • Property svn:keywords set to Id
File size: 13.4 KB
Line 
1## $Id: test_browser.py 9154 2012-09-04 07:07:44Z 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.aaue.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('...Wrong state...',
86                           self.browser.contents)
87        IWorkflowState(self.student).setState('cleared')
88        self.browser.open(self.payments_path + '/addop')
89        self.browser.getControl("Create ticket").click()
90        self.assertMatches('...Amount could not be determined...',
91                           self.browser.contents)
92
93        self.app['configuration']['2004'].school_fee_base = 6666.0
94
95        self.browser.getControl("Add online payment ticket").click()
96        self.browser.getControl("Create ticket").click()
97        self.assertMatches('...ticket created...',
98                           self.browser.contents)
99        ctrl = self.browser.getControl(name='val_id')
100        value = ctrl.options[0]
101        self.browser.getLink(value).click()
102        self.assertMatches('...Amount Authorized...',
103                           self.browser.contents)
104        # Managers can open payment slip
105        self.browser.getLink("Download payment slip").click()
106        self.assertEqual(self.browser.headers['Status'], '200 Ok')
107        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
108        # Set ticket paid
109        ticket = self.student['payments'].items()[0][1]
110        ticket.p_state = 'paid'
111        self.browser.open(self.payments_path + '/addop')
112        self.browser.getControl("Create ticket").click()
113        self.assertMatches('...This type of payment has already been made...',
114                           self.browser.contents)
115        self.browser.open(self.payments_path + '/addop')
116        # Also the other payments can be made
117        self.browser.getControl(name="form.p_category").value = ['gown']
118        self.browser.getControl("Create ticket").click()
119        self.assertMatches('...ticket created...',
120                           self.browser.contents)
121        self.browser.open(self.payments_path + '/addop')
122        self.browser.getControl(name="form.p_category").value = ['transfer']
123        self.browser.getControl("Create ticket").click()
124        self.assertMatches('...ticket created...',
125                           self.browser.contents)
126        self.browser.open(self.payments_path + '/addop')
127        self.browser.getControl(
128            name="form.p_category").value = ['bed_allocation']
129        self.browser.getControl("Create ticket").click()
130        self.assertMatches('...ticket created...',
131                           self.browser.contents)
132        self.browser.open(self.payments_path + '/addop')
133        self.browser.getControl(
134            name="form.p_category").value = ['hostel_maintenance']
135        self.browser.getControl("Create ticket").click()
136        self.assertMatches('...ticket created...',
137                           self.browser.contents)
138        self.browser.open(self.payments_path + '/addop')
139        self.browser.getControl(name="form.p_category").value = ['clearance']
140        self.browser.getControl("Create ticket").click()
141        self.assertMatches('...ticket created...',
142                           self.browser.contents)
143        # Remove all payments so that we can add a school fee payment again
144        keys = [i for i in self.student['payments'].keys()]
145        for payment in keys:
146            del self.student['payments'][payment]
147        self.browser.open(self.payments_path + '/addop')
148        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
149        self.browser.getControl("Create ticket").click()
150        self.assertMatches('...ticket created...',
151                           self.browser.contents)
152        # We can't add the 2nd instalment ticket because the
153        # first one has not yet been approved.
154        self.browser.open(self.payments_path + '/addop')
155        self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
156        self.browser.getControl("Create ticket").click()
157        self.assertMatches('...1st school fee instalment has not yet been paid...',
158                           self.browser.contents)
159        # Ok, then we approve the first instalment ...
160        ctrl = self.browser.getControl(name='val_id')
161        p_id = ctrl.options[0]
162        self.browser.open(self.payments_path + '/' + p_id + '/approve')
163        # ... add the second instalment ...
164        self.browser.open(self.payments_path + '/addop')
165        self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
166        self.browser.getControl("Create ticket").click()
167        self.assertMatches('...ticket created...',
168                           self.browser.contents)
169        # ... approve the second instalment ...
170        ctrl = self.browser.getControl(name='val_id')
171        p_id = ctrl.options[1]
172        self.browser.open(self.payments_path + '/' + p_id + '/approve')
173        # ... and finally add the 1st instalment for the next session
174        # provided that student is returning.
175        IWorkflowState(self.student).setState('returning')
176        self.browser.open(self.payments_path + '/addop')
177        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
178        self.browser.getControl("Create ticket").click()
179        self.assertMatches('...Session configuration object is not...',
180                           self.browser.contents)
181        # Uups, we forgot to add a session configuration for next session
182        configuration = createObject('waeup.SessionConfiguration')
183        configuration.academic_session = 2005
184        self.app['configuration'].addSessionConfiguration(configuration)
185        self.app['configuration']['2005'].school_fee_base = 7777.0
186        self.browser.open(self.payments_path + '/addop')
187        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
188        self.browser.getControl("Create ticket").click()
189        self.assertMatches('...ticket created...',
190                           self.browser.contents)
191        # If the session configuration doesn't exist an error message will
192        # be shown. No other requirement is being checked.
193        del self.app['configuration']['2004']
194        self.browser.open(self.payments_path)
195        self.browser.getControl("Add online payment ticket").click()
196        self.browser.getControl("Create ticket").click()
197        self.assertMatches('...Session configuration object is not...',
198                           self.browser.contents)
199
200    def test_get_returning_data(self):
201        # Student is in level 100, session 2004 with verdict A
202        utils = getUtility(IStudentsUtils)
203        self.assertEqual(utils.getReturningData(self.student),(2005, 200))
204        self.student['studycourse'].current_verdict = 'C'
205        self.assertEqual(utils.getReturningData(self.student),(2005, 110))
206        self.student['studycourse'].current_verdict = 'D'
207        self.assertEqual(utils.getReturningData(self.student),(2005, 100))
208        return
209
210    def test_set_payment_details(self):
211        self.app['configuration']['2004'].gown_fee = 150.0
212        self.app['configuration']['2004'].transfer_fee = 90.0
213        self.app['configuration']['2004'].booking_fee = 150.0
214        self.app['configuration']['2004'].maint_fee = 180.0
215        self.app['configuration']['2004'].clearance_fee = 1234.0
216        self.app['configuration']['2004'].school_fee_base = 6666.0
217        utils = getUtility(IStudentsUtils)
218
219        configuration = createObject('waeup.SessionConfiguration')
220        configuration.academic_session = 2005
221        self.app['configuration'].addSessionConfiguration(configuration)
222        self.app['configuration']['2005'].school_fee_base = 7777.0
223
224        error, payment = utils.setPaymentDetails('schoolfee_1',self.student)
225        self.assertEqual(payment, None)
226        self.assertEqual(error, u'Wrong state.')
227
228        IWorkflowState(self.student).setState('cleared')
229        error, payment = utils.setPaymentDetails('schoolfee_1',self.student)
230        self.assertEqual(payment.p_level, 100)
231        self.assertEqual(payment.p_session, 2004)
232        self.assertEqual(payment.amount_auth, 6666.0)
233        self.assertEqual(payment.p_item, u'CERT1')
234        self.assertEqual(error, None)
235
236        # Add penalty fee ...
237        # ... for cleared
238        self.app['configuration']['2004'].penalty_ug = 99.0
239        # ... for returning
240        self.app['configuration']['2005'].penalty_ug = 88.0
241        error, payment = utils.setPaymentDetails('schoolfee_1',self.student)
242        self.assertEqual(payment.amount_auth, 6765.0)
243        IWorkflowState(self.student).setState('returning')
244        error, payment = utils.setPaymentDetails('schoolfee_1',self.student)
245        self.assertEqual(payment.p_level, 200)
246        self.assertEqual(payment.p_session, 2005)
247        self.assertEqual(payment.amount_auth, 7865.0)
248        self.assertEqual(payment.p_item, u'CERT1')
249        self.assertEqual(error, None)
250
251        error, payment = utils.setPaymentDetails('clearance',self.student)
252        self.assertEqual(payment.p_level, 100)
253        self.assertEqual(payment.p_session, 2004)
254        self.assertEqual(payment.amount_auth, 1234.0)
255        self.assertEqual(payment.p_item, u'CERT1')
256        self.assertEqual(error, None)
257
258        error, payment = utils.setPaymentDetails('gown',self.student)
259        self.assertEqual(payment.p_level, 100)
260        self.assertEqual(payment.p_session, 2004)
261        self.assertEqual(payment.amount_auth, 150.0)
262        self.assertEqual(payment.p_item, u'')
263        self.assertEqual(error, None)
264
265        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
266        self.assertEqual(payment.p_level, 100)
267        self.assertEqual(payment.p_session, 2004)
268        self.assertEqual(payment.amount_auth, 180.0)
269        self.assertEqual(payment.p_item, u'')
270        self.assertEqual(error, None)
271
272        error, payment = utils.setPaymentDetails('bed_allocation',self.student)
273        self.assertEqual(payment.p_level, 100)
274        self.assertEqual(payment.p_session, 2004)
275        self.assertEqual(payment.amount_auth, 150.0)
276        self.assertEqual(payment.p_item, u'')
277        self.assertEqual(error, None)
278
279        error, payment = utils.setPaymentDetails('transfer',self.student)
280        self.assertEqual(payment.p_level, 100)
281        self.assertEqual(payment.p_session, 2004)
282        self.assertEqual(payment.amount_auth, 90.0)
283        self.assertEqual(payment.p_item, u'')
284        self.assertEqual(error, None)
285
286        error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100)
287        self.assertEqual(error, u'Previous session payment not yet implemented.')
288        return
Note: See TracBrowser for help on using the repository browser.