source: main/waeup.aaue/trunk/src/waeup/aaue/students/tests/test_browser.py @ 10222

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

Customize maxCredits.

  • Property svn:keywords set to Id
File size: 18.4 KB
Line 
1## $Id: test_browser.py 10051 2013-03-28 17:03:36Z 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
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 StudentsFullSetup
28from waeup.kofa.students.accommodation import BedTicket
29from waeup.kofa.testing import FunctionalTestCase
30from waeup.kofa.interfaces import (
31    IExtFileStore, IFileStoreNameChooser)
32from waeup.kofa.students.interfaces import IStudentsUtils
33from waeup.aaue.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 setUp(self):
74        super(StudentUITests, self).setUp()
75
76        bedticket = BedTicket()
77        bedticket.booking_session = 2004
78        bedticket.bed_type = u'any bed type'
79        bedticket.bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
80        bedticket.bed_coordinates = u'My bed coordinates'
81        self.student['accommodation'].addBedTicket(bedticket)
82
83    def test_manage_payments(self):
84        # Add missing configuration data
85        self.app['configuration']['2004'].gown_fee = 150.0
86        self.app['configuration']['2004'].transfer_fee = 90.0
87        self.app['configuration']['2004'].booking_fee = 150.0
88        self.app['configuration']['2004'].maint_fee = 180.0
89
90        # Managers can add online payment tickets
91        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
92        self.browser.open(self.payments_path)
93        self.browser.getLink("Add current session payment ticket").click()
94        self.browser.getControl(name="form.p_category").value = ['schoolfee']
95        self.browser.getControl("Create ticket").click()
96        self.assertMatches('...Wrong state...',
97                           self.browser.contents)
98        IWorkflowState(self.student).setState('cleared')
99        self.browser.open(self.payments_path + '/addop')
100        self.browser.getControl("Create ticket").click()
101        self.assertMatches('...Amount could not be determined...',
102                           self.browser.contents)
103        self.app['configuration']['2004'].school_fee = 6666.0
104        self.browser.getControl(name="form.p_category").value = ['schoolfee']
105        self.browser.getControl("Create ticket").click()
106        self.assertMatches('...ticket created...',
107                           self.browser.contents)
108        ctrl = self.browser.getControl(name='val_id')
109        value = ctrl.options[0]
110        self.browser.getLink(value).click()
111        self.assertMatches('...Amount Authorized...',
112                           self.browser.contents)
113        # Managers can open payment slip
114        self.browser.getLink("Download payment slip").click()
115        self.assertEqual(self.browser.headers['Status'], '200 Ok')
116        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
117        # Set ticket paid
118        ticket = self.student['payments'].items()[0][1]
119        ticket.p_state = 'paid'
120        self.browser.open(self.payments_path + '/addop')
121        self.browser.getControl(name="form.p_category").value = ['schoolfee']
122        self.browser.getControl("Create ticket").click()
123        self.assertMatches('...This type of payment has already been made...',
124                           self.browser.contents)
125        self.browser.open(self.payments_path + '/addop')
126        # Also the other payments can be made
127        self.browser.getControl(name="form.p_category").value = ['gown']
128        self.browser.getControl("Create ticket").click()
129        self.assertMatches('...ticket created...',
130                           self.browser.contents)
131        self.browser.open(self.payments_path + '/addop')
132        self.browser.getControl(name="form.p_category").value = ['transfer']
133        self.browser.getControl("Create ticket").click()
134        self.assertMatches('...ticket created...',
135                           self.browser.contents)
136        self.browser.open(self.payments_path + '/addop')
137        self.browser.getControl(
138            name="form.p_category").value = ['bed_allocation']
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 = ['hostel_maintenance']
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(name="form.p_category").value = ['clearance']
150        self.browser.getControl("Create ticket").click()
151        self.assertMatches('...ticket created...',
152                           self.browser.contents)
153
154
155    def deactivated_test_for_instalment_payments(self):
156        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
157        self.browser.open(self.payments_path)
158        self.browser.open(self.payments_path + '/addop')
159        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
160        self.browser.getControl("Create ticket").click()
161        self.assertMatches('...ticket created...',
162                           self.browser.contents)
163        # We can't add the 2nd instalment ticket because the
164        # first one has not yet been approved.
165        self.browser.open(self.payments_path + '/addop')
166        self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
167        self.browser.getControl("Create ticket").click()
168        self.assertMatches('...1st school fee instalment has not yet been paid...',
169                           self.browser.contents)
170        # Ok, then we approve the first instalment ...
171        self.browser.open(self.payments_path)
172        ctrl = self.browser.getControl(name='val_id')
173        p_id = ctrl.options[0]
174        self.browser.open(self.payments_path + '/' + p_id + '/approve')
175        # ... add the second instalment ...
176        self.browser.open(self.payments_path + '/addop')
177        self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
178        self.browser.getControl("Create ticket").click()
179        self.assertMatches('...ticket created...',
180                           self.browser.contents)
181        # ... approve the second instalment ...
182        ctrl = self.browser.getControl(name='val_id')
183        p_id = ctrl.options[1]
184        self.browser.open(self.payments_path + '/' + p_id + '/approve')
185        # ... and finally add the 1st instalment for the next session
186        # provided that student is returning.
187        IWorkflowState(self.student).setState('returning')
188        self.browser.open(self.payments_path + '/addop')
189        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
190        self.browser.getControl("Create ticket").click()
191        self.assertMatches('...Session configuration object is not...',
192                           self.browser.contents)
193        # Uups, we forgot to add a session configuration for next session
194        configuration = createObject('waeup.SessionConfiguration')
195        configuration.academic_session = 2005
196        self.app['configuration'].addSessionConfiguration(configuration)
197        self.app['configuration']['2005'].school_base = 7777.0
198        self.browser.open(self.payments_path + '/addop')
199        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
200        self.browser.getControl("Create ticket").click()
201        self.assertMatches('...ticket created...',
202                           self.browser.contents)
203        # If the session configuration doesn't exist an error message will
204        # be shown. No other requirement is being checked.
205        del self.app['configuration']['2004']
206        self.browser.open(self.payments_path)
207        self.browser.getLink("Add current session payment ticket").click()
208        self.browser.getControl("Create ticket").click()
209        self.assertMatches('...Session configuration object is not...',
210                           self.browser.contents)
211
212    def test_student_payments(self):
213        # Login
214        IWorkflowState(self.student).setState('returning')
215        self.browser.open(self.login_path)
216        self.browser.getControl(name="form.login").value = self.student_id
217        self.browser.getControl(name="form.password").value = 'spwd'
218        self.browser.getControl("Login").click()
219        self.browser.open(self.student_path + '/payments')
220        self.assertTrue(
221          'Add current session payment ticket' in self.browser.contents)
222        self.assertFalse(
223          'Add previous session payment ticket' in self.browser.contents)
224        return
225
226    def test_get_returning_data(self):
227        # Student is in level 100, session 2004 with verdict A
228        utils = getUtility(IStudentsUtils)
229        self.assertEqual(utils.getReturningData(self.student),(2005, 200))
230        self.student['studycourse'].current_verdict = 'C'
231        self.assertEqual(utils.getReturningData(self.student),(2005, 110))
232        self.student['studycourse'].current_verdict = 'D'
233        self.assertEqual(utils.getReturningData(self.student),(2005, 100))
234        return
235
236    def test_set_payment_details(self):
237        self.app['configuration']['2004'].gown_fee = 150.0
238        self.app['configuration']['2004'].transfer_fee = 90.0
239        self.app['configuration']['2004'].booking_fee = 150.0
240        self.app['configuration']['2004'].maint_fee = 180.0
241        self.app['configuration']['2004'].clearance_fee = 1234.0
242        self.app['configuration']['2004'].school_fee = 6666.0
243        utils = getUtility(IStudentsUtils)
244
245        configuration = createObject('waeup.SessionConfiguration')
246        configuration.academic_session = 2005
247        self.app['configuration'].addSessionConfiguration(configuration)
248        self.app['configuration']['2005'].school_fee = 7777.0
249
250        error, payment = utils.setPaymentDetails('schoolfee',self.student)
251        self.assertEqual(payment, None)
252        self.assertEqual(error, u'Wrong state.')
253
254        IWorkflowState(self.student).setState('cleared')
255        error, payment = utils.setPaymentDetails('schoolfee',self.student)
256        self.assertEqual(payment.p_level, 100)
257        self.assertEqual(payment.p_session, 2004)
258        self.assertEqual(payment.amount_auth, 6666.0)
259        self.assertEqual(payment.p_item, u'CERT1')
260        self.assertEqual(error, None)
261
262        # Add penalty fee ...
263        # ... for cleared
264        self.app['configuration']['2004'].penalty_ug = 99.0
265        # ... for returning
266        self.app['configuration']['2005'].penalty_ug = 88.0
267        error, payment = utils.setPaymentDetails('schoolfee',self.student)
268        self.assertEqual(payment.amount_auth, 6765.0)
269        IWorkflowState(self.student).setState('returning')
270        error, payment = utils.setPaymentDetails('schoolfee',self.student)
271        self.assertEqual(payment.p_level, 200)
272        self.assertEqual(payment.p_session, 2005)
273        self.assertEqual(payment.amount_auth, 7865.0)
274        self.assertEqual(payment.p_item, u'CERT1')
275        self.assertEqual(error, None)
276
277        error, payment = utils.setPaymentDetails('clearance',self.student)
278        self.assertEqual(payment.p_level, 100)
279        self.assertEqual(payment.p_session, 2004)
280        self.assertEqual(payment.amount_auth, 1234.0)
281        self.assertEqual(payment.p_item, u'CERT1')
282        self.assertEqual(error, None)
283
284        error, payment = utils.setPaymentDetails('gown',self.student)
285        self.assertEqual(payment.p_level, 100)
286        self.assertEqual(payment.p_session, 2004)
287        self.assertEqual(payment.amount_auth, 150.0)
288        self.assertEqual(payment.p_item, u'')
289        self.assertEqual(error, None)
290
291        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
292        self.assertEqual(payment.p_level, 100)
293        self.assertEqual(payment.p_session, 2004)
294        self.assertEqual(payment.amount_auth, 180.0)
295        self.assertEqual(payment.p_item, u'')
296        self.assertEqual(error, None)
297
298        error, payment = utils.setPaymentDetails('bed_allocation',self.student)
299        self.assertEqual(payment.p_level, 100)
300        self.assertEqual(payment.p_session, 2004)
301        self.assertEqual(payment.amount_auth, 150.0)
302        self.assertEqual(payment.p_item, u'')
303        self.assertEqual(error, None)
304
305        error, payment = utils.setPaymentDetails('transfer',self.student)
306        self.assertEqual(payment.p_level, 100)
307        self.assertEqual(payment.p_session, 2004)
308        self.assertEqual(payment.amount_auth, 90.0)
309        self.assertEqual(payment.p_item, u'')
310        self.assertEqual(error, None)
311
312        error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100)
313        self.assertEqual(error, u'Previous session payment not yet implemented.')
314        return
315
316    def deactivated_test_student_course_registration(self):
317
318        # Add more courses
319        self.course2 = createObject('waeup.Course')
320        self.course2.code = 'COURSE2'
321        self.course2.semester = 2
322        self.course2.credits = 10
323        self.course2.passmark = 40
324        self.app['faculties']['fac1']['dep1'].courses.addCourse(
325            self.course2)
326        self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCertCourse(
327            self.course2, level=100)
328        self.course3 = createObject('waeup.Course')
329        self.course3.code = 'COURSE3'
330        self.course3.semester = 3
331        self.course3.credits = 10
332        self.course3.passmark = 40
333        self.app['faculties']['fac1']['dep1'].courses.addCourse(
334            self.course3)
335        self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCertCourse(
336            self.course3, level=100)
337
338        # Login as student
339        self.browser.open(self.login_path)
340        IWorkflowState(self.student).setState('school fee paid')
341        self.browser.open(self.login_path)
342        self.browser.getControl(name="form.login").value = self.student_id
343        self.browser.getControl(name="form.password").value = 'spwd'
344        self.browser.getControl("Login").click()
345        # Students can add the current study level
346        self.browser.getLink("Study Course").click()
347        self.browser.getLink("Add course list").click()
348        self.assertMatches('...Add current level 100 (Year 1)...',
349                           self.browser.contents)
350        self.browser.getControl("Create course list now").click()
351        # Student has not paid second instalment, therefore a level
352        # with two course ticket was created (semester 1 and combined)
353        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 2)
354        self.browser.getLink("100").click()
355        self.browser.getLink("Edit course list").click()
356        self.browser.getControl("Add course ticket").click()
357        # Student can't add second semester course
358        self.assertTrue('<option value="COURSE1">' in self.browser.contents)
359        self.assertTrue('<option value="COURSE3">' in self.browser.contents)
360        self.assertFalse('<option value="COURSE2">' in self.browser.contents)
361
362        # Let's remove level and see what happens after 2nd instalment payment
363        del(self.student['studycourse']['100'])
364        payment2 = createObject('waeup.StudentOnlinePayment')
365        payment2.p_category = u'schoolfee_2'
366        payment2.p_session = self.student.current_session
367        self.student['payments']['anykey'] = payment2
368        self.browser.open(self.studycourse_path)
369        self.browser.getLink("Add course list").click()
370        self.browser.getControl("Create course list now").click()
371        # Still only 2 tickets have been created since payment ticket
372        # was not paid
373        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 2)
374        payment2.p_state = u'paid'
375        del(self.student['studycourse']['100'])
376        self.browser.open(self.studycourse_path)
377        self.browser.getLink("Add course list").click()
378        self.browser.getControl("Create course list now").click()
379        # Now 2nd semester course has been added
380        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 3)
381        # Student can add second semester course
382        self.browser.getLink("100").click()
383        self.browser.getLink("Edit course list").click()
384        self.browser.getControl("Add course ticket").click()
385        self.assertTrue('<option value="COURSE1">' in self.browser.contents)
386        self.assertTrue('<option value="COURSE2">' in self.browser.contents)
387        self.assertTrue('<option value="COURSE3">' in self.browser.contents)
388        return
389
390    def test_maxCredits(self):
391        dummy = object()
392        utils = getUtility(IStudentsUtils)
393        self.assertEqual(utils.maxCredits(dummy), 48)
394        return
Note: See TracBrowser for help on using the repository browser.