source: main/waeup.futminna/trunk/src/waeup/futminna/students/tests/test_browser.py @ 8981

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

Merged with waeup.fceokene 8978:8979.

  • Property svn:keywords set to Id
File size: 12.1 KB
Line 
1## $Id: test_browser.py 8981 2012-07-12 08:53:27Z 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.futminna.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.browser.open(self.payments_path + '/addop')
89        self.browser.getControl("Create ticket").click()
90        self.assertMatches('...ticket created...',
91                           self.browser.contents)
92        ctrl = self.browser.getControl(name='val_id')
93        value = ctrl.options[0]
94        self.browser.getLink(value).click()
95        self.assertMatches('...Amount Authorized...',
96                           self.browser.contents)
97        # Managers can open payment slip
98        self.browser.getLink("Download payment slip").click()
99        self.assertEqual(self.browser.headers['Status'], '200 Ok')
100        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
101        # Set ticket paid
102        ticket = self.student['payments'].items()[0][1]
103        ticket.p_state = 'paid'
104        self.browser.open(self.payments_path + '/addop')
105        self.browser.getControl("Create ticket").click()
106        self.assertMatches('...This type of payment has already been made...',
107                           self.browser.contents)
108        # Remove all payments so that we can add a school fee payment again
109        keys = [i for i in self.student['payments'].keys()]
110        for payment in keys:
111            del self.student['payments'][payment]
112        self.browser.open(self.payments_path + '/addop')
113        self.browser.getControl("Create ticket").click()
114        self.assertMatches('...ticket created...',
115                           self.browser.contents)
116        self.browser.open(self.payments_path + '/addop')
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        self.browser.open(self.payments_path + '/addop')
144        self.browser.getControl(name="form.p_category").value = ['schoolfee']
145        self.browser.getControl("Create ticket").click()
146        self.assertMatches('...ticket created...',
147                           self.browser.contents)
148        # In state returning we can add a new school fee ticket since
149        # p_session and p_level is different
150        IWorkflowState(self.student).setState('returning')
151        self.browser.open(self.payments_path + '/addop')
152        self.browser.getControl(name="form.p_category").value = ['schoolfee']
153        self.browser.getControl("Create ticket").click()
154        self.assertMatches('...Session configuration object is not...',
155                           self.browser.contents)
156        # Uups, we forgot to add a session configuration for next session
157        configuration = createObject('waeup.SessionConfiguration')
158        configuration.academic_session = 2005
159        self.app['configuration'].addSessionConfiguration(configuration)
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 admitted school fee can't be determined
166        IWorkflowState(self.student).setState('admitted')
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        self.assertMatches('...Amount could not be determined...',
171                           self.browser.contents)
172
173        # If the session configuration doesn't exist an error message will
174        # be shown. No other requirement is being checked.
175        del self.app['configuration']['2004']
176        self.browser.open(self.payments_path)
177        self.browser.getControl("Add online payment ticket").click()
178        self.browser.getControl("Create ticket").click()
179        self.assertMatches('...Session configuration object is not...',
180                           self.browser.contents)
181
182    def test_get_returning_data(self):
183        # Student is in level 100, session 2004 with verdict A
184        utils = getUtility(IStudentsUtils)
185        self.assertEqual(utils.getReturningData(self.student),(2005, 200))
186        self.student['studycourse'].current_verdict = 'C'
187        self.assertEqual(utils.getReturningData(self.student),(2005, 110))
188        self.student['studycourse'].current_verdict = 'D'
189        self.assertEqual(utils.getReturningData(self.student),(2005, 100))
190        return
191
192    def test_set_payment_details(self):
193        self.app['configuration']['2004'].gown_fee = 150.0
194        self.app['configuration']['2004'].transfer_fee = 90.0
195        self.app['configuration']['2004'].booking_fee = 150.0
196        self.app['configuration']['2004'].maint_fee = 180.0
197        utils = getUtility(IStudentsUtils)
198
199        configuration = createObject('waeup.SessionConfiguration')
200        configuration.academic_session = 2005
201        self.app['configuration'].addSessionConfiguration(configuration)
202
203        error, payment = utils.setPaymentDetails('schoolfee',self.student)
204        self.assertEqual(payment, None)
205        self.assertEqual(error, u'Amount could not be determined.')
206
207        IWorkflowState(self.student).setState('cleared')
208        error, payment = utils.setPaymentDetails('schoolfee',self.student)
209        self.assertEqual(payment.p_level, 100)
210        self.assertEqual(payment.p_session, 2004)
211        self.assertEqual(payment.amount_auth, 40000.0)
212        self.assertEqual(payment.p_item, u'CERT1')
213        self.assertEqual(error, None)
214
215        # Add penalty fee ...
216        # ... for cleared
217        self.app['configuration']['2004'].penalty_ug = 99.0
218        # ... for returning
219        self.app['configuration']['2005'].penalty_ug = 88.0
220        error, payment = utils.setPaymentDetails('schoolfee',self.student)
221        self.assertEqual(payment.amount_auth, 40099.0)
222
223        IWorkflowState(self.student).setState('returning')
224        error, payment = utils.setPaymentDetails('schoolfee',self.student)
225        self.assertEqual(payment.p_level, 200)
226        self.assertEqual(payment.p_session, 2005)
227        self.assertEqual(payment.amount_auth, 20088.0)
228        self.assertEqual(payment.p_item, u'CERT1')
229        self.assertEqual(error, None)
230
231        error, payment = utils.setPaymentDetails('clearance',self.student)
232        self.assertEqual(payment.p_level, 100)
233        self.assertEqual(payment.p_session, 2004)
234        self.assertEqual(payment.amount_auth, 34250.0)
235        self.assertEqual(payment.p_item, u'CERT1')
236        self.assertEqual(error, None)
237
238        error, payment = utils.setPaymentDetails('gown',self.student)
239        self.assertEqual(payment.p_level, 100)
240        self.assertEqual(payment.p_session, 2004)
241        self.assertEqual(payment.amount_auth, 150.0)
242        self.assertEqual(payment.p_item, u'')
243        self.assertEqual(error, None)
244
245        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
246        self.assertEqual(payment.p_level, 100)
247        self.assertEqual(payment.p_session, 2004)
248        self.assertEqual(payment.amount_auth, 180.0)
249        self.assertEqual(payment.p_item, u'')
250        self.assertEqual(error, None)
251
252        error, payment = utils.setPaymentDetails('bed_allocation',self.student)
253        self.assertEqual(payment.p_level, 100)
254        self.assertEqual(payment.p_session, 2004)
255        self.assertEqual(payment.amount_auth, 150.0)
256        self.assertEqual(payment.p_item, u'')
257        self.assertEqual(error, None)
258
259        error, payment = utils.setPaymentDetails('transfer',self.student)
260        self.assertEqual(payment.p_level, 100)
261        self.assertEqual(payment.p_session, 2004)
262        self.assertEqual(payment.amount_auth, 90.0)
263        self.assertEqual(payment.p_item, u'')
264        self.assertEqual(error, None)
265        return
Note: See TracBrowser for help on using the repository browser.