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

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

Link maintenance payment with bedticket. This way we can forgo a secon maint. payment category. The amount depends now on the bed really booked.

  • Property svn:keywords set to Id
File size: 10.3 KB
Line 
1## $Id: test_browser.py 9431 2012-10-26 20:59:03Z 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        self.assertEqual(payment.p_level, 200)
154        self.assertEqual(payment.p_session, 2005)
155        self.assertEqual(payment.amount_auth, 37000.0)
156        self.assertEqual(payment.p_item, u'CERT2')
157        self.assertEqual(error, None)
158
159        self.certificate2.study_mode = 'ug_ft'
160        error, payment = utils.setPaymentDetails('schoolfee',self.student)
161        self.assertEqual(payment.amount_auth, 20000.0)
162
163        error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100)
164        self.assertEqual(error, u'Previous session payment not yet implemented.')
165
166        error, payment = utils.setPaymentDetails('clearance',self.student)
167        self.assertEqual(payment.p_level, 100)
168        self.assertEqual(payment.p_session, 2004)
169        self.assertEqual(payment.amount_auth, 20000.0)
170        self.assertEqual(payment.p_item, u'CERT2')
171        self.assertEqual(error, None)
172
173        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
174        self.assertEqual(error, 'You have not yet booked accommodation.')
175        bedticket = BedTicket()
176        bedticket.booking_session = 2004
177        bedticket.bed_type = u'any bed type'
178        bedticket.bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
179        bedticket.bed_coordinates = u'My bed coordinates'
180        self.student['accommodation'].addBedTicket(bedticket)
181        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
182        self.assertEqual(payment.p_level, 100)
183        self.assertEqual(payment.p_session, 2004)
184        self.assertEqual(payment.amount_auth, 10000.0)
185        self.assertEqual(payment.p_item, u'My bed coordinates')
186        self.assertEqual(error, None)
187
188        self.student['studycourse'].certificate = self.certificate3
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, 12000.0)
193        self.assertEqual(payment.p_item, u'My bed coordinates')
194        self.assertEqual(error, None)
195
196        bedticket.bed.bed_id = u'block-h_anything'
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, 15000.0)
201        self.assertEqual(payment.p_item, u'My bed coordinates')
202        self.assertEqual(error, None)
203
204        self.app['hostels'].accommodation_session = 2009
205        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
206        self.assertEqual(error,
207            'Current session does not match accommodation session.')
208        self.assertEqual(payment, None)
209        return
210
211    def test_get_accommodation_details(self):
212        self.app['configuration']['2004'].gown_fee = 150.0
213        self.app['configuration']['2004'].transfer_fee = 90.0
214        self.app['configuration']['2004'].booking_fee = 150.0
215        self.app['configuration']['2004'].maint_fee = 180.0
216        self.app['configuration']['2004'].clearance_fee = 120.0
217        utils = getUtility(IStudentsUtils)
218
219        details = utils.getAccommodationDetails(self.student)
220        self.assertEqual(details['bt'], u'sse_male_fr')
221
222    def test_student_accommodation(self):
223        # Login
224        self.browser.open(self.login_path)
225        self.browser.getControl(name="form.login").value = self.student_id
226        self.browser.getControl(name="form.password").value = 'spwd'
227        self.browser.getControl("Login").click()
228
229        # Students can book accommodation without AC ...
230        self.browser.open(self.acco_path)
231        IWorkflowState(self.student).setState('admitted')
232        self.browser.getLink("Book accommodation").click()
233        self.assertFalse('Activation Code:' in self.browser.contents)
234        self.browser.getControl("Create bed ticket").click()
235        # Bed is randomly selected but, since there is only
236        # one bed for this student, we know that ...
237        self.assertMatches('...Hall 1, Block A, Room 101, Bed C...',
238                           self.browser.contents)
239        return
Note: See TracBrowser for help on using the repository browser.