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

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

Customize StartClearancePage?. In Okene the students can just start clearance without entering an activation code.

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