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

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

Apply Uli's new FeeTable? which is really a milestone.

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