source: main/waeup.fceokene/trunk/src/waeup/fceokene/students/tests/test_browser.py @ 9612

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

Calculate hostel maintenance fee.

  • Property svn:keywords set to Id
File size: 15.3 KB
Line 
1## $Id: test_browser.py 9612 2012-11-11 06:07:51Z 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.fceokene.testing import FunctionalLayer
35
36
37class StudentProcessorTest(FunctionalTestCase):
38    """Perform some batching tests.
39    """
40
41    layer = FunctionalLayer
42
43    def setUp(self):
44        super(StudentProcessorTest, self).setUp()
45        # Setup a sample site for each test
46        app = University()
47        self.dc_root = tempfile.mkdtemp()
48        app['datacenter'].setStoragePath(self.dc_root)
49
50        # Prepopulate the ZODB...
51        self.getRootFolder()['app'] = app
52        # we add the site immediately after creation to the
53        # ZODB. Catalogs and other local utilities are not setup
54        # before that step.
55        self.app = self.getRootFolder()['app']
56        # Set site here. Some of the following setup code might need
57        # to access grok.getSite() and should get our new app then
58        setSite(app)
59
60
61    def tearDown(self):
62        super(StudentProcessorTest, self).tearDown()
63        shutil.rmtree(self.workdir)
64        shutil.rmtree(self.dc_root)
65        clearSite()
66        return
67
68class StudentUITests(StudentsFullSetup):
69    """Tests for customized student class views and pages
70    """
71
72    layer = FunctionalLayer
73
74    def setUp(self):
75        super(StudentUITests, self).setUp()
76
77        bedticket = BedTicket()
78        bedticket.booking_session = 2004
79        bedticket.bed_type = u'any bed type'
80        bedticket.bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
81        bedticket.bed_coordinates = u'My bed coordinates'
82        self.student['accommodation'].addBedTicket(bedticket)
83
84    def test_manage_payments(self):
85        # Add missing configuration data
86        self.app['configuration']['2004'].gown_fee = 150.0
87        self.app['configuration']['2004'].transfer_fee = 90.0
88        self.app['configuration']['2004'].clearance_fee = 120.0
89        self.app['configuration']['2004'].booking_fee = 150.0
90        self.app['configuration']['2004'].maint_fee = 180.0
91
92        # Managers can add online payment tickets
93        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
94        self.browser.open(self.payments_path)
95        self.browser.getLink("Add current session payment ticket").click()
96        self.browser.getControl("Create ticket").click()
97        self.assertMatches('...Amount could not be determined...',
98                           self.browser.contents)
99        IWorkflowState(self.student).setState('cleared')
100        self.browser.open(self.payments_path + '/addop')
101        self.browser.getControl("Create ticket").click()
102        self.assertMatches('...ticket created...',
103                           self.browser.contents)
104        ctrl = self.browser.getControl(name='val_id')
105        value = ctrl.options[0]
106        self.browser.getLink(value).click()
107        self.assertMatches('...Amount Authorized...',
108                           self.browser.contents)
109        # Managers can open payment slip
110        self.browser.getLink("Download payment slip").click()
111        self.assertEqual(self.browser.headers['Status'], '200 Ok')
112        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
113        # Set ticket paid
114        ticket = self.student['payments'].items()[0][1]
115        ticket.p_state = 'paid'
116        self.browser.open(self.payments_path + '/addop')
117        self.browser.getControl("Create ticket").click()
118        self.assertMatches('...This type of payment has already been made...',
119                           self.browser.contents)
120        # Remove all payments so that we can add a school fee payment again
121        keys = [i for i in self.student['payments'].keys()]
122        for payment in keys:
123            del self.student['payments'][payment]
124        self.browser.open(self.payments_path + '/addop')
125        self.browser.getControl("Create ticket").click()
126        self.assertMatches('...ticket created...',
127                           self.browser.contents)
128        self.browser.open(self.payments_path + '/addop')
129        self.browser.getControl(name="form.p_category").value = ['gown']
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(name="form.p_category").value = ['transfer']
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(
140            name="form.p_category").value = ['bed_allocation']
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(
146            name="form.p_category").value = ['hostel_maintenance']
147        self.browser.getControl("Create ticket").click()
148        self.assertMatches('...ticket created...',
149                           self.browser.contents)
150        self.browser.open(self.payments_path + '/addop')
151        self.browser.getControl(name="form.p_category").value = ['clearance']
152        self.browser.getControl("Create ticket").click()
153        self.assertMatches('...ticket created...',
154                           self.browser.contents)
155        self.browser.open(self.payments_path + '/addop')
156        self.browser.getControl(name="form.p_category").value = ['schoolfee']
157        self.browser.getControl("Create ticket").click()
158        self.assertMatches('...ticket created...',
159                           self.browser.contents)
160        # In state returning we can add a new school fee ticket since
161        # p_session and p_level is different
162        IWorkflowState(self.student).setState('returning')
163        self.browser.open(self.payments_path + '/addop')
164        self.browser.getControl(name="form.p_category").value = ['schoolfee']
165        self.browser.getControl("Create ticket").click()
166        # Uups, we forgot to add a session configuration for next session
167        self.assertTrue('Session configuration object is not available.'
168            in self.browser.contents)
169        configuration = createObject('waeup.SessionConfiguration')
170        configuration.academic_session = 2005
171        self.app['configuration'].addSessionConfiguration(configuration)
172        self.browser.getControl("Create ticket").click()
173        self.assertMatches('...ticket created...',
174                           self.browser.contents)
175
176        # In state admitted school fee can't be determined
177        IWorkflowState(self.student).setState('admitted')
178        self.browser.open(self.payments_path + '/addop')
179        self.browser.getControl(name="form.p_category").value = ['schoolfee']
180        self.browser.getControl("Create ticket").click()
181        self.assertMatches('...Amount could not be determined...',
182                           self.browser.contents)
183
184    def test_student_payments(self):
185        # Login
186        IWorkflowState(self.student).setState('returning')
187        self.browser.open(self.login_path)
188        self.browser.getControl(name="form.login").value = self.student_id
189        self.browser.getControl(name="form.password").value = 'spwd'
190        self.browser.getControl("Login").click()
191        self.browser.open(self.student_path + '/payments')
192        self.assertTrue(
193          'Add current session payment ticket' in self.browser.contents)
194        self.assertFalse(
195          'Add previous session payment ticket' in self.browser.contents)
196        return
197
198    def test_get_returning_data(self):
199        # Student is in level 100, session 2004 with verdict A
200        utils = getUtility(IStudentsUtils)
201        self.assertEqual(utils.getReturningData(self.student),(2005, 200))
202        self.student['studycourse'].current_verdict = 'C'
203        self.assertEqual(utils.getReturningData(self.student),(2005, 110))
204        self.student['studycourse'].current_verdict = 'D'
205        self.assertEqual(utils.getReturningData(self.student),(2005, 100))
206        return
207
208    def test_set_payment_details(self):
209        self.app['configuration']['2004'].gown_fee = 150.0
210        self.app['configuration']['2004'].transfer_fee = 90.0
211        self.app['configuration']['2004'].booking_fee = 150.0
212        self.app['configuration']['2004'].maint_fee = 180.0
213        self.app['configuration']['2004'].clearance_fee = 120.0
214        utils = getUtility(IStudentsUtils)
215
216        error, payment = utils.setPaymentDetails('schoolfee',self.student)
217        self.assertEqual(payment, None)
218        self.assertEqual(error, u'Amount could not be determined.')
219
220        IWorkflowState(self.student).setState('cleared')
221        error, payment = utils.setPaymentDetails('schoolfee',self.student)
222        self.assertEqual(payment.p_level, 100)
223        self.assertEqual(payment.p_session, 2004)
224        self.assertEqual(payment.amount_auth, 12495.0)
225        self.assertEqual(payment.p_item, u'CERT1')
226        self.assertEqual(error, None)
227
228        IWorkflowState(self.student).setState('returning')
229        error, payment = utils.setPaymentDetails('schoolfee',self.student)
230        self.assertEqual('Session configuration object is not available.', error)
231        configuration = createObject('waeup.SessionConfiguration')
232        configuration.academic_session = 2005
233        self.app['configuration'].addSessionConfiguration(configuration)
234        error, payment = utils.setPaymentDetails('schoolfee',self.student)
235        self.assertEqual(payment.p_level, 200)
236        self.assertEqual(payment.p_session, 2005)
237        self.assertEqual(payment.amount_auth, 11545.0)
238        self.assertEqual(payment.p_item, u'CERT1')
239        self.assertEqual(error, None)
240
241        error, payment = utils.setPaymentDetails('clearance',self.student)
242        self.assertEqual(payment.p_level, 100)
243        self.assertEqual(payment.p_session, 2004)
244        self.assertEqual(payment.amount_auth, 120.0)
245        self.assertEqual(payment.p_item, u'CERT1')
246        self.assertEqual(error, None)
247
248        error, payment = utils.setPaymentDetails('gown',self.student)
249        self.assertEqual(payment.p_level, 100)
250        self.assertEqual(payment.p_session, 2004)
251        self.assertEqual(payment.amount_auth, 150.0)
252        self.assertEqual(payment.p_item, u'')
253        self.assertEqual(error, None)
254
255        self.student['studycourse'].current_session = 2005
256        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
257        self.assertEqual(payment, None)
258        self.assertEqual(error, 'You have not yet booked accommodation.')
259        self.student['studycourse'].current_session = 2004
260
261        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
262        self.assertEqual(payment.p_level, 100)
263        self.assertEqual(payment.p_session, 2004)
264        self.assertEqual(payment.amount_auth, 4000.0)
265        self.assertEqual(payment.p_item, u'My bed coordinates')
266        self.assertEqual(error, None)
267
268        self.certificate.study_mode = u'ug_sw'
269        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
270        self.assertEqual(payment.p_level, 100)
271        self.assertEqual(payment.p_session, 2004)
272        self.assertEqual(payment.amount_auth, 2500.0)
273        self.assertEqual(payment.p_item, u'My bed coordinates')
274        self.assertEqual(error, None)
275
276        error, payment = utils.setPaymentDetails('bed_allocation',self.student)
277        self.assertEqual(payment.p_level, 100)
278        self.assertEqual(payment.p_session, 2004)
279        self.assertEqual(payment.amount_auth, 150.0)
280        self.assertEqual(payment.p_item, u'')
281        self.assertEqual(error, None)
282
283        error, payment = utils.setPaymentDetails('transfer',self.student)
284        self.assertEqual(payment.p_level, 100)
285        self.assertEqual(payment.p_session, 2004)
286        self.assertEqual(payment.amount_auth, 90.0)
287        self.assertEqual(payment.p_item, u'')
288        self.assertEqual(error, None)
289
290        error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100)
291        self.assertEqual(error, u'Previous session payment not yet implemented.')
292        return
293
294    def test_student_start_clearance(self):
295        self.browser.open(self.login_path)
296        self.browser.getControl(name="form.login").value = self.student_id
297        self.browser.getControl(name="form.password").value = 'spwd'
298        self.browser.getControl("Login").click()
299
300        IWorkflowInfo(self.student).fireTransition('admit')
301        self.browser.open(self.student_path + '/change_portrait')
302        image = open(SAMPLE_IMAGE, 'rb')
303        ctrl = self.browser.getControl(name='passportuploadedit')
304        file_ctrl = ctrl.mech_control
305        file_ctrl.add_file(image, filename='my_photo.jpg')
306        self.browser.getControl(
307            name='upload_passportuploadedit').click()
308        self.browser.open(self.student_path + '/start_clearance')
309        # In Okene the students can just start clearance without entering
310        # an activation code.
311        self.browser.getControl("Start clearance now").click()
312        self.assertMatches('...Clearance process has been started...',
313                           self.browser.contents)
314
315    def test_student_accommodation(self):
316        del self.student['accommodation']['2004']
317        # Login
318        self.browser.open(self.login_path)
319        self.browser.getControl(name="form.login").value = self.student_id
320        self.browser.getControl(name="form.password").value = 'spwd'
321        self.browser.getControl("Login").click()
322
323        # Students can book accommodation without AC ...
324        self.browser.open(self.acco_path)
325        IWorkflowInfo(self.student).fireTransition('admit')
326        self.browser.getLink("Book accommodation").click()
327        self.assertFalse('Activation Code:' in self.browser.contents)
328        self.browser.getControl("Create bed ticket").click()
329        # Bed is randomly selected but, since there is only
330        # one bed for this student, we know that
331        self.assertMatches('...Hall 1, Block A, Room 101, Bed A...',
332                           self.browser.contents)
333        return
Note: See TracBrowser for help on using the repository browser.