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

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

Adjust to changes made in base package.

  • Property svn:keywords set to Id
File size: 18.1 KB
Line 
1## $Id: test_browser.py 9527 2012-11-04 20:12:59Z 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("Create ticket").click()
95        self.assertMatches('...Wrong state...',
96                           self.browser.contents)
97        IWorkflowState(self.student).setState('cleared')
98        self.browser.open(self.payments_path + '/addop')
99        self.browser.getControl("Create ticket").click()
100        self.assertMatches('...Amount could not be determined...',
101                           self.browser.contents)
102        self.app['configuration']['2004'].school_fee_base = 6666.0
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("Create ticket").click()
120        self.assertMatches('...This type of payment has already been made...',
121                           self.browser.contents)
122        self.browser.open(self.payments_path + '/addop')
123        # Also the other payments can be made
124        self.browser.getControl(name="form.p_category").value = ['gown']
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 = ['transfer']
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 = ['bed_allocation']
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(
141            name="form.p_category").value = ['hostel_maintenance']
142        self.browser.getControl("Create ticket").click()
143        self.assertMatches('...ticket created...',
144                           self.browser.contents)
145        self.browser.open(self.payments_path + '/addop')
146        self.browser.getControl(name="form.p_category").value = ['clearance']
147        self.browser.getControl("Create ticket").click()
148        self.assertMatches('...ticket created...',
149                           self.browser.contents)
150        # Remove all payments so that we can add a school fee payment again
151        keys = [i for i in self.student['payments'].keys()]
152        for payment in keys:
153            del self.student['payments'][payment]
154        self.browser.open(self.payments_path + '/addop')
155        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
156        self.browser.getControl("Create ticket").click()
157        self.assertMatches('...ticket created...',
158                           self.browser.contents)
159        # We can't add the 2nd instalment ticket because the
160        # first one has not yet been approved.
161        self.browser.open(self.payments_path + '/addop')
162        self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
163        self.browser.getControl("Create ticket").click()
164        self.assertMatches('...1st school fee instalment has not yet been paid...',
165                           self.browser.contents)
166        # Ok, then we approve the first instalment ...
167        self.browser.open(self.payments_path)
168        ctrl = self.browser.getControl(name='val_id')
169        p_id = ctrl.options[0]
170        self.browser.open(self.payments_path + '/' + p_id + '/approve')
171        # ... add the second instalment ...
172        self.browser.open(self.payments_path + '/addop')
173        self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
174        self.browser.getControl("Create ticket").click()
175        self.assertMatches('...ticket created...',
176                           self.browser.contents)
177        # ... approve the second instalment ...
178        ctrl = self.browser.getControl(name='val_id')
179        p_id = ctrl.options[1]
180        self.browser.open(self.payments_path + '/' + p_id + '/approve')
181        # ... and finally add the 1st instalment for the next session
182        # provided that student is returning.
183        IWorkflowState(self.student).setState('returning')
184        self.browser.open(self.payments_path + '/addop')
185        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
186        self.browser.getControl("Create ticket").click()
187        self.assertMatches('...Session configuration object is not...',
188                           self.browser.contents)
189        # Uups, we forgot to add a session configuration for next session
190        configuration = createObject('waeup.SessionConfiguration')
191        configuration.academic_session = 2005
192        self.app['configuration'].addSessionConfiguration(configuration)
193        self.app['configuration']['2005'].school_fee_base = 7777.0
194        self.browser.open(self.payments_path + '/addop')
195        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
196        self.browser.getControl("Create ticket").click()
197        self.assertMatches('...ticket created...',
198                           self.browser.contents)
199        # If the session configuration doesn't exist an error message will
200        # be shown. No other requirement is being checked.
201        del self.app['configuration']['2004']
202        self.browser.open(self.payments_path)
203        self.browser.getLink("Add current session payment ticket").click()
204        self.browser.getControl("Create ticket").click()
205        self.assertMatches('...Session configuration object is not...',
206                           self.browser.contents)
207
208    def test_student_payments(self):
209        # Login
210        IWorkflowState(self.student).setState('returning')
211        self.browser.open(self.login_path)
212        self.browser.getControl(name="form.login").value = self.student_id
213        self.browser.getControl(name="form.password").value = 'spwd'
214        self.browser.getControl("Login").click()
215        self.browser.open(self.student_path + '/payments')
216        self.assertTrue(
217          'Add current session payment ticket' in self.browser.contents)
218        self.assertFalse(
219          'Add previous session payment ticket' in self.browser.contents)
220        return
221
222    def test_get_returning_data(self):
223        # Student is in level 100, session 2004 with verdict A
224        utils = getUtility(IStudentsUtils)
225        self.assertEqual(utils.getReturningData(self.student),(2005, 200))
226        self.student['studycourse'].current_verdict = 'C'
227        self.assertEqual(utils.getReturningData(self.student),(2005, 110))
228        self.student['studycourse'].current_verdict = 'D'
229        self.assertEqual(utils.getReturningData(self.student),(2005, 100))
230        return
231
232    def test_set_payment_details(self):
233        self.app['configuration']['2004'].gown_fee = 150.0
234        self.app['configuration']['2004'].transfer_fee = 90.0
235        self.app['configuration']['2004'].booking_fee = 150.0
236        self.app['configuration']['2004'].maint_fee = 180.0
237        self.app['configuration']['2004'].clearance_fee = 1234.0
238        self.app['configuration']['2004'].school_fee_base = 6666.0
239        utils = getUtility(IStudentsUtils)
240
241        configuration = createObject('waeup.SessionConfiguration')
242        configuration.academic_session = 2005
243        self.app['configuration'].addSessionConfiguration(configuration)
244        self.app['configuration']['2005'].school_fee_base = 7777.0
245
246        error, payment = utils.setPaymentDetails('schoolfee_1',self.student)
247        self.assertEqual(payment, None)
248        self.assertEqual(error, u'Wrong state.')
249
250        IWorkflowState(self.student).setState('cleared')
251        error, payment = utils.setPaymentDetails('schoolfee_1',self.student)
252        self.assertEqual(payment.p_level, 100)
253        self.assertEqual(payment.p_session, 2004)
254        self.assertEqual(payment.amount_auth, 6666.0)
255        self.assertEqual(payment.p_item, u'CERT1')
256        self.assertEqual(error, None)
257
258        # Add penalty fee ...
259        # ... for cleared
260        self.app['configuration']['2004'].penalty_ug = 99.0
261        # ... for returning
262        self.app['configuration']['2005'].penalty_ug = 88.0
263        error, payment = utils.setPaymentDetails('schoolfee_1',self.student)
264        self.assertEqual(payment.amount_auth, 6765.0)
265        IWorkflowState(self.student).setState('returning')
266        error, payment = utils.setPaymentDetails('schoolfee_1',self.student)
267        self.assertEqual(payment.p_level, 200)
268        self.assertEqual(payment.p_session, 2005)
269        self.assertEqual(payment.amount_auth, 7865.0)
270        self.assertEqual(payment.p_item, u'CERT1')
271        self.assertEqual(error, None)
272
273        error, payment = utils.setPaymentDetails('clearance',self.student)
274        self.assertEqual(payment.p_level, 100)
275        self.assertEqual(payment.p_session, 2004)
276        self.assertEqual(payment.amount_auth, 1234.0)
277        self.assertEqual(payment.p_item, u'CERT1')
278        self.assertEqual(error, None)
279
280        error, payment = utils.setPaymentDetails('gown',self.student)
281        self.assertEqual(payment.p_level, 100)
282        self.assertEqual(payment.p_session, 2004)
283        self.assertEqual(payment.amount_auth, 150.0)
284        self.assertEqual(payment.p_item, u'')
285        self.assertEqual(error, None)
286
287        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
288        self.assertEqual(payment.p_level, 100)
289        self.assertEqual(payment.p_session, 2004)
290        self.assertEqual(payment.amount_auth, 180.0)
291        self.assertEqual(payment.p_item, u'')
292        self.assertEqual(error, None)
293
294        error, payment = utils.setPaymentDetails('bed_allocation',self.student)
295        self.assertEqual(payment.p_level, 100)
296        self.assertEqual(payment.p_session, 2004)
297        self.assertEqual(payment.amount_auth, 150.0)
298        self.assertEqual(payment.p_item, u'')
299        self.assertEqual(error, None)
300
301        error, payment = utils.setPaymentDetails('transfer',self.student)
302        self.assertEqual(payment.p_level, 100)
303        self.assertEqual(payment.p_session, 2004)
304        self.assertEqual(payment.amount_auth, 90.0)
305        self.assertEqual(payment.p_item, u'')
306        self.assertEqual(error, None)
307
308        error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100)
309        self.assertEqual(error, u'Previous session payment not yet implemented.')
310        return
311
312    def test_student_course_registration(self):
313
314        # Add more courses
315        self.course2 = createObject('waeup.Course')
316        self.course2.code = 'COURSE2'
317        self.course2.semester = 2
318        self.course2.credits = 10
319        self.course2.passmark = 40
320        self.app['faculties']['fac1']['dep1'].courses.addCourse(
321            self.course2)
322        self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCertCourse(
323            self.course2, level=100)
324        self.course3 = createObject('waeup.Course')
325        self.course3.code = 'COURSE3'
326        self.course3.semester = 3
327        self.course3.credits = 10
328        self.course3.passmark = 40
329        self.app['faculties']['fac1']['dep1'].courses.addCourse(
330            self.course3)
331        self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCertCourse(
332            self.course3, level=100)
333
334        # Login as student
335        self.browser.open(self.login_path)
336        IWorkflowState(self.student).setState('school fee paid')
337        self.browser.open(self.login_path)
338        self.browser.getControl(name="form.login").value = self.student_id
339        self.browser.getControl(name="form.password").value = 'spwd'
340        self.browser.getControl("Login").click()
341        # Students can add the current study level
342        self.browser.getLink("Study Course").click()
343        self.browser.getLink("Add course list").click()
344        self.assertMatches('...Add current level 100 (Year 1)...',
345                           self.browser.contents)
346        self.browser.getControl("Create course list now").click()
347        # Student has not paid second instalment, therefore a level
348        # with two course ticket was created (semester 1 and combined)
349        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 2)
350        self.browser.getLink("100").click()
351        self.browser.getLink("Edit course list").click()
352        self.browser.getControl("Add course ticket").click()
353        # Student can't add second semester course
354        self.assertTrue('<option value="COURSE1">' in self.browser.contents)
355        self.assertTrue('<option value="COURSE3">' in self.browser.contents)
356        self.assertFalse('<option value="COURSE2">' in self.browser.contents)
357
358        # Let's remove level and see what happens after 2nd instalment payment
359        del(self.student['studycourse']['100'])
360        payment2 = createObject('waeup.StudentOnlinePayment')
361        payment2.p_category = u'schoolfee_2'
362        payment2.p_session = self.student.current_session
363        self.student['payments']['anykey'] = payment2
364        self.browser.open(self.studycourse_path)
365        self.browser.getLink("Add course list").click()
366        self.browser.getControl("Create course list now").click()
367        # Still only 2 tickets have been created since payment ticket
368        # was not paid
369        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 2)
370        payment2.p_state = u'paid'
371        del(self.student['studycourse']['100'])
372        self.browser.open(self.studycourse_path)
373        self.browser.getLink("Add course list").click()
374        self.browser.getControl("Create course list now").click()
375        # Now 2nd semester course has been added
376        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 3)
377        # Student can add second semester course
378        self.browser.getLink("100").click()
379        self.browser.getLink("Edit course list").click()
380        self.browser.getControl("Add course ticket").click()
381        self.assertTrue('<option value="COURSE1">' in self.browser.contents)
382        self.assertTrue('<option value="COURSE2">' in self.browser.contents)
383        self.assertTrue('<option value="COURSE3">' in self.browser.contents)
384        return
Note: See TracBrowser for help on using the repository browser.