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

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

Configure hostel maintenance fee.

  • Property svn:keywords set to Id
File size: 8.8 KB
Line 
1## $Id: test_browser.py 9404 2012-10-24 09:38:33Z 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.testing import FunctionalTestCase
31from waeup.kofa.interfaces import (
32    IExtFileStore, IFileStoreNameChooser)
33from waeup.kofa.students.interfaces import IStudentsUtils
34from waeup.kofa.hostels.hostel import Bed, NOT_OCCUPIED
35from waeup.futminna.testing import FunctionalLayer
36
37
38class StudentProcessorTest(FunctionalTestCase):
39    """Perform some batching tests.
40    """
41
42    layer = FunctionalLayer
43
44    def setUp(self):
45        super(StudentProcessorTest, self).setUp()
46        # Setup a sample site for each test
47        app = University()
48        self.dc_root = tempfile.mkdtemp()
49        app['datacenter'].setStoragePath(self.dc_root)
50
51        # Prepopulate the ZODB...
52        self.getRootFolder()['app'] = app
53        # we add the site immediately after creation to the
54        # ZODB. Catalogs and other local utilities are not setup
55        # before that step.
56        self.app = self.getRootFolder()['app']
57        # Set site here. Some of the following setup code might need
58        # to access grok.getSite() and should get our new app then
59        setSite(app)
60
61
62    def tearDown(self):
63        super(StudentProcessorTest, self).tearDown()
64        shutil.rmtree(self.workdir)
65        shutil.rmtree(self.dc_root)
66        clearSite()
67        return
68
69class StudentUITests(StudentsFullSetup):
70    """Tests for customized student class views and pages
71    """
72
73    layer = FunctionalLayer
74
75    def setUp(self):
76        super(StudentUITests, self).setUp()
77
78        # Create SSE faculty with certificate
79        self.app['faculties']['SSE'] = Faculty(code='SSE')
80        self.app['faculties']['SSE']['dep1'] = Department(code='dep1')
81        self.certificate2 = createObject('waeup.Certificate')
82        self.certificate2.code = u'CERT2'
83        self.certificate2.application_category = 'basic'
84        self.certificate2.study_mode = 'ug_ft'
85        self.certificate2.start_level = 100
86        self.certificate2.end_level = 300
87        self.app['faculties']['SSE']['dep1'].certificates.addCertificate(
88            self.certificate2)
89        # Set study course attributes of test student
90        self.student['studycourse'].certificate = self.certificate2
91        self.student['studycourse'].current_session = 2004
92        self.student['studycourse'].entry_session = 2004
93        self.student['studycourse'].current_verdict = 'A'
94        self.student['studycourse'].current_level = 100
95        # Add sse bed
96        bed = Bed()
97        bed.bed_id = u'hall-1_A_101_C'
98        bed.bed_number = 2
99        bed.owner = NOT_OCCUPIED
100        bed.bed_type = u'sse_male_fr'
101        self.app['hostels']['hall-1'].addBed(bed)
102
103    def test_get_returning_data(self):
104        # Student is in level 100, session 2004 with verdict A
105        utils = getUtility(IStudentsUtils)
106        self.assertEqual(utils.getReturningData(self.student),(2005, 200))
107        self.student['studycourse'].current_verdict = 'C'
108        self.assertEqual(utils.getReturningData(self.student),(2005, 110))
109        self.student['studycourse'].current_verdict = 'D'
110        self.assertEqual(utils.getReturningData(self.student),(2005, 100))
111        return
112
113    def test_set_payment_details(self):
114        self.app['configuration']['2004'].gown_fee = 150.0
115        self.app['configuration']['2004'].transfer_fee = 90.0
116        self.app['configuration']['2004'].booking_fee = 150.0
117        self.app['configuration']['2004'].maint_fee = 180.0
118        self.app['configuration']['2004'].clearance_fee = 120.0
119        utils = getUtility(IStudentsUtils)
120
121        error, payment = utils.setPaymentDetails('schoolfee',self.student)
122        self.assertEqual(payment, None)
123        self.assertEqual(error, u'Amount could not be determined.')
124
125        self.student.nationality = u'NG'
126
127        IWorkflowState(self.student).setState('cleared')
128        error, payment = utils.setPaymentDetails('schoolfee',self.student)
129        self.assertEqual(payment.p_level, 100)
130        self.assertEqual(payment.p_session, 2004)
131        self.assertEqual(payment.amount_auth, 37000.0)
132        self.assertEqual(payment.p_item, u'CERT2')
133        self.assertEqual(error, None)
134
135        self.certificate2.study_mode = 'jm_ft'
136        error, payment = utils.setPaymentDetails('schoolfee',self.student)
137        self.assertEqual(payment.amount_auth, 72700.0)
138
139        IWorkflowState(self.student).setState('returning')
140        error, payment = utils.setPaymentDetails('schoolfee',self.student)
141        self.assertEqual(payment.p_level, 200)
142        self.assertEqual(payment.p_session, 2005)
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 = 'ug_ft'
148        error, payment = utils.setPaymentDetails('schoolfee',self.student)
149        self.assertEqual(payment.amount_auth, 20000.0)
150
151        error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100)
152        self.assertEqual(error, u'Previous session payment not yet implemented.')
153
154        error, payment = utils.setPaymentDetails('clearance',self.student)
155        self.assertEqual(payment.p_level, 100)
156        self.assertEqual(payment.p_session, 2004)
157        self.assertEqual(payment.amount_auth, 20000.0)
158        self.assertEqual(payment.p_item, u'CERT2')
159        self.assertEqual(error, None)
160
161        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
162        self.assertEqual(payment.p_level, 100)
163        self.assertEqual(payment.p_session, 2004)
164        self.assertEqual(payment.amount_auth, 15000.0)
165        self.assertEqual(payment.p_item, u'sse_male_fr')
166        self.assertEqual(error, None)
167
168        self.student['studycourse'].certificate = self.certificate
169        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
170        self.assertEqual(payment.p_level, 100)
171        self.assertEqual(payment.p_session, 2004)
172        self.assertEqual(payment.amount_auth, 10000.0)
173        self.assertEqual(payment.p_item, u'regular_male_fr')
174        self.assertEqual(error, None)
175
176        self.app['hostels'].accommodation_session = 2009
177        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
178        self.assertEqual(error,
179            'Current session does not match accommodation session.')
180        self.assertEqual(payment, None)
181        return
182
183    def test_get_accommodation_details(self):
184        self.app['configuration']['2004'].gown_fee = 150.0
185        self.app['configuration']['2004'].transfer_fee = 90.0
186        self.app['configuration']['2004'].booking_fee = 150.0
187        self.app['configuration']['2004'].maint_fee = 180.0
188        self.app['configuration']['2004'].clearance_fee = 120.0
189        utils = getUtility(IStudentsUtils)
190
191        details = utils.getAccommodationDetails(self.student)
192        self.assertEqual(details['bt'], u'sse_male_fr')
193
194    def test_student_accommodation(self):
195        # Login
196        self.browser.open(self.login_path)
197        self.browser.getControl(name="form.login").value = self.student_id
198        self.browser.getControl(name="form.password").value = 'spwd'
199        self.browser.getControl("Login").click()
200
201        # Students can book accommodation without AC ...
202        self.browser.open(self.acco_path)
203        IWorkflowState(self.student).setState('admitted')
204        self.browser.getLink("Book accommodation").click()
205        self.assertFalse('Activation Code:' in self.browser.contents)
206        self.browser.getControl("Create bed ticket").click()
207        # Bed is randomly selected but, since there is only
208        # one bed for this student, we know that ...
209        self.assertMatches('...Hall 1, Block A, Room 101, Bed C...',
210                           self.browser.contents)
211        return
Note: See TracBrowser for help on using the repository browser.