1 | ## $Id: test_browser.py 9524 2012-11-04 19:53:40Z 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 = '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 | error, payment = utils.setPaymentDetails('clearance',self.student) |
---|
174 | self.assertEqual(payment.p_level, 100) |
---|
175 | self.assertEqual(payment.p_session, 2004) |
---|
176 | self.assertEqual(payment.amount_auth, 20000.0) |
---|
177 | self.assertEqual(payment.p_item, u'CERT2') |
---|
178 | self.assertEqual(error, None) |
---|
179 | |
---|
180 | error, payment = utils.setPaymentDetails('hostel_maintenance',self.student) |
---|
181 | self.assertEqual(error, 'You have not yet booked accommodation.') |
---|
182 | bedticket = BedTicket() |
---|
183 | bedticket.booking_session = 2004 |
---|
184 | bedticket.bed_type = u'any bed type' |
---|
185 | bedticket.bed = self.app['hostels']['hall-1']['hall-1_A_101_A'] |
---|
186 | bedticket.bed_coordinates = u'My bed coordinates' |
---|
187 | self.student['accommodation'].addBedTicket(bedticket) |
---|
188 | error, payment = utils.setPaymentDetails('hostel_maintenance',self.student) |
---|
189 | self.assertEqual(payment.p_level, 100) |
---|
190 | self.assertEqual(payment.p_session, 2004) |
---|
191 | self.assertEqual(payment.amount_auth, 10000.0) |
---|
192 | self.assertEqual(payment.p_item, u'My bed coordinates') |
---|
193 | self.assertEqual(error, None) |
---|
194 | |
---|
195 | self.student['studycourse'].certificate = self.certificate3 |
---|
196 | error, payment = utils.setPaymentDetails('hostel_maintenance',self.student) |
---|
197 | self.assertEqual(payment.p_level, 100) |
---|
198 | self.assertEqual(payment.p_session, 2004) |
---|
199 | self.assertEqual(payment.amount_auth, 12000.0) |
---|
200 | self.assertEqual(payment.p_item, u'My bed coordinates') |
---|
201 | self.assertEqual(error, None) |
---|
202 | |
---|
203 | bedticket.bed.bed_id = u'block-h_anything' |
---|
204 | error, payment = utils.setPaymentDetails('hostel_maintenance',self.student) |
---|
205 | self.assertEqual(payment.p_level, 100) |
---|
206 | self.assertEqual(payment.p_session, 2004) |
---|
207 | self.assertEqual(payment.amount_auth, 15000.0) |
---|
208 | self.assertEqual(payment.p_item, u'My bed coordinates') |
---|
209 | self.assertEqual(error, None) |
---|
210 | |
---|
211 | self.app['hostels'].accommodation_session = 2009 |
---|
212 | error, payment = utils.setPaymentDetails('hostel_maintenance',self.student) |
---|
213 | self.assertEqual(error, |
---|
214 | 'Current session does not match accommodation session.') |
---|
215 | self.assertEqual(payment, None) |
---|
216 | return |
---|
217 | |
---|
218 | def test_get_accommodation_details(self): |
---|
219 | self.app['configuration']['2004'].gown_fee = 150.0 |
---|
220 | self.app['configuration']['2004'].transfer_fee = 90.0 |
---|
221 | self.app['configuration']['2004'].booking_fee = 150.0 |
---|
222 | self.app['configuration']['2004'].maint_fee = 180.0 |
---|
223 | self.app['configuration']['2004'].clearance_fee = 120.0 |
---|
224 | utils = getUtility(IStudentsUtils) |
---|
225 | |
---|
226 | details = utils.getAccommodationDetails(self.student) |
---|
227 | self.assertEqual(details['bt'], u'sse_male_fr') |
---|
228 | |
---|
229 | def test_student_accommodation(self): |
---|
230 | # Login |
---|
231 | self.browser.open(self.login_path) |
---|
232 | self.browser.getControl(name="form.login").value = self.student_id |
---|
233 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
234 | self.browser.getControl("Login").click() |
---|
235 | |
---|
236 | # Students can book accommodation without AC ... |
---|
237 | self.browser.open(self.acco_path) |
---|
238 | IWorkflowState(self.student).setState('admitted') |
---|
239 | self.browser.getLink("Book accommodation").click() |
---|
240 | self.assertFalse('Activation Code:' in self.browser.contents) |
---|
241 | self.browser.getControl("Create bed ticket").click() |
---|
242 | # Bed is randomly selected but, since there is only |
---|
243 | # one bed for this student, we know that ... |
---|
244 | self.assertMatches('...Hall 1, Block A, Room 101, Bed C...', |
---|
245 | self.browser.contents) |
---|
246 | return |
---|
247 | |
---|
248 | def test_student_payments(self): |
---|
249 | # Login |
---|
250 | IWorkflowState(self.student).setState('returning') |
---|
251 | self.browser.open(self.login_path) |
---|
252 | self.browser.getControl(name="form.login").value = self.student_id |
---|
253 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
254 | self.browser.getControl("Login").click() |
---|
255 | self.browser.open(self.student_path + '/payments') |
---|
256 | self.assertTrue( |
---|
257 | 'Add current session payment ticket' in self.browser.contents) |
---|
258 | self.assertFalse( |
---|
259 | 'Add previous session payment ticket' in self.browser.contents) |
---|
260 | return |
---|