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

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

Change acceptance fee calculation. This way penalty fees can be added or payment can be disabled via the UI.

  • Property svn:keywords set to Id
File size: 12.7 KB
Line 
1## $Id: test_browser.py 9714 2012-11-23 10:51:00Z 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        error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100)
171        self.assertEqual(error, u'Previous session payment not yet implemented.')
172
173        self.app['configuration']['2004'].clearance_fee = 20000.0
174        error, payment = utils.setPaymentDetails('clearance',self.student)
175        self.assertEqual(payment.p_level, 100)
176        self.assertEqual(payment.p_session, 2004)
177        self.assertEqual(payment.amount_auth, 20000.0)
178        self.assertEqual(payment.p_item, u'CERT2')
179        self.assertEqual(error, None)
180
181        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
182        self.assertEqual(error, 'You have not yet booked accommodation.')
183        bedticket = BedTicket()
184        bedticket.booking_session = 2004
185        bedticket.bed_type = u'any bed type'
186        bedticket.bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
187        bedticket.bed_coordinates = u'My bed coordinates'
188        self.student['accommodation'].addBedTicket(bedticket)
189        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
190        self.assertEqual(payment.p_level, 100)
191        self.assertEqual(payment.p_session, 2004)
192        self.assertEqual(payment.amount_auth, 10000.0)
193        self.assertEqual(payment.p_item, u'My bed coordinates')
194        self.assertEqual(error, None)
195
196        self.student['studycourse'].certificate = self.certificate3
197        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
198        self.assertEqual(payment.p_level, 100)
199        self.assertEqual(payment.p_session, 2004)
200        self.assertEqual(payment.amount_auth, 12000.0)
201        self.assertEqual(payment.p_item, u'My bed coordinates')
202        self.assertEqual(error, None)
203
204        bedticket.bed.bed_id = u'block-h_anything'
205        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
206        self.assertEqual(payment.p_level, 100)
207        self.assertEqual(payment.p_session, 2004)
208        self.assertEqual(payment.amount_auth, 15000.0)
209        self.assertEqual(payment.p_item, u'My bed coordinates')
210        self.assertEqual(error, None)
211
212        self.app['hostels'].accommodation_session = 2009
213        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
214        self.assertEqual(error,
215            'Current session does not match accommodation session.')
216        self.assertEqual(payment, None)
217        return
218
219    def test_get_accommodation_details(self):
220        self.app['configuration']['2004'].gown_fee = 150.0
221        self.app['configuration']['2004'].transfer_fee = 90.0
222        self.app['configuration']['2004'].booking_fee = 150.0
223        self.app['configuration']['2004'].maint_fee = 180.0
224        self.app['configuration']['2004'].clearance_fee = 120.0
225        utils = getUtility(IStudentsUtils)
226
227        details = utils.getAccommodationDetails(self.student)
228        self.assertEqual(details['bt'], u'sse_male_fr')
229
230    def test_student_accommodation(self):
231        # Login
232        self.browser.open(self.login_path)
233        self.browser.getControl(name="form.login").value = self.student_id
234        self.browser.getControl(name="form.password").value = 'spwd'
235        self.browser.getControl("Login").click()
236
237        # Students can book accommodation without AC ...
238        self.browser.open(self.acco_path)
239        IWorkflowState(self.student).setState('admitted')
240        self.browser.getLink("Book accommodation").click()
241        self.assertFalse('Activation Code:' in self.browser.contents)
242        self.browser.getControl("Create bed ticket").click()
243        # Bed is randomly selected but, since there is only
244        # one bed for this student, we know that ...
245        self.assertMatches('...Hall 1, Block A, Room 101, Bed C...',
246                           self.browser.contents)
247        return
248
249    def test_student_payments(self):
250        # Login
251        IWorkflowState(self.student).setState('returning')
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        self.browser.open(self.student_path + '/payments')
257        self.assertTrue(
258          'Add current session payment ticket' in self.browser.contents)
259        self.assertFalse(
260          'Add previous session payment ticket' in self.browser.contents)
261        return
262
263    def test_student_course_registration(self):
264        IWorkflowState(self.student).setState('school fee paid')
265        self.student['studycourse'].certificate = self.certificate
266        self.browser.open(self.login_path)
267        self.browser.getControl(name="form.login").value = self.student_id
268        self.browser.getControl(name="form.password").value = 'spwd'
269        self.browser.getControl("Login").click()
270        self.browser.getLink("Study Course").click()
271        self.browser.getLink("Add course list").click()
272        self.assertMatches('...Add current level 100 (Year 1)...',
273                           self.browser.contents)
274        self.browser.getControl("Create course list now").click()
275        # A level with one course ticket was created
276        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 1)
277        # Even if course is mandatory, students can remove the course
278        self.student['studycourse']['100']['COURSE1'].mandatory = True
279        self.browser.getLink("100").click()
280        self.browser.getLink("Edit course list").click()
281        ctrl = self.browser.getControl(name='val_id')
282        ctrl.getControl(value='COURSE1').selected = True
283        self.browser.getControl("Remove selected", index=0).click()
284        self.assertTrue('Successfully removed' in self.browser.contents)
285        return
Note: See TracBrowser for help on using the repository browser.