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

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

Adjust to previous revisions.

  • Property svn:keywords set to Id
File size: 13.9 KB
Line 
1## $Id: test_browser.py 9433 2012-10-26 21:46:42Z 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.students.accommodation import BedTicket
29from waeup.kofa.testing import FunctionalTestCase
30from waeup.kofa.interfaces import (
31    IExtFileStore, IFileStoreNameChooser)
32from waeup.kofa.students.interfaces import IStudentsUtils
33from waeup.aaue.testing import FunctionalLayer
34
35
36class StudentProcessorTest(FunctionalTestCase):
37    """Perform some batching tests.
38    """
39
40    layer = FunctionalLayer
41
42    def setUp(self):
43        super(StudentProcessorTest, self).setUp()
44        # Setup a sample site for each test
45        app = University()
46        self.dc_root = tempfile.mkdtemp()
47        app['datacenter'].setStoragePath(self.dc_root)
48
49        # Prepopulate the ZODB...
50        self.getRootFolder()['app'] = app
51        # we add the site immediately after creation to the
52        # ZODB. Catalogs and other local utilities are not setup
53        # before that step.
54        self.app = self.getRootFolder()['app']
55        # Set site here. Some of the following setup code might need
56        # to access grok.getSite() and should get our new app then
57        setSite(app)
58
59
60    def tearDown(self):
61        super(StudentProcessorTest, self).tearDown()
62        shutil.rmtree(self.workdir)
63        shutil.rmtree(self.dc_root)
64        clearSite()
65        return
66
67class StudentUITests(StudentsFullSetup):
68    """Tests for customized student class views and pages
69    """
70
71    layer = FunctionalLayer
72
73    def setUp(self):
74        super(StudentUITests, self).setUp()
75
76        bedticket = BedTicket()
77        bedticket.booking_session = 2004
78        bedticket.bed_type = u'any bed type'
79        bedticket.bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
80        bedticket.bed_coordinates = u'My bed coordinates'
81        self.student['accommodation'].addBedTicket(bedticket)
82
83    def test_manage_payments(self):
84        # Add missing configuration data
85        self.app['configuration']['2004'].gown_fee = 150.0
86        self.app['configuration']['2004'].transfer_fee = 90.0
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.getControl("Add online payment ticket").click()
95        self.browser.getControl("Create ticket").click()
96        self.assertMatches('...Wrong state...',
97                           self.browser.contents)
98        IWorkflowState(self.student).setState('cleared')
99        self.browser.open(self.payments_path + '/addop')
100        self.browser.getControl("Create ticket").click()
101        self.assertMatches('...Amount could not be determined...',
102                           self.browser.contents)
103
104        self.app['configuration']['2004'].school_fee_base = 6666.0
105
106        self.browser.getControl("Add online payment ticket").click()
107        self.browser.getControl("Create ticket").click()
108        self.assertMatches('...ticket created...',
109                           self.browser.contents)
110        ctrl = self.browser.getControl(name='val_id')
111        value = ctrl.options[0]
112        self.browser.getLink(value).click()
113        self.assertMatches('...Amount Authorized...',
114                           self.browser.contents)
115        # Managers can open payment slip
116        self.browser.getLink("Download payment slip").click()
117        self.assertEqual(self.browser.headers['Status'], '200 Ok')
118        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
119        # Set ticket paid
120        ticket = self.student['payments'].items()[0][1]
121        ticket.p_state = 'paid'
122        self.browser.open(self.payments_path + '/addop')
123        self.browser.getControl("Create ticket").click()
124        self.assertMatches('...This type of payment has already been made...',
125                           self.browser.contents)
126        self.browser.open(self.payments_path + '/addop')
127        # Also the other payments can be made
128        self.browser.getControl(name="form.p_category").value = ['gown']
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(name="form.p_category").value = ['transfer']
134        self.browser.getControl("Create ticket").click()
135        self.assertMatches('...ticket created...',
136                           self.browser.contents)
137        self.browser.open(self.payments_path + '/addop')
138        self.browser.getControl(
139            name="form.p_category").value = ['bed_allocation']
140        self.browser.getControl("Create ticket").click()
141        self.assertMatches('...ticket created...',
142                           self.browser.contents)
143        self.browser.open(self.payments_path + '/addop')
144        self.browser.getControl(
145            name="form.p_category").value = ['hostel_maintenance']
146        self.browser.getControl("Create ticket").click()
147        self.assertMatches('...ticket created...',
148                           self.browser.contents)
149        self.browser.open(self.payments_path + '/addop')
150        self.browser.getControl(name="form.p_category").value = ['clearance']
151        self.browser.getControl("Create ticket").click()
152        self.assertMatches('...ticket created...',
153                           self.browser.contents)
154        # Remove all payments so that we can add a school fee payment again
155        keys = [i for i in self.student['payments'].keys()]
156        for payment in keys:
157            del self.student['payments'][payment]
158        self.browser.open(self.payments_path + '/addop')
159        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
160        self.browser.getControl("Create ticket").click()
161        self.assertMatches('...ticket created...',
162                           self.browser.contents)
163        # We can't add the 2nd instalment ticket because the
164        # first one has not yet been approved.
165        self.browser.open(self.payments_path + '/addop')
166        self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
167        self.browser.getControl("Create ticket").click()
168        self.assertMatches('...1st school fee instalment has not yet been paid...',
169                           self.browser.contents)
170        # Ok, then we approve the first instalment ...
171        ctrl = self.browser.getControl(name='val_id')
172        p_id = ctrl.options[0]
173        self.browser.open(self.payments_path + '/' + p_id + '/approve')
174        # ... add the second instalment ...
175        self.browser.open(self.payments_path + '/addop')
176        self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
177        self.browser.getControl("Create ticket").click()
178        self.assertMatches('...ticket created...',
179                           self.browser.contents)
180        # ... approve the second instalment ...
181        ctrl = self.browser.getControl(name='val_id')
182        p_id = ctrl.options[1]
183        self.browser.open(self.payments_path + '/' + p_id + '/approve')
184        # ... and finally add the 1st instalment for the next session
185        # provided that student is returning.
186        IWorkflowState(self.student).setState('returning')
187        self.browser.open(self.payments_path + '/addop')
188        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
189        self.browser.getControl("Create ticket").click()
190        self.assertMatches('...Session configuration object is not...',
191                           self.browser.contents)
192        # Uups, we forgot to add a session configuration for next session
193        configuration = createObject('waeup.SessionConfiguration')
194        configuration.academic_session = 2005
195        self.app['configuration'].addSessionConfiguration(configuration)
196        self.app['configuration']['2005'].school_fee_base = 7777.0
197        self.browser.open(self.payments_path + '/addop')
198        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
199        self.browser.getControl("Create ticket").click()
200        self.assertMatches('...ticket created...',
201                           self.browser.contents)
202        # If the session configuration doesn't exist an error message will
203        # be shown. No other requirement is being checked.
204        del self.app['configuration']['2004']
205        self.browser.open(self.payments_path)
206        self.browser.getControl("Add online payment ticket").click()
207        self.browser.getControl("Create ticket").click()
208        self.assertMatches('...Session configuration object is not...',
209                           self.browser.contents)
210
211    def test_get_returning_data(self):
212        # Student is in level 100, session 2004 with verdict A
213        utils = getUtility(IStudentsUtils)
214        self.assertEqual(utils.getReturningData(self.student),(2005, 200))
215        self.student['studycourse'].current_verdict = 'C'
216        self.assertEqual(utils.getReturningData(self.student),(2005, 110))
217        self.student['studycourse'].current_verdict = 'D'
218        self.assertEqual(utils.getReturningData(self.student),(2005, 100))
219        return
220
221    def test_set_payment_details(self):
222        self.app['configuration']['2004'].gown_fee = 150.0
223        self.app['configuration']['2004'].transfer_fee = 90.0
224        self.app['configuration']['2004'].booking_fee = 150.0
225        self.app['configuration']['2004'].maint_fee = 180.0
226        self.app['configuration']['2004'].clearance_fee = 1234.0
227        self.app['configuration']['2004'].school_fee_base = 6666.0
228        utils = getUtility(IStudentsUtils)
229
230        configuration = createObject('waeup.SessionConfiguration')
231        configuration.academic_session = 2005
232        self.app['configuration'].addSessionConfiguration(configuration)
233        self.app['configuration']['2005'].school_fee_base = 7777.0
234
235        error, payment = utils.setPaymentDetails('schoolfee_1',self.student)
236        self.assertEqual(payment, None)
237        self.assertEqual(error, u'Wrong state.')
238
239        IWorkflowState(self.student).setState('cleared')
240        error, payment = utils.setPaymentDetails('schoolfee_1',self.student)
241        self.assertEqual(payment.p_level, 100)
242        self.assertEqual(payment.p_session, 2004)
243        self.assertEqual(payment.amount_auth, 6666.0)
244        self.assertEqual(payment.p_item, u'CERT1')
245        self.assertEqual(error, None)
246
247        # Add penalty fee ...
248        # ... for cleared
249        self.app['configuration']['2004'].penalty_ug = 99.0
250        # ... for returning
251        self.app['configuration']['2005'].penalty_ug = 88.0
252        error, payment = utils.setPaymentDetails('schoolfee_1',self.student)
253        self.assertEqual(payment.amount_auth, 6765.0)
254        IWorkflowState(self.student).setState('returning')
255        error, payment = utils.setPaymentDetails('schoolfee_1',self.student)
256        self.assertEqual(payment.p_level, 200)
257        self.assertEqual(payment.p_session, 2005)
258        self.assertEqual(payment.amount_auth, 7865.0)
259        self.assertEqual(payment.p_item, u'CERT1')
260        self.assertEqual(error, None)
261
262        error, payment = utils.setPaymentDetails('clearance',self.student)
263        self.assertEqual(payment.p_level, 100)
264        self.assertEqual(payment.p_session, 2004)
265        self.assertEqual(payment.amount_auth, 1234.0)
266        self.assertEqual(payment.p_item, u'CERT1')
267        self.assertEqual(error, None)
268
269        error, payment = utils.setPaymentDetails('gown',self.student)
270        self.assertEqual(payment.p_level, 100)
271        self.assertEqual(payment.p_session, 2004)
272        self.assertEqual(payment.amount_auth, 150.0)
273        self.assertEqual(payment.p_item, u'')
274        self.assertEqual(error, None)
275
276        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
277        self.assertEqual(payment.p_level, 100)
278        self.assertEqual(payment.p_session, 2004)
279        self.assertEqual(payment.amount_auth, 180.0)
280        self.assertEqual(payment.p_item, u'')
281        self.assertEqual(error, None)
282
283        error, payment = utils.setPaymentDetails('bed_allocation',self.student)
284        self.assertEqual(payment.p_level, 100)
285        self.assertEqual(payment.p_session, 2004)
286        self.assertEqual(payment.amount_auth, 150.0)
287        self.assertEqual(payment.p_item, u'')
288        self.assertEqual(error, None)
289
290        error, payment = utils.setPaymentDetails('transfer',self.student)
291        self.assertEqual(payment.p_level, 100)
292        self.assertEqual(payment.p_session, 2004)
293        self.assertEqual(payment.amount_auth, 90.0)
294        self.assertEqual(payment.p_item, u'')
295        self.assertEqual(error, None)
296
297        error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100)
298        self.assertEqual(error, u'Previous session payment not yet implemented.')
299        return
Note: See TracBrowser for help on using the repository browser.