1 | ## $Id: test_browser.py 9891 2013-01-15 15:25:06Z 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 | ## |
---|
18 | import os |
---|
19 | import shutil |
---|
20 | import tempfile |
---|
21 | from StringIO import StringIO |
---|
22 | from hurry.workflow.interfaces import IWorkflowState |
---|
23 | from zope.component.hooks import setSite, clearSite |
---|
24 | from zope.component import getUtility, createObject |
---|
25 | from zope.interface import verify |
---|
26 | from waeup.kofa.app import University |
---|
27 | from waeup.kofa.university.faculty import Faculty |
---|
28 | from waeup.kofa.university.department import Department |
---|
29 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
30 | from waeup.kofa.students.accommodation import BedTicket |
---|
31 | from waeup.kofa.testing import FunctionalTestCase |
---|
32 | from waeup.kofa.interfaces import ( |
---|
33 | IExtFileStore, IFileStoreNameChooser) |
---|
34 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
35 | from waeup.kofa.hostels.hostel import Bed, NOT_OCCUPIED |
---|
36 | from waeup.futminna.testing import FunctionalLayer |
---|
37 | |
---|
38 | |
---|
39 | class 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 | |
---|
70 | class 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 = 'pg_ft' |
---|
148 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
149 | self.assertEqual(error, u'Amount could not be determined.') |
---|
150 | self.certificate2.school_fee_1 = 876.55 |
---|
151 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
152 | self.assertEqual(payment.amount_auth, 876.55) |
---|
153 | |
---|
154 | self.certificate2.study_mode = 'jm_ft' |
---|
155 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
156 | self.assertEqual(payment.amount_auth, 72700.0) |
---|
157 | |
---|
158 | IWorkflowState(self.student).setState('returning') |
---|
159 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
160 | # Uups, we forgot to add a session configuration for next session |
---|
161 | self.assertEqual('Session configuration object is not available.', error) |
---|
162 | configuration = createObject('waeup.SessionConfiguration') |
---|
163 | configuration.academic_session = 2005 |
---|
164 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
165 | |
---|
166 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
167 | self.assertEqual(payment.p_level, 200) |
---|
168 | self.assertEqual(payment.p_session, 2005) |
---|
169 | self.assertEqual(payment.amount_auth, 37000.0) |
---|
170 | self.assertEqual(payment.p_item, u'CERT2') |
---|
171 | self.assertEqual(error, None) |
---|
172 | |
---|
173 | self.certificate2.study_mode = 'ug_ft' |
---|
174 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
175 | self.assertEqual(payment.amount_auth, 20000.0) |
---|
176 | |
---|
177 | # Penalty fee is taken into consideration |
---|
178 | self.app['configuration']['2005'].penalty_ug = 9999.0 |
---|
179 | self.app['configuration']['2005'].penalty_pg = 9999.0 |
---|
180 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
181 | self.assertEqual(error, u'School fee payment is disabled.') |
---|
182 | self.app['configuration']['2005'].penalty_ug = 3000.0 |
---|
183 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
184 | self.assertEqual(payment.p_level, 200) |
---|
185 | self.assertEqual(payment.p_session, 2005) |
---|
186 | self.assertEqual(payment.amount_auth, 23000.0) |
---|
187 | self.assertEqual(payment.p_item, u'CERT2') |
---|
188 | self.assertEqual(error, None) |
---|
189 | |
---|
190 | error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100) |
---|
191 | self.assertEqual(error, u'Previous session payment not yet implemented.') |
---|
192 | |
---|
193 | self.app['configuration']['2004'].clearance_fee = 20000.0 |
---|
194 | error, payment = utils.setPaymentDetails('clearance',self.student) |
---|
195 | self.assertEqual(payment.p_level, 100) |
---|
196 | self.assertEqual(payment.p_session, 2004) |
---|
197 | self.assertEqual(payment.amount_auth, 20000.0) |
---|
198 | self.assertEqual(payment.p_item, u'CERT2') |
---|
199 | self.assertEqual(error, None) |
---|
200 | |
---|
201 | error, payment = utils.setPaymentDetails('hostel_maintenance',self.student) |
---|
202 | self.assertEqual(error, 'You have not yet booked accommodation.') |
---|
203 | bedticket = BedTicket() |
---|
204 | bedticket.booking_session = 2004 |
---|
205 | bedticket.bed_type = u'any bed type' |
---|
206 | bedticket.bed = self.app['hostels']['hall-1']['hall-1_A_101_A'] |
---|
207 | bedticket.bed_coordinates = u'My bed coordinates' |
---|
208 | self.student['accommodation'].addBedTicket(bedticket) |
---|
209 | error, payment = utils.setPaymentDetails('hostel_maintenance',self.student) |
---|
210 | self.assertEqual(payment.p_level, 100) |
---|
211 | self.assertEqual(payment.p_session, 2004) |
---|
212 | self.assertEqual(payment.amount_auth, 10000.0) |
---|
213 | self.assertEqual(payment.p_item, u'My bed coordinates') |
---|
214 | self.assertEqual(error, None) |
---|
215 | |
---|
216 | self.student['studycourse'].certificate = self.certificate3 |
---|
217 | error, payment = utils.setPaymentDetails('hostel_maintenance',self.student) |
---|
218 | self.assertEqual(payment.p_level, 100) |
---|
219 | self.assertEqual(payment.p_session, 2004) |
---|
220 | self.assertEqual(payment.amount_auth, 12000.0) |
---|
221 | self.assertEqual(payment.p_item, u'My bed coordinates') |
---|
222 | self.assertEqual(error, None) |
---|
223 | |
---|
224 | bedticket.bed.bed_id = u'block-h_anything' |
---|
225 | error, payment = utils.setPaymentDetails('hostel_maintenance',self.student) |
---|
226 | self.assertEqual(payment.p_level, 100) |
---|
227 | self.assertEqual(payment.p_session, 2004) |
---|
228 | self.assertEqual(payment.amount_auth, 15000.0) |
---|
229 | self.assertEqual(payment.p_item, u'My bed coordinates') |
---|
230 | self.assertEqual(error, None) |
---|
231 | |
---|
232 | self.app['hostels'].accommodation_session = 2009 |
---|
233 | error, payment = utils.setPaymentDetails('hostel_maintenance',self.student) |
---|
234 | self.assertEqual(error, |
---|
235 | 'Current session does not match accommodation session.') |
---|
236 | self.assertEqual(payment, None) |
---|
237 | return |
---|
238 | |
---|
239 | def test_get_accommodation_details(self): |
---|
240 | self.app['configuration']['2004'].gown_fee = 150.0 |
---|
241 | self.app['configuration']['2004'].transfer_fee = 90.0 |
---|
242 | self.app['configuration']['2004'].booking_fee = 150.0 |
---|
243 | self.app['configuration']['2004'].maint_fee = 180.0 |
---|
244 | self.app['configuration']['2004'].clearance_fee = 120.0 |
---|
245 | utils = getUtility(IStudentsUtils) |
---|
246 | |
---|
247 | details = utils.getAccommodationDetails(self.student) |
---|
248 | self.assertEqual(details['bt'], u'sse_male_fr') |
---|
249 | |
---|
250 | def test_student_accommodation(self): |
---|
251 | # Login |
---|
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 | |
---|
257 | # Students can book accommodation without AC ... |
---|
258 | self.browser.open(self.acco_path) |
---|
259 | IWorkflowState(self.student).setState('admitted') |
---|
260 | self.browser.getLink("Book accommodation").click() |
---|
261 | self.assertFalse('Activation Code:' in self.browser.contents) |
---|
262 | self.browser.getControl("Create bed ticket").click() |
---|
263 | # Bed is randomly selected but, since there is only |
---|
264 | # one bed for this student, we know that ... |
---|
265 | self.assertMatches('...Hall 1, Block A, Room 101, Bed C...', |
---|
266 | self.browser.contents) |
---|
267 | return |
---|
268 | |
---|
269 | def test_student_payments(self): |
---|
270 | # Login |
---|
271 | IWorkflowState(self.student).setState('returning') |
---|
272 | self.browser.open(self.login_path) |
---|
273 | self.browser.getControl(name="form.login").value = self.student_id |
---|
274 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
275 | self.browser.getControl("Login").click() |
---|
276 | self.browser.open(self.student_path + '/payments') |
---|
277 | self.assertTrue( |
---|
278 | 'Add current session payment ticket' in self.browser.contents) |
---|
279 | self.assertFalse( |
---|
280 | 'Add previous session payment ticket' in self.browser.contents) |
---|
281 | return |
---|
282 | |
---|
283 | def test_student_course_registration(self): |
---|
284 | IWorkflowState(self.student).setState('school fee paid') |
---|
285 | self.student['studycourse'].certificate = self.certificate |
---|
286 | self.browser.open(self.login_path) |
---|
287 | self.browser.getControl(name="form.login").value = self.student_id |
---|
288 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
289 | self.browser.getControl("Login").click() |
---|
290 | self.browser.getLink("Study Course").click() |
---|
291 | self.browser.getLink("Add course list").click() |
---|
292 | self.assertMatches('...Add current level 100 (Year 1)...', |
---|
293 | self.browser.contents) |
---|
294 | self.browser.getControl("Create course list now").click() |
---|
295 | # A level with one course ticket was created |
---|
296 | self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 1) |
---|
297 | # Even if course is mandatory, students can remove the course |
---|
298 | self.student['studycourse']['100']['COURSE1'].mandatory = True |
---|
299 | self.browser.getLink("100").click() |
---|
300 | self.browser.getLink("Edit course list").click() |
---|
301 | ctrl = self.browser.getControl(name='val_id') |
---|
302 | ctrl.getControl(value='COURSE1').selected = True |
---|
303 | self.browser.getControl("Remove selected", index=0).click() |
---|
304 | self.assertTrue('Successfully removed' in self.browser.contents) |
---|
305 | return |
---|