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

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

Log payment category.

Adjust to previous revisions.

  • Property svn:keywords set to Id
File size: 13.7 KB
Line 
1## $Id: test_browser.py 9434 2012-10-26 21:47:44Z 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.getControl("Add online 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        self.assertMatches('...ticket created...',
167                           self.browser.contents)
168        # In state admitted school fee can't be determined
169        IWorkflowState(self.student).setState('admitted')
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        self.assertMatches('...Amount could not be determined...',
174                           self.browser.contents)
175
176        # If the session configuration doesn't exist an error message will
177        # be shown. No other requirement is being checked.
178        del self.app['configuration']['2004']
179        self.browser.open(self.payments_path)
180        self.browser.getControl("Add online payment ticket").click()
181        self.browser.getControl("Create ticket").click()
182        self.assertMatches('...Session configuration object is not...',
183                           self.browser.contents)
184
185    def test_get_returning_data(self):
186        # Student is in level 100, session 2004 with verdict A
187        utils = getUtility(IStudentsUtils)
188        self.assertEqual(utils.getReturningData(self.student),(2005, 200))
189        self.student['studycourse'].current_verdict = 'C'
190        self.assertEqual(utils.getReturningData(self.student),(2005, 110))
191        self.student['studycourse'].current_verdict = 'D'
192        self.assertEqual(utils.getReturningData(self.student),(2005, 100))
193        return
194
195    def test_set_payment_details(self):
196        self.app['configuration']['2004'].gown_fee = 150.0
197        self.app['configuration']['2004'].transfer_fee = 90.0
198        self.app['configuration']['2004'].booking_fee = 150.0
199        self.app['configuration']['2004'].maint_fee = 180.0
200        self.app['configuration']['2004'].clearance_fee = 120.0
201        utils = getUtility(IStudentsUtils)
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, 12495.0)
212        self.assertEqual(payment.p_item, u'CERT1')
213        self.assertEqual(error, None)
214
215        IWorkflowState(self.student).setState('returning')
216        error, payment = utils.setPaymentDetails('schoolfee',self.student)
217        self.assertEqual(payment.p_level, 200)
218        self.assertEqual(payment.p_session, 2005)
219        self.assertEqual(payment.amount_auth, 11545.0)
220        self.assertEqual(payment.p_item, u'CERT1')
221        self.assertEqual(error, None)
222
223        error, payment = utils.setPaymentDetails('clearance',self.student)
224        self.assertEqual(payment.p_level, 100)
225        self.assertEqual(payment.p_session, 2004)
226        self.assertEqual(payment.amount_auth, 120.0)
227        self.assertEqual(payment.p_item, u'CERT1')
228        self.assertEqual(error, None)
229
230        error, payment = utils.setPaymentDetails('gown',self.student)
231        self.assertEqual(payment.p_level, 100)
232        self.assertEqual(payment.p_session, 2004)
233        self.assertEqual(payment.amount_auth, 150.0)
234        self.assertEqual(payment.p_item, u'')
235        self.assertEqual(error, None)
236
237        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
238        self.assertEqual(payment.p_level, 100)
239        self.assertEqual(payment.p_session, 2004)
240        self.assertEqual(payment.amount_auth, 180.0)
241        self.assertEqual(payment.p_item, u'')
242        self.assertEqual(error, None)
243
244        error, payment = utils.setPaymentDetails('bed_allocation',self.student)
245        self.assertEqual(payment.p_level, 100)
246        self.assertEqual(payment.p_session, 2004)
247        self.assertEqual(payment.amount_auth, 150.0)
248        self.assertEqual(payment.p_item, u'')
249        self.assertEqual(error, None)
250
251        error, payment = utils.setPaymentDetails('transfer',self.student)
252        self.assertEqual(payment.p_level, 100)
253        self.assertEqual(payment.p_session, 2004)
254        self.assertEqual(payment.amount_auth, 90.0)
255        self.assertEqual(payment.p_item, u'')
256        self.assertEqual(error, None)
257
258        error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100)
259        self.assertEqual(error, u'Previous session payment not yet implemented.')
260        return
261
262    def test_student_start_clearance(self):
263        self.browser.open(self.login_path)
264        self.browser.getControl(name="form.login").value = self.student_id
265        self.browser.getControl(name="form.password").value = 'spwd'
266        self.browser.getControl("Login").click()
267
268        IWorkflowInfo(self.student).fireTransition('admit')
269        self.browser.open(self.student_path + '/change_portrait')
270        image = open(SAMPLE_IMAGE, 'rb')
271        ctrl = self.browser.getControl(name='passportuploadedit')
272        file_ctrl = ctrl.mech_control
273        file_ctrl.add_file(image, filename='my_photo.jpg')
274        self.browser.getControl(
275            name='upload_passportuploadedit').click()
276        self.browser.open(self.student_path + '/start_clearance')
277        # In Okene the students can just start clearance without entering
278        # an activation code.
279        self.browser.getControl("Start clearance now").click()
280        self.assertMatches('...Clearance process has been started...',
281                           self.browser.contents)
282
283    def test_student_accommodation(self):
284        del self.student['accommodation']['2004']
285        # Login
286        self.browser.open(self.login_path)
287        self.browser.getControl(name="form.login").value = self.student_id
288        self.browser.getControl(name="form.password").value = 'spwd'
289        self.browser.getControl("Login").click()
290
291        # Students can book accommodation without AC ...
292        self.browser.open(self.acco_path)
293        IWorkflowInfo(self.student).fireTransition('admit')
294        self.browser.getLink("Book accommodation").click()
295        self.assertFalse('Activation Code:' in self.browser.contents)
296        self.browser.getControl("Create bed ticket").click()
297        # Bed is randomly selected but, since there is only
298        # one bed for this student, we know that
299        self.assertMatches('...Hall 1, Block A, Room 101, Bed A...',
300                           self.browser.contents)
301        return
Note: See TracBrowser for help on using the repository browser.