source: main/waeup.futminna/trunk/src/waeup/futminna/students/tests/test_browser.py @ 9756

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

Add session specific penalty fee.

  • Property svn:keywords set to Id
File size: 13.1 KB
Line 
1## $Id: test_browser.py 9732 2012-11-27 15:50:05Z 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.university.faculty import Faculty
28from waeup.kofa.university.department import Department
29from waeup.kofa.students.tests.test_browser import StudentsFullSetup
30from waeup.kofa.students.accommodation import BedTicket
31from waeup.kofa.testing import FunctionalTestCase
32from waeup.kofa.interfaces import (
33    IExtFileStore, IFileStoreNameChooser)
34from waeup.kofa.students.interfaces import IStudentsUtils
35from waeup.kofa.hostels.hostel import Bed, NOT_OCCUPIED
36from waeup.futminna.testing import FunctionalLayer
37
38
39class StudentProcessorTest(FunctionalTestCase):
40    """Perform some batching tests.
41    """
42
43    layer = FunctionalLayer
44
45    def setUp(self):
46        super(StudentProcessorTest, self).setUp()
47        # Setup a sample site for each test
48        app = University()
49        self.dc_root = tempfile.mkdtemp()
50        app['datacenter'].setStoragePath(self.dc_root)
51
52        # Prepopulate the ZODB...
53        self.getRootFolder()['app'] = app
54        # we add the site immediately after creation to the
55        # ZODB. Catalogs and other local utilities are not setup
56        # before that step.
57        self.app = self.getRootFolder()['app']
58        # Set site here. Some of the following setup code might need
59        # to access grok.getSite() and should get our new app then
60        setSite(app)
61
62
63    def tearDown(self):
64        super(StudentProcessorTest, self).tearDown()
65        shutil.rmtree(self.workdir)
66        shutil.rmtree(self.dc_root)
67        clearSite()
68        return
69
70class StudentUITests(StudentsFullSetup):
71    """Tests for customized student class views and pages
72    """
73
74    layer = FunctionalLayer
75
76    def setUp(self):
77        super(StudentUITests, self).setUp()
78
79        # Create SSE faculty with certificate
80        self.app['faculties']['SSE'] = Faculty(code='SSE')
81        self.app['faculties']['SSE']['dep1'] = Department(code='dep1')
82        self.certificate2 = createObject('waeup.Certificate')
83        self.certificate2.code = u'CERT2'
84        self.certificate2.application_category = 'basic'
85        self.certificate2.study_mode = 'ug_ft'
86        self.certificate2.start_level = 100
87        self.certificate2.end_level = 300
88        self.app['faculties']['SSE']['dep1'].certificates.addCertificate(
89            self.certificate2)
90        # Create EET faculty with certificate
91        self.app['faculties']['EET'] = Faculty(code='EET')
92        self.app['faculties']['EET']['dep1'] = Department(code='dep1')
93        self.certificate3 = createObject('waeup.Certificate')
94        self.certificate3.code = u'CERT3'
95        self.certificate3.application_category = 'basic'
96        self.certificate3.study_mode = 'ug_ft'
97        self.certificate3.start_level = 100
98        self.certificate3.end_level = 300
99        self.app['faculties']['EET']['dep1'].certificates.addCertificate(
100            self.certificate3)
101        # Set study course attributes of test student
102        self.student['studycourse'].certificate = self.certificate2
103        self.student['studycourse'].current_session = 2004
104        self.student['studycourse'].entry_session = 2004
105        self.student['studycourse'].current_verdict = 'A'
106        self.student['studycourse'].current_level = 100
107        # Add sse bed
108        bed = Bed()
109        bed.bed_id = u'hall-1_A_101_C'
110        bed.bed_number = 2
111        bed.owner = NOT_OCCUPIED
112        bed.bed_type = u'sse_male_fr'
113        self.app['hostels']['hall-1'].addBed(bed)
114
115    def test_get_returning_data(self):
116        # Student is in level 100, session 2004 with verdict A
117        utils = getUtility(IStudentsUtils)
118        self.assertEqual(utils.getReturningData(self.student),(2005, 200))
119        self.student['studycourse'].current_verdict = 'C'
120        self.assertEqual(utils.getReturningData(self.student),(2005, 110))
121        self.student['studycourse'].current_verdict = 'D'
122        self.assertEqual(utils.getReturningData(self.student),(2005, 100))
123        return
124
125    def test_set_payment_details(self):
126        self.app['configuration']['2004'].gown_fee = 150.0
127        self.app['configuration']['2004'].transfer_fee = 90.0
128        self.app['configuration']['2004'].booking_fee = 150.0
129        self.app['configuration']['2004'].maint_fee = 180.0
130        self.app['configuration']['2004'].clearance_fee = 120.0
131        utils = getUtility(IStudentsUtils)
132
133        error, payment = utils.setPaymentDetails('schoolfee',self.student)
134        self.assertEqual(payment, None)
135        self.assertEqual(error, u'Amount could not be determined.')
136
137        self.student.nationality = u'NG'
138
139        IWorkflowState(self.student).setState('cleared')
140        error, payment = utils.setPaymentDetails('schoolfee',self.student)
141        self.assertEqual(payment.p_level, 100)
142        self.assertEqual(payment.p_session, 2004)
143        self.assertEqual(payment.amount_auth, 37000.0)
144        self.assertEqual(payment.p_item, u'CERT2')
145        self.assertEqual(error, None)
146
147        self.certificate2.study_mode = 'jm_ft'
148        error, payment = utils.setPaymentDetails('schoolfee',self.student)
149        self.assertEqual(payment.amount_auth, 72700.0)
150
151        IWorkflowState(self.student).setState('returning')
152        error, payment = utils.setPaymentDetails('schoolfee',self.student)
153        # Uups, we forgot to add a session configuration for next session
154        self.assertEqual('Session configuration object is not available.', error)
155        configuration = createObject('waeup.SessionConfiguration')
156        configuration.academic_session = 2005
157        self.app['configuration'].addSessionConfiguration(configuration)
158
159        error, payment = utils.setPaymentDetails('schoolfee',self.student)
160        self.assertEqual(payment.p_level, 200)
161        self.assertEqual(payment.p_session, 2005)
162        self.assertEqual(payment.amount_auth, 37000.0)
163        self.assertEqual(payment.p_item, u'CERT2')
164        self.assertEqual(error, None)
165
166        self.certificate2.study_mode = 'ug_ft'
167        error, payment = utils.setPaymentDetails('schoolfee',self.student)
168        self.assertEqual(payment.amount_auth, 20000.0)
169
170        # Penalty fee is taken into consideration
171        self.app['configuration']['2005'].penalty_ug = 3000.0
172        error, payment = utils.setPaymentDetails('schoolfee',self.student)
173        self.assertEqual(payment.p_level, 200)
174        self.assertEqual(payment.p_session, 2005)
175        self.assertEqual(payment.amount_auth, 23000.0)
176        self.assertEqual(payment.p_item, u'CERT2')
177        self.assertEqual(error, None)
178
179        error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100)
180        self.assertEqual(error, u'Previous session payment not yet implemented.')
181
182        self.app['configuration']['2004'].clearance_fee = 20000.0
183        error, payment = utils.setPaymentDetails('clearance',self.student)
184        self.assertEqual(payment.p_level, 100)
185        self.assertEqual(payment.p_session, 2004)
186        self.assertEqual(payment.amount_auth, 20000.0)
187        self.assertEqual(payment.p_item, u'CERT2')
188        self.assertEqual(error, None)
189
190        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
191        self.assertEqual(error, 'You have not yet booked accommodation.')
192        bedticket = BedTicket()
193        bedticket.booking_session = 2004
194        bedticket.bed_type = u'any bed type'
195        bedticket.bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
196        bedticket.bed_coordinates = u'My bed coordinates'
197        self.student['accommodation'].addBedTicket(bedticket)
198        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
199        self.assertEqual(payment.p_level, 100)
200        self.assertEqual(payment.p_session, 2004)
201        self.assertEqual(payment.amount_auth, 10000.0)
202        self.assertEqual(payment.p_item, u'My bed coordinates')
203        self.assertEqual(error, None)
204
205        self.student['studycourse'].certificate = self.certificate3
206        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
207        self.assertEqual(payment.p_level, 100)
208        self.assertEqual(payment.p_session, 2004)
209        self.assertEqual(payment.amount_auth, 12000.0)
210        self.assertEqual(payment.p_item, u'My bed coordinates')
211        self.assertEqual(error, None)
212
213        bedticket.bed.bed_id = u'block-h_anything'
214        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
215        self.assertEqual(payment.p_level, 100)
216        self.assertEqual(payment.p_session, 2004)
217        self.assertEqual(payment.amount_auth, 15000.0)
218        self.assertEqual(payment.p_item, u'My bed coordinates')
219        self.assertEqual(error, None)
220
221        self.app['hostels'].accommodation_session = 2009
222        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
223        self.assertEqual(error,
224            'Current session does not match accommodation session.')
225        self.assertEqual(payment, None)
226        return
227
228    def test_get_accommodation_details(self):
229        self.app['configuration']['2004'].gown_fee = 150.0
230        self.app['configuration']['2004'].transfer_fee = 90.0
231        self.app['configuration']['2004'].booking_fee = 150.0
232        self.app['configuration']['2004'].maint_fee = 180.0
233        self.app['configuration']['2004'].clearance_fee = 120.0
234        utils = getUtility(IStudentsUtils)
235
236        details = utils.getAccommodationDetails(self.student)
237        self.assertEqual(details['bt'], u'sse_male_fr')
238
239    def test_student_accommodation(self):
240        # Login
241        self.browser.open(self.login_path)
242        self.browser.getControl(name="form.login").value = self.student_id
243        self.browser.getControl(name="form.password").value = 'spwd'
244        self.browser.getControl("Login").click()
245
246        # Students can book accommodation without AC ...
247        self.browser.open(self.acco_path)
248        IWorkflowState(self.student).setState('admitted')
249        self.browser.getLink("Book accommodation").click()
250        self.assertFalse('Activation Code:' in self.browser.contents)
251        self.browser.getControl("Create bed ticket").click()
252        # Bed is randomly selected but, since there is only
253        # one bed for this student, we know that ...
254        self.assertMatches('...Hall 1, Block A, Room 101, Bed C...',
255                           self.browser.contents)
256        return
257
258    def test_student_payments(self):
259        # Login
260        IWorkflowState(self.student).setState('returning')
261        self.browser.open(self.login_path)
262        self.browser.getControl(name="form.login").value = self.student_id
263        self.browser.getControl(name="form.password").value = 'spwd'
264        self.browser.getControl("Login").click()
265        self.browser.open(self.student_path + '/payments')
266        self.assertTrue(
267          'Add current session payment ticket' in self.browser.contents)
268        self.assertFalse(
269          'Add previous session payment ticket' in self.browser.contents)
270        return
271
272    def test_student_course_registration(self):
273        IWorkflowState(self.student).setState('school fee paid')
274        self.student['studycourse'].certificate = self.certificate
275        self.browser.open(self.login_path)
276        self.browser.getControl(name="form.login").value = self.student_id
277        self.browser.getControl(name="form.password").value = 'spwd'
278        self.browser.getControl("Login").click()
279        self.browser.getLink("Study Course").click()
280        self.browser.getLink("Add course list").click()
281        self.assertMatches('...Add current level 100 (Year 1)...',
282                           self.browser.contents)
283        self.browser.getControl("Create course list now").click()
284        # A level with one course ticket was created
285        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 1)
286        # Even if course is mandatory, students can remove the course
287        self.student['studycourse']['100']['COURSE1'].mandatory = True
288        self.browser.getLink("100").click()
289        self.browser.getLink("Edit course list").click()
290        ctrl = self.browser.getControl(name='val_id')
291        ctrl.getControl(value='COURSE1').selected = True
292        self.browser.getControl("Remove selected", index=0).click()
293        self.assertTrue('Successfully removed' in self.browser.contents)
294        return
Note: See TracBrowser for help on using the repository browser.