1 | ## $Id: test_browser.py 10520 2013-08-21 16:43:41Z 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 | ## |
---|
18 | import os |
---|
19 | import shutil |
---|
20 | import tempfile |
---|
21 | from StringIO import StringIO |
---|
22 | from hurry.workflow.interfaces import IWorkflowState, IWorkflowInfo |
---|
23 | from zope.component.hooks import setSite, clearSite |
---|
24 | from zope.component import getUtility, createObject |
---|
25 | from zope.interface import verify |
---|
26 | from waeup.kofa.app import University |
---|
27 | from waeup.kofa.students.tests.test_browser import ( |
---|
28 | StudentsFullSetup, SAMPLE_IMAGE) |
---|
29 | from waeup.kofa.students.accommodation import BedTicket |
---|
30 | from waeup.kofa.testing import FunctionalTestCase |
---|
31 | from waeup.kofa.interfaces import ( |
---|
32 | IExtFileStore, IFileStoreNameChooser) |
---|
33 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
34 | from waeup.fceokene.testing import FunctionalLayer |
---|
35 | |
---|
36 | |
---|
37 | class 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 | |
---|
68 | class 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(name="form.p_category").value = ['schoolfee'] |
---|
97 | self.browser.getControl("Create ticket").click() |
---|
98 | self.assertMatches('...Wrong state...', |
---|
99 | self.browser.contents) |
---|
100 | IWorkflowState(self.student).setState('cleared') |
---|
101 | self.browser.open(self.payments_path + '/addop') |
---|
102 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
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(name="form.p_category").value = ['schoolfee'] |
---|
120 | self.browser.getControl("Create ticket").click() |
---|
121 | self.assertMatches('...This type of payment has already been made...', |
---|
122 | self.browser.contents) |
---|
123 | # Remove all payments so that we can add a school fee payment again |
---|
124 | keys = [i for i in self.student['payments'].keys()] |
---|
125 | for payment in keys: |
---|
126 | del self.student['payments'][payment] |
---|
127 | self.browser.open(self.payments_path + '/addop') |
---|
128 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
129 | self.browser.getControl("Create ticket").click() |
---|
130 | self.assertMatches('...ticket created...', |
---|
131 | self.browser.contents) |
---|
132 | self.browser.open(self.payments_path + '/addop') |
---|
133 | self.browser.getControl(name="form.p_category").value = ['gown'] |
---|
134 | self.browser.getControl("Create ticket").click() |
---|
135 | self.assertMatches('...ticket created...', |
---|
136 | self.browser.contents) |
---|
137 | self.browser.open(self.payments_path + '/addop') |
---|
138 | self.browser.getControl(name="form.p_category").value = ['transfer'] |
---|
139 | self.browser.getControl("Create ticket").click() |
---|
140 | self.assertMatches('...ticket created...', |
---|
141 | self.browser.contents) |
---|
142 | self.browser.open(self.payments_path + '/addop') |
---|
143 | self.browser.getControl( |
---|
144 | name="form.p_category").value = ['bed_allocation'] |
---|
145 | self.browser.getControl("Create ticket").click() |
---|
146 | self.assertMatches('...ticket created...', |
---|
147 | self.browser.contents) |
---|
148 | self.browser.open(self.payments_path + '/addop') |
---|
149 | self.browser.getControl( |
---|
150 | name="form.p_category").value = ['hostel_maintenance'] |
---|
151 | self.browser.getControl("Create ticket").click() |
---|
152 | self.assertMatches('...ticket created...', |
---|
153 | self.browser.contents) |
---|
154 | self.browser.open(self.payments_path + '/addop') |
---|
155 | self.browser.getControl(name="form.p_category").value = ['clearance'] |
---|
156 | self.browser.getControl("Create ticket").click() |
---|
157 | self.assertMatches('...ticket created...', |
---|
158 | self.browser.contents) |
---|
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('...ticket created...', |
---|
163 | self.browser.contents) |
---|
164 | # In state returning we can add a new school fee ticket since |
---|
165 | # p_session and p_level is different |
---|
166 | IWorkflowState(self.student).setState('returning') |
---|
167 | self.browser.open(self.payments_path + '/addop') |
---|
168 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
169 | self.browser.getControl("Create ticket").click() |
---|
170 | # Uups, we forgot to add a session configuration for next session |
---|
171 | self.assertTrue('Session configuration object is not available.' |
---|
172 | in self.browser.contents) |
---|
173 | configuration = createObject('waeup.SessionConfiguration') |
---|
174 | configuration.academic_session = 2005 |
---|
175 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
176 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
177 | self.browser.getControl("Create ticket").click() |
---|
178 | self.assertMatches('...ticket created...', |
---|
179 | self.browser.contents) |
---|
180 | |
---|
181 | # In state admitted school fee can't be determined |
---|
182 | IWorkflowState(self.student).setState('admitted') |
---|
183 | self.browser.open(self.payments_path + '/addop') |
---|
184 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
185 | self.browser.getControl("Create ticket").click() |
---|
186 | self.assertMatches('...Wrong state...', |
---|
187 | self.browser.contents) |
---|
188 | |
---|
189 | def test_student_payments(self): |
---|
190 | # Login |
---|
191 | IWorkflowState(self.student).setState('returning') |
---|
192 | self.browser.open(self.login_path) |
---|
193 | self.browser.getControl(name="form.login").value = self.student_id |
---|
194 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
195 | self.browser.getControl("Login").click() |
---|
196 | self.browser.open(self.student_path + '/payments') |
---|
197 | self.assertTrue( |
---|
198 | 'Add current session payment ticket' in self.browser.contents) |
---|
199 | self.assertFalse( |
---|
200 | 'Add previous session payment ticket' in self.browser.contents) |
---|
201 | return |
---|
202 | |
---|
203 | def test_get_returning_data(self): |
---|
204 | # Student is in level 100, session 2004 with verdict A |
---|
205 | utils = getUtility(IStudentsUtils) |
---|
206 | self.assertEqual(utils.getReturningData(self.student),(2005, 200)) |
---|
207 | self.student['studycourse'].current_verdict = 'C' |
---|
208 | self.assertEqual(utils.getReturningData(self.student),(2005, 110)) |
---|
209 | self.student['studycourse'].current_verdict = 'D' |
---|
210 | self.assertEqual(utils.getReturningData(self.student),(2005, 100)) |
---|
211 | self.student['studycourse'].current_verdict = 'O' |
---|
212 | self.assertEqual(utils.getReturningData(self.student),(2004, 110)) |
---|
213 | return |
---|
214 | |
---|
215 | def test_set_payment_details(self): |
---|
216 | self.app['configuration']['2004'].gown_fee = 150.0 |
---|
217 | self.app['configuration']['2004'].transfer_fee = 90.0 |
---|
218 | self.app['configuration']['2004'].booking_fee = 150.0 |
---|
219 | self.app['configuration']['2004'].maint_fee = 180.0 |
---|
220 | self.app['configuration']['2004'].clearance_fee = 120.0 |
---|
221 | utils = getUtility(IStudentsUtils) |
---|
222 | |
---|
223 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
224 | self.assertEqual(payment, None) |
---|
225 | self.assertEqual(error, u'Wrong state.') |
---|
226 | |
---|
227 | IWorkflowState(self.student).setState('cleared') |
---|
228 | self.certificate.study_mode = 'nce_ft' |
---|
229 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
230 | self.assertEqual(payment.p_level, 100) |
---|
231 | self.assertEqual(payment.p_session, 2004) |
---|
232 | self.assertEqual(payment.amount_auth, 12645.0) |
---|
233 | self.assertEqual(payment.p_item, u'CERT1') |
---|
234 | self.assertEqual(error, None) |
---|
235 | |
---|
236 | IWorkflowState(self.student).setState('returning') |
---|
237 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
238 | self.assertEqual('Session configuration object is not available.', error) |
---|
239 | configuration = createObject('waeup.SessionConfiguration') |
---|
240 | configuration.academic_session = 2005 |
---|
241 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
242 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
243 | self.assertEqual(payment.p_level, 200) |
---|
244 | self.assertEqual(payment.p_session, 2005) |
---|
245 | self.assertEqual(payment.amount_auth, 11695.0) |
---|
246 | self.assertEqual(payment.p_item, u'CERT1') |
---|
247 | self.assertEqual(error, None) |
---|
248 | |
---|
249 | # UG students pay 65800 |
---|
250 | self.certificate.study_mode = 'ug_ft' |
---|
251 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
252 | self.assertEqual(payment.amount_auth, 65800.0) |
---|
253 | self.assertEqual(error, None) |
---|
254 | |
---|
255 | # NCE student payment can be disabled by |
---|
256 | # setting the base school fee to -1 |
---|
257 | IWorkflowState(self.student).setState('returning') |
---|
258 | configuration = createObject('waeup.SessionConfiguration') |
---|
259 | self.app['configuration']['2004'].school_fee_base = -1.0 |
---|
260 | self.certificate.study_mode = 'nce_ft' |
---|
261 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
262 | self.assertEqual(error, u'School fee payment is disabled.') |
---|
263 | |
---|
264 | error, payment = utils.setPaymentDetails('clearance',self.student) |
---|
265 | self.assertEqual(payment.p_level, 100) |
---|
266 | self.assertEqual(payment.p_session, 2004) |
---|
267 | self.assertEqual(payment.amount_auth, 270.0) |
---|
268 | self.assertEqual(payment.p_item, u'CERT1') |
---|
269 | self.assertEqual(error, None) |
---|
270 | |
---|
271 | error, payment = utils.setPaymentDetails('gown',self.student) |
---|
272 | self.assertEqual(payment.p_level, 100) |
---|
273 | self.assertEqual(payment.p_session, 2004) |
---|
274 | self.assertEqual(payment.amount_auth, 300.0) |
---|
275 | self.assertEqual(payment.p_item, u'') |
---|
276 | self.assertEqual(error, None) |
---|
277 | |
---|
278 | self.student['studycourse'].current_session = 2005 |
---|
279 | error, payment = utils.setPaymentDetails('hostel_maintenance',self.student) |
---|
280 | self.assertEqual(payment, None) |
---|
281 | self.assertEqual(error, 'You have not yet booked accommodation.') |
---|
282 | self.student['studycourse'].current_session = 2004 |
---|
283 | |
---|
284 | error, payment = utils.setPaymentDetails('hostel_maintenance',self.student) |
---|
285 | self.assertEqual(payment.p_level, 100) |
---|
286 | self.assertEqual(payment.p_session, 2004) |
---|
287 | self.assertEqual(payment.amount_auth, 4150.0) |
---|
288 | self.assertEqual(payment.p_item, u'My bed coordinates') |
---|
289 | self.assertEqual(error, None) |
---|
290 | |
---|
291 | self.certificate.study_mode = u'nce_sw' |
---|
292 | error, payment = utils.setPaymentDetails('hostel_maintenance',self.student) |
---|
293 | self.assertEqual(payment.p_level, 100) |
---|
294 | self.assertEqual(payment.p_session, 2004) |
---|
295 | self.assertEqual(payment.amount_auth, 2650.0) |
---|
296 | self.assertEqual(payment.p_item, u'My bed coordinates') |
---|
297 | self.assertEqual(error, None) |
---|
298 | |
---|
299 | error, payment = utils.setPaymentDetails('bed_allocation',self.student) |
---|
300 | self.assertEqual(payment.p_level, 100) |
---|
301 | self.assertEqual(payment.p_session, 2004) |
---|
302 | self.assertEqual(payment.amount_auth, 300.0) |
---|
303 | self.assertEqual(payment.p_item, u'') |
---|
304 | self.assertEqual(error, None) |
---|
305 | |
---|
306 | error, payment = utils.setPaymentDetails('transfer',self.student) |
---|
307 | self.assertEqual(payment.p_level, 100) |
---|
308 | self.assertEqual(payment.p_session, 2004) |
---|
309 | self.assertEqual(payment.amount_auth, 240.0) |
---|
310 | self.assertEqual(payment.p_item, u'') |
---|
311 | self.assertEqual(error, None) |
---|
312 | |
---|
313 | error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100) |
---|
314 | self.assertEqual(error, u'Previous session payment not yet implemented.') |
---|
315 | return |
---|
316 | |
---|
317 | def test_student_start_clearance(self): |
---|
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 | IWorkflowInfo(self.student).fireTransition('admit') |
---|
324 | self.browser.open(self.student_path + '/change_portrait') |
---|
325 | image = open(SAMPLE_IMAGE, 'rb') |
---|
326 | ctrl = self.browser.getControl(name='passportuploadedit') |
---|
327 | file_ctrl = ctrl.mech_control |
---|
328 | file_ctrl.add_file(image, filename='my_photo.jpg') |
---|
329 | self.browser.getControl( |
---|
330 | name='upload_passportuploadedit').click() |
---|
331 | self.browser.open(self.student_path + '/start_clearance') |
---|
332 | # In Okene the ug students start clearance with activation code ... |
---|
333 | self.assertTrue('Activation Code:' in self.browser.contents) |
---|
334 | self.browser.getControl("Start clearance now").click() |
---|
335 | self.assertTrue('Activation code is invalid' in self.browser.contents) |
---|
336 | # ... and nce students without. |
---|
337 | self.certificate.study_mode = 'nce_ft' |
---|
338 | self.browser.open(self.student_path + '/start_clearance') |
---|
339 | self.assertFalse('Activation Code:' in self.browser.contents) |
---|
340 | self.browser.getControl("Start clearance now").click() |
---|
341 | self.assertTrue( |
---|
342 | 'Clearance process has been started' in self.browser.contents) |
---|
343 | |
---|
344 | def test_open_slips(self): |
---|
345 | # Managers can open clearance slip |
---|
346 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
347 | self.browser.open(self.student_path + '/view_clearance') |
---|
348 | self.browser.getLink("Download clearance slip").click() |
---|
349 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
350 | self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf') |
---|
351 | |
---|
352 | def test_student_accommodation(self): |
---|
353 | del self.student['accommodation']['2004'] |
---|
354 | # Login |
---|
355 | self.browser.open(self.login_path) |
---|
356 | self.browser.getControl(name="form.login").value = self.student_id |
---|
357 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
358 | self.browser.getControl("Login").click() |
---|
359 | |
---|
360 | # Students can book accommodation without AC ... |
---|
361 | self.browser.open(self.acco_path) |
---|
362 | IWorkflowInfo(self.student).fireTransition('admit') |
---|
363 | self.browser.getLink("Book accommodation").click() |
---|
364 | self.assertFalse('Activation Code:' in self.browser.contents) |
---|
365 | self.browser.getControl("Create bed ticket").click() |
---|
366 | # Bed is randomly selected but, since there is only |
---|
367 | # one bed for this student, we know that |
---|
368 | self.assertEqual(self.student['accommodation']['2004'].bed_coordinates, |
---|
369 | 'Hall 1, Block A, Room 101, Bed A (regular_male_fr)') |
---|
370 | self.assertEqual(self.student['accommodation']['2004'].display_coordinates, |
---|
371 | '(see payment slip)') |
---|
372 | # But the bed coordinates are hidden. |
---|
373 | self.assertFalse('Hall 1, Block A, Room 101, Bed A' |
---|
374 | in self.browser.contents) |
---|
375 | self.assertTrue('<td>(see payment slip)</td>' |
---|
376 | in self.browser.contents) |
---|
377 | return |
---|