source: main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students/tests/test_browser.py @ 9724

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

Implement carry-over fee payment.

  • Property svn:keywords set to Id
File size: 15.4 KB
Line 
1## $Id: test_browser.py 9724 2012-11-26 14:41:57Z 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.interfaces import (
32    IExtFileStore, IFileStoreNameChooser)
33from waeup.kofa.students.interfaces import IStudentsUtils
34from waeup.kwarapoly.testing import FunctionalLayer
35from waeup.kwarapoly.students.utils import (
36    local_nonlocal, arts_science, pt_ft)
37
38
39class StudentProcessorTest(FunctionalTestCase):
40    """Perform some batching tests.
41    """
42
43    layer = FunctionalLayer
44
45    def setUp(self):
46        super(StudentProcessorTest, self).setUp()
47        # Setup a sample site for each test
48        app = University()
49        self.dc_root = tempfile.mkdtemp()
50        app['datacenter'].setStoragePath(self.dc_root)
51
52        # Prepopulate the ZODB...
53        self.getRootFolder()['app'] = app
54        # we add the site immediately after creation to the
55        # ZODB. Catalogs and other local utilities are not setup
56        # before that step.
57        self.app = self.getRootFolder()['app']
58        # Set site here. Some of the following setup code might need
59        # to access grok.getSite() and should get our new app then
60        setSite(app)
61
62
63    def tearDown(self):
64        super(StudentProcessorTest, self).tearDown()
65        shutil.rmtree(self.workdir)
66        shutil.rmtree(self.dc_root)
67        clearSite()
68        return
69
70class StudentUITests(StudentsFullSetup):
71    """Tests for customized student class views and pages
72    """
73
74    layer = FunctionalLayer
75
76    def setUp(self):
77        super(StudentUITests, self).setUp()
78
79        bedticket = BedTicket()
80        bedticket.booking_session = 2004
81        bedticket.bed_type = u'any bed type'
82        bedticket.bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
83        bedticket.bed_coordinates = u'My bed coordinates'
84        self.student['accommodation'].addBedTicket(bedticket)
85
86    def test_manage_payments(self):
87        # Add missing configuration data
88        self.app['configuration']['2004'].gown_fee = 150.0
89        self.app['configuration']['2004'].transfer_fee = 90.0
90        self.app['configuration']['2004'].clearance_fee = 120.0
91        self.app['configuration']['2004'].booking_fee = 150.0
92        self.app['configuration']['2004'].maint_fee = 180.0
93
94        # Managers can add online payment tickets
95        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
96        self.browser.open(self.payments_path)
97        self.browser.getLink("Add current session payment ticket").click()
98        self.browser.getControl("Create ticket").click()
99        self.assertMatches('...Amount could not be determined...',
100                           self.browser.contents)
101        IWorkflowState(self.student).setState('cleared')
102        self.browser.open(self.payments_path + '/addop')
103        self.browser.getControl("Create ticket").click()
104        self.assertMatches('...ticket created...',
105                           self.browser.contents)
106        ctrl = self.browser.getControl(name='val_id')
107        value = ctrl.options[0]
108        self.browser.getLink(value).click()
109        self.assertMatches('...Amount Authorized...',
110                           self.browser.contents)
111        # Managers can open payment slip
112        self.browser.getLink("Download payment slip").click()
113        self.assertEqual(self.browser.headers['Status'], '200 Ok')
114        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
115        # Set ticket paid
116        ticket = self.student['payments'].items()[0][1]
117        ticket.p_state = 'paid'
118        self.browser.open(self.payments_path + '/addop')
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("Create ticket").click()
128        self.assertMatches('...ticket created...',
129                           self.browser.contents)
130        self.browser.open(self.payments_path + '/addop')
131        self.browser.getControl(name="form.p_category").value = ['co1']
132        self.browser.getControl("Create ticket").click()
133        self.assertMatches('...ticket created...',
134                           self.browser.contents)
135        self.browser.open(self.payments_path + '/addop')
136        self.browser.getControl(name="form.p_category").value = ['co2']
137        self.browser.getControl("Create ticket").click()
138        self.assertMatches('...ticket created...',
139                           self.browser.contents)
140        self.browser.open(self.payments_path + '/addop')
141        self.browser.getControl(name="form.p_category").value = ['co3']
142        self.browser.getControl("Create ticket").click()
143        self.assertMatches('...ticket created...',
144                           self.browser.contents)
145        self.browser.open(self.payments_path + '/addop')
146        self.browser.getControl(
147            name="form.p_category").value = ['bed_allocation']
148        self.browser.getControl("Create ticket").click()
149        self.assertMatches('...ticket created...',
150                           self.browser.contents)
151        self.browser.open(self.payments_path + '/addop')
152        self.browser.getControl(
153            name="form.p_category").value = ['hostel_maintenance']
154        self.browser.getControl("Create ticket").click()
155        self.assertMatches('...ticket created...',
156                           self.browser.contents)
157        self.browser.open(self.payments_path + '/addop')
158        self.browser.getControl(name="form.p_category").value = ['clearance']
159        self.browser.getControl("Create ticket").click()
160        self.assertMatches('...ticket created...',
161                           self.browser.contents)
162        self.browser.open(self.payments_path + '/addop')
163        self.browser.getControl(name="form.p_category").value = ['schoolfee']
164        self.browser.getControl("Create ticket").click()
165        self.assertMatches('...ticket created...',
166                           self.browser.contents)
167        # In state returning we can add a new school fee ticket since
168        # p_session and p_level is different
169        IWorkflowState(self.student).setState('returning')
170        self.browser.open(self.payments_path + '/addop')
171        self.browser.getControl(name="form.p_category").value = ['schoolfee']
172        self.browser.getControl("Create ticket").click()
173        # Uups, we forgot to add a session configuration for next session
174        self.assertTrue('Session configuration object is not available.'
175            in self.browser.contents)
176        configuration = createObject('waeup.SessionConfiguration')
177        configuration.academic_session = 2005
178        self.app['configuration'].addSessionConfiguration(configuration)
179        self.browser.getControl("Create ticket").click()
180        self.assertMatches('...ticket created...',
181                           self.browser.contents)
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('...Amount could not be determined...',
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        return
213
214    def test_set_payment_details(self):
215        self.app['configuration']['2004'].gown_fee = 150.0
216        self.app['configuration']['2004'].transfer_fee = 90.0
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'Amount could not be determined.')
225
226        IWorkflowState(self.student).setState('cleared')
227        self.assertEqual(local_nonlocal(self.student), 'non-local')
228        self.assertEqual(arts_science(self.student), 'science')
229        self.assertEqual(pt_ft(self.student), 'ft')
230
231        error, payment = utils.setPaymentDetails('schoolfee',self.student)
232        self.assertEqual(payment.p_level, 100)
233        self.assertEqual(payment.p_session, 2004)
234        self.assertEqual(payment.amount_auth, 52100.0)
235        self.assertEqual(payment.p_item, u'CERT1')
236        self.assertEqual(error, None)
237
238        IWorkflowState(self.student).setState('returning')
239        error, payment = utils.setPaymentDetails('schoolfee',self.student)
240        self.assertEqual('Session configuration object is not available.', error)
241        configuration = createObject('waeup.SessionConfiguration')
242        configuration.academic_session = 2005
243        self.app['configuration'].addSessionConfiguration(configuration)
244        error, payment = utils.setPaymentDetails('schoolfee',self.student)
245        self.assertEqual(payment.p_level, 200)
246        self.assertEqual(payment.p_session, 2005)
247        self.assertEqual(payment.amount_auth, 38850.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, 120.0)
255        self.assertEqual(payment.p_item, u'CERT1')
256        self.assertEqual(error, None)
257
258        error, payment = utils.setPaymentDetails('co1',self.student)
259        self.assertEqual(payment.p_level, 100)
260        self.assertEqual(payment.p_session, 2004)
261        self.assertEqual(payment.amount_auth, 6000.0)
262        self.assertEqual(payment.p_item, u'')
263        self.assertEqual(error, None)
264
265        error, payment = utils.setPaymentDetails('co2',self.student)
266        self.assertEqual(payment.p_level, 100)
267        self.assertEqual(payment.p_session, 2004)
268        self.assertEqual(payment.amount_auth, 7000.0)
269        self.assertEqual(payment.p_item, u'')
270        self.assertEqual(error, None)
271
272        error, payment = utils.setPaymentDetails('co3',self.student)
273        self.assertEqual(payment.p_level, 100)
274        self.assertEqual(payment.p_session, 2004)
275        self.assertEqual(payment.amount_auth, 8000.0)
276        self.assertEqual(payment.p_item, u'')
277        self.assertEqual(error, None)
278
279        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
280        self.assertEqual(payment.p_level, 100)
281        self.assertEqual(payment.p_session, 2004)
282        self.assertEqual(payment.amount_auth, 180.0)
283        self.assertEqual(payment.p_item, u'')
284        self.assertEqual(error, None)
285
286        error, payment = utils.setPaymentDetails('bed_allocation',self.student)
287        self.assertEqual(payment.p_level, 100)
288        self.assertEqual(payment.p_session, 2004)
289        self.assertEqual(payment.amount_auth, 150.0)
290        self.assertEqual(payment.p_item, u'')
291        self.assertEqual(error, None)
292
293        error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100)
294        self.assertEqual(error, u'Previous session payment not yet implemented.')
295        return
296
297    def test_student_start_clearance(self):
298        self.browser.open(self.login_path)
299        self.browser.getControl(name="form.login").value = self.student_id
300        self.browser.getControl(name="form.password").value = 'spwd'
301        self.browser.getControl("Login").click()
302
303        IWorkflowInfo(self.student).fireTransition('admit')
304        self.browser.open(self.student_path + '/change_portrait')
305        image = open(SAMPLE_IMAGE, 'rb')
306        ctrl = self.browser.getControl(name='passportuploadedit')
307        file_ctrl = ctrl.mech_control
308        file_ctrl.add_file(image, filename='my_photo.jpg')
309        self.browser.getControl(
310            name='upload_passportuploadedit').click()
311        self.browser.open(self.student_path + '/start_clearance')
312        # In Okene the students can just start clearance without entering
313        # an activation code.
314        self.browser.getControl("Start clearance now").click()
315        self.assertMatches('...Clearance process has been started...',
316                           self.browser.contents)
317
318    def test_student_accommodation(self):
319        del self.student['accommodation']['2004']
320        # Login
321        self.browser.open(self.login_path)
322        self.browser.getControl(name="form.login").value = self.student_id
323        self.browser.getControl(name="form.password").value = 'spwd'
324        self.browser.getControl("Login").click()
325
326        # Students can book accommodation without AC ...
327        self.browser.open(self.acco_path)
328        IWorkflowInfo(self.student).fireTransition('admit')
329        self.browser.getLink("Book accommodation").click()
330        self.assertFalse('Activation Code:' in self.browser.contents)
331        self.browser.getControl("Create bed ticket").click()
332        # Bed is randomly selected but, since there is only
333        # one bed for this student, we know that
334        self.assertMatches('...Hall 1, Block A, Room 101, Bed A...',
335                           self.browser.contents)
336        return
Note: See TracBrowser for help on using the repository browser.