1 | ## $Id: test_browser.py 13653 2016-02-07 07:32:25Z 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 mechanize import LinkNotFoundError |
---|
22 | from StringIO import StringIO |
---|
23 | from hurry.workflow.interfaces import IWorkflowState, IWorkflowInfo |
---|
24 | from zope.component.hooks import setSite, clearSite |
---|
25 | from zope.component import getUtility, createObject |
---|
26 | from zope.interface import verify |
---|
27 | from waeup.kofa.app import University |
---|
28 | from waeup.kofa.students.tests.test_browser import ( |
---|
29 | StudentsFullSetup, SAMPLE_IMAGE) |
---|
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.browser.tests.test_pdf import samples_dir |
---|
35 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
36 | from waeup.kwarapoly.testing import FunctionalLayer |
---|
37 | from waeup.kwarapoly.students.utils import ( |
---|
38 | local_nonlocal, arts_science, we_ft) |
---|
39 | |
---|
40 | |
---|
41 | class StudentProcessorTest(FunctionalTestCase): |
---|
42 | """Perform some batching tests. |
---|
43 | """ |
---|
44 | |
---|
45 | layer = FunctionalLayer |
---|
46 | |
---|
47 | def setUp(self): |
---|
48 | super(StudentProcessorTest, self).setUp() |
---|
49 | # Setup a sample site for each test |
---|
50 | app = University() |
---|
51 | self.dc_root = tempfile.mkdtemp() |
---|
52 | app['datacenter'].setStoragePath(self.dc_root) |
---|
53 | |
---|
54 | # Prepopulate the ZODB... |
---|
55 | self.getRootFolder()['app'] = app |
---|
56 | # we add the site immediately after creation to the |
---|
57 | # ZODB. Catalogs and other local utilities are not setup |
---|
58 | # before that step. |
---|
59 | self.app = self.getRootFolder()['app'] |
---|
60 | # Set site here. Some of the following setup code might need |
---|
61 | # to access grok.getSite() and should get our new app then |
---|
62 | setSite(app) |
---|
63 | |
---|
64 | |
---|
65 | def tearDown(self): |
---|
66 | super(StudentProcessorTest, self).tearDown() |
---|
67 | shutil.rmtree(self.workdir) |
---|
68 | shutil.rmtree(self.dc_root) |
---|
69 | clearSite() |
---|
70 | return |
---|
71 | |
---|
72 | class StudentUITests(StudentsFullSetup): |
---|
73 | """Tests for customized student class views and pages |
---|
74 | """ |
---|
75 | |
---|
76 | layer = FunctionalLayer |
---|
77 | |
---|
78 | def setUp(self): |
---|
79 | super(StudentUITests, self).setUp() |
---|
80 | self.certificate.study_mode = 'hnd_ft' |
---|
81 | bedticket = BedTicket() |
---|
82 | bedticket.booking_session = 2004 |
---|
83 | bedticket.bed_type = u'any bed type' |
---|
84 | bedticket.bed = self.app['hostels']['hall-1']['hall-1_A_101_A'] |
---|
85 | bedticket.bed_coordinates = u'My bed coordinates' |
---|
86 | self.student['accommodation'].addBedTicket(bedticket) |
---|
87 | |
---|
88 | self.app['configuration']['2004'].gown_fee = 150.0 |
---|
89 | self.app['configuration']['2004'].transfer_fee = 90.0 |
---|
90 | self.app['configuration']['2004'].clearance_fee = 120.0 |
---|
91 | self.app['configuration']['2004'].booking_fee = 150.0 |
---|
92 | self.app['configuration']['2004'].maint_fee = 180.0 |
---|
93 | self.app['configuration']['2004'].certificate_fee = 444.0 |
---|
94 | |
---|
95 | def test_manage_payments(self): |
---|
96 | # Managers can add online payment tickets |
---|
97 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
98 | self.browser.open(self.payments_path) |
---|
99 | self.browser.getLink("Add current session payment ticket").click() |
---|
100 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
101 | self.browser.getControl("Create ticket").click() |
---|
102 | self.assertMatches('...Amount could not be determined...', |
---|
103 | self.browser.contents) |
---|
104 | IWorkflowState(self.student).setState('cleared') |
---|
105 | self.browser.open(self.payments_path + '/addop') |
---|
106 | |
---|
107 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
108 | self.browser.getControl("Create ticket").click() |
---|
109 | self.assertMatches('...Book and pay for accommodation first...', |
---|
110 | self.browser.contents) |
---|
111 | # In KwaraPoly only returning students can create school fee payment |
---|
112 | # without having paid accommodation fee |
---|
113 | |
---|
114 | IWorkflowState(self.student).setState('returning') |
---|
115 | configuration = createObject('waeup.SessionConfiguration') |
---|
116 | configuration.academic_session = 2005 |
---|
117 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
118 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
119 | self.browser.getControl("Create ticket").click() |
---|
120 | self.assertMatches('...ticket created...', |
---|
121 | self.browser.contents) |
---|
122 | ctrl = self.browser.getControl(name='val_id') |
---|
123 | value = ctrl.options[0] |
---|
124 | self.browser.getLink(value).click() |
---|
125 | self.assertMatches('...Amount Authorized...', |
---|
126 | self.browser.contents) |
---|
127 | # Managers can open payment slip |
---|
128 | self.browser.getLink("Download payment slip").click() |
---|
129 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
130 | self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf') |
---|
131 | # Set ticket paid |
---|
132 | ticket = self.student['payments'].items()[0][1] |
---|
133 | ticket.p_state = 'paid' |
---|
134 | self.browser.open(self.payments_path + '/addop') |
---|
135 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
136 | self.browser.getControl("Create ticket").click() |
---|
137 | self.assertMatches('...This type of payment has already been made...', |
---|
138 | self.browser.contents) |
---|
139 | # Remove all payments so that we can add a school fee payment again |
---|
140 | keys = [i for i in self.student['payments'].keys()] |
---|
141 | for payment in keys: |
---|
142 | del self.student['payments'][payment] |
---|
143 | self.browser.open(self.payments_path + '/addop') |
---|
144 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
145 | self.browser.getControl("Create ticket").click() |
---|
146 | self.assertMatches('...ticket created...', |
---|
147 | self.browser.contents) |
---|
148 | self.browser.open(self.payments_path + '/addop') |
---|
149 | self.browser.getControl(name="form.p_category").value = ['carryover1'] |
---|
150 | self.browser.getControl("Create ticket").click() |
---|
151 | self.assertMatches('...ticket created...', |
---|
152 | self.browser.contents) |
---|
153 | self.browser.open(self.payments_path + '/addop') |
---|
154 | self.browser.getControl(name="form.p_category").value = ['carryover2'] |
---|
155 | self.browser.getControl("Create ticket").click() |
---|
156 | self.assertMatches('...ticket created...', |
---|
157 | self.browser.contents) |
---|
158 | self.browser.open(self.payments_path + '/addop') |
---|
159 | self.browser.getControl(name="form.p_category").value = ['carryover3'] |
---|
160 | self.browser.getControl("Create ticket").click() |
---|
161 | self.assertMatches('...ticket created...', |
---|
162 | self.browser.contents) |
---|
163 | self.browser.open(self.payments_path + '/addop') |
---|
164 | self.browser.getControl( |
---|
165 | name="form.p_category").value = ['hostel_maintenance'] |
---|
166 | self.browser.getControl("Create ticket").click() |
---|
167 | self.assertMatches('...ticket created...', |
---|
168 | self.browser.contents) |
---|
169 | self.browser.open(self.payments_path + '/addop') |
---|
170 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
171 | self.browser.getControl("Create ticket").click() |
---|
172 | self.assertMatches('...ticket created...', |
---|
173 | self.browser.contents) |
---|
174 | # In state admitted school fee can't be determined |
---|
175 | IWorkflowState(self.student).setState('admitted') |
---|
176 | self.browser.open(self.payments_path + '/addop') |
---|
177 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
178 | self.browser.getControl("Create ticket").click() |
---|
179 | self.assertMatches('...Amount could not be determined...', |
---|
180 | self.browser.contents) |
---|
181 | self.browser.open(self.payments_path + '/addop') |
---|
182 | self.browser.getControl(name="form.p_category").value = ['certificate'] |
---|
183 | self.browser.getControl("Create ticket").click() |
---|
184 | self.assertMatches('...ticket created...', |
---|
185 | self.browser.contents) |
---|
186 | |
---|
187 | def test_student_payments(self): |
---|
188 | # Login |
---|
189 | IWorkflowState(self.student).setState('returning') |
---|
190 | self.browser.open(self.login_path) |
---|
191 | self.browser.getControl(name="form.login").value = self.student_id |
---|
192 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
193 | self.browser.getControl("Login").click() |
---|
194 | self.browser.open(self.student_path + '/payments') |
---|
195 | self.assertTrue( |
---|
196 | 'Add current session payment ticket' in self.browser.contents) |
---|
197 | self.assertFalse( |
---|
198 | 'Add previous session payment ticket' in self.browser.contents) |
---|
199 | return |
---|
200 | |
---|
201 | def test_get_returning_data(self): |
---|
202 | # Student is in level 100, session 2004 with verdict A |
---|
203 | utils = getUtility(IStudentsUtils) |
---|
204 | self.assertEqual(utils.getReturningData(self.student),(2005, 200)) |
---|
205 | self.student['studycourse'].current_verdict = 'C' |
---|
206 | self.assertEqual(utils.getReturningData(self.student),(2005, 110)) |
---|
207 | self.student['studycourse'].current_verdict = 'D' |
---|
208 | self.assertEqual(utils.getReturningData(self.student),(2005, 100)) |
---|
209 | return |
---|
210 | |
---|
211 | def test_set_payment_details(self): |
---|
212 | utils = getUtility(IStudentsUtils) |
---|
213 | |
---|
214 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
215 | self.assertEqual(payment, None) |
---|
216 | self.assertEqual(error, u'Amount could not be determined.') |
---|
217 | |
---|
218 | IWorkflowState(self.student).setState('cleared') |
---|
219 | self.assertEqual(local_nonlocal(self.student), 'non-local') |
---|
220 | self.assertEqual(arts_science(self.student), 'science') |
---|
221 | self.assertEqual(we_ft(self.student), 'ft') |
---|
222 | |
---|
223 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
224 | self.assertEqual(error, |
---|
225 | 'Book and pay for accommodation first before making' |
---|
226 | ' school fee payments.') |
---|
227 | # We add a fake maint. payment ticket to meet the condition |
---|
228 | maint_payment = createObject('waeup.StudentOnlinePayment') |
---|
229 | self.student['payments']['any_key'] = maint_payment |
---|
230 | maint_payment.p_category = 'hostel_maintenance' |
---|
231 | maint_payment.p_state = 'paid' |
---|
232 | maint_payment.p_session = 2004 |
---|
233 | |
---|
234 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
235 | self.assertEqual(payment.p_level, 100) |
---|
236 | self.assertEqual(payment.p_session, 2004) |
---|
237 | self.assertEqual(payment.amount_auth, 55200.0) |
---|
238 | self.assertEqual(payment.p_item, u'CERT1') |
---|
239 | self.assertEqual(error, None) |
---|
240 | |
---|
241 | IWorkflowState(self.student).setState('returning') |
---|
242 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
243 | self.assertEqual('Session configuration object is not available.', error) |
---|
244 | configuration = createObject('waeup.SessionConfiguration') |
---|
245 | configuration.academic_session = 2005 |
---|
246 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
247 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
248 | self.assertEqual(payment.p_level, 200) |
---|
249 | self.assertEqual(payment.p_session, 2005) |
---|
250 | self.assertEqual(payment.amount_auth, 34090.0) |
---|
251 | self.assertEqual(payment.p_item, u'CERT1') |
---|
252 | self.assertEqual(error, None) |
---|
253 | |
---|
254 | configuration.penalty_ug = 5000.0 |
---|
255 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
256 | self.assertEqual(payment.amount_auth, 39090.0) |
---|
257 | self.assertEqual(error, None) |
---|
258 | |
---|
259 | error, payment = utils.setPaymentDetails('clearance',self.student) |
---|
260 | self.assertEqual(payment.p_level, 100) |
---|
261 | self.assertEqual(payment.p_session, 2004) |
---|
262 | self.assertEqual(payment.amount_auth, 120.0) |
---|
263 | self.assertEqual(payment.p_item, u'CERT1') |
---|
264 | self.assertEqual(error, None) |
---|
265 | |
---|
266 | error, payment = utils.setPaymentDetails('carryover1',self.student) |
---|
267 | self.assertEqual(payment.p_level, 100) |
---|
268 | self.assertEqual(payment.p_session, 2004) |
---|
269 | self.assertEqual(payment.amount_auth, 6000.0) |
---|
270 | self.assertEqual(payment.p_item, u'One Carry-Over') |
---|
271 | self.assertEqual(payment.p_category, 'carryover1') |
---|
272 | self.assertEqual(error, None) |
---|
273 | |
---|
274 | error, payment = utils.setPaymentDetails('carryover2',self.student) |
---|
275 | self.assertEqual(payment.p_level, 100) |
---|
276 | self.assertEqual(payment.p_session, 2004) |
---|
277 | self.assertEqual(payment.amount_auth, 10000.0) |
---|
278 | self.assertEqual(payment.p_item, u'Two Carry-Overs') |
---|
279 | self.assertEqual(payment.p_category, 'carryover2') |
---|
280 | self.assertEqual(error, None) |
---|
281 | |
---|
282 | error, payment = utils.setPaymentDetails('carryover3',self.student) |
---|
283 | self.assertEqual(payment.p_level, 100) |
---|
284 | self.assertEqual(payment.p_session, 2004) |
---|
285 | self.assertEqual(payment.amount_auth, 15000.0) |
---|
286 | self.assertEqual(payment.p_item, u'Three Carry-Overs') |
---|
287 | self.assertEqual(payment.p_category, 'carryover3') |
---|
288 | self.assertEqual(error, None) |
---|
289 | |
---|
290 | error, payment = utils.setPaymentDetails('hostel_maintenance',self.student) |
---|
291 | self.assertEqual(payment.p_level, 100) |
---|
292 | self.assertEqual(payment.p_session, 2004) |
---|
293 | self.assertEqual(payment.amount_auth, 876.0) |
---|
294 | self.assertEqual(payment.p_item, u'My bed coordinates') |
---|
295 | self.assertEqual(error, None) |
---|
296 | |
---|
297 | self.app['hostels']['hall-1'].maint_fee = 0.0 |
---|
298 | error, payment = utils.setPaymentDetails('hostel_maintenance',self.student) |
---|
299 | self.assertEqual(payment.p_level, 100) |
---|
300 | self.assertEqual(payment.p_session, 2004) |
---|
301 | self.assertEqual(payment.amount_auth, 180.0) |
---|
302 | self.assertEqual(payment.p_item, u'My bed coordinates') |
---|
303 | self.assertEqual(error, None) |
---|
304 | |
---|
305 | error, payment = utils.setPaymentDetails('bed_allocation',self.student) |
---|
306 | self.assertEqual(payment.p_level, 100) |
---|
307 | self.assertEqual(payment.p_session, 2004) |
---|
308 | self.assertEqual(payment.amount_auth, 150.0) |
---|
309 | self.assertEqual(payment.p_item, u'') |
---|
310 | self.assertEqual(error, None) |
---|
311 | |
---|
312 | error, payment = utils.setPaymentDetails('certificate',self.student) |
---|
313 | self.assertEqual(payment.p_level, 100) |
---|
314 | self.assertEqual(payment.p_session, 2004) |
---|
315 | self.assertEqual(payment.amount_auth, 444.0) |
---|
316 | self.assertEqual(payment.p_item, u'') |
---|
317 | self.assertEqual(payment.p_category, 'certificate') |
---|
318 | self.assertEqual(error, None) |
---|
319 | |
---|
320 | error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100) |
---|
321 | self.assertEqual(error, u'Previous session payment not yet implemented.') |
---|
322 | return |
---|
323 | |
---|
324 | def test_student_start_clearance(self): |
---|
325 | self.browser.open(self.login_path) |
---|
326 | self.browser.getControl(name="form.login").value = self.student_id |
---|
327 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
328 | self.browser.getControl("Login").click() |
---|
329 | |
---|
330 | IWorkflowInfo(self.student).fireTransition('admit') |
---|
331 | self.browser.open(self.student_path + '/change_portrait') |
---|
332 | image = open(SAMPLE_IMAGE, 'rb') |
---|
333 | ctrl = self.browser.getControl(name='passportuploadedit') |
---|
334 | file_ctrl = ctrl.mech_control |
---|
335 | file_ctrl.add_file(image, filename='my_photo.jpg') |
---|
336 | self.browser.getControl( |
---|
337 | name='upload_passportuploadedit').click() |
---|
338 | self.browser.open(self.student_path + '/start_clearance') |
---|
339 | # In KwaraPoly the students can just start clearance without entering |
---|
340 | # an activation code. |
---|
341 | self.browser.getControl("Start clearance now").click() |
---|
342 | self.assertMatches('...Clearance process has been started...', |
---|
343 | self.browser.contents) |
---|
344 | |
---|
345 | def test_change_passport(self): |
---|
346 | self.browser.open(self.login_path) |
---|
347 | self.browser.getControl(name="form.login").value = self.student_id |
---|
348 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
349 | self.browser.getControl("Login").click() |
---|
350 | |
---|
351 | IWorkflowState(self.student).setState('cleared') |
---|
352 | self.browser.open(self.student_path + '/change_portrait') |
---|
353 | image = open(SAMPLE_IMAGE, 'rb') |
---|
354 | ctrl = self.browser.getControl(name='passportuploadedit') |
---|
355 | file_ctrl = ctrl.mech_control |
---|
356 | file_ctrl.add_file(image, filename='my_photo.jpg') |
---|
357 | self.browser.getControl( |
---|
358 | name='upload_passportuploadedit').click() |
---|
359 | |
---|
360 | |
---|
361 | def test_student_accommodation(self): |
---|
362 | del self.student['accommodation']['2004'] |
---|
363 | # Login |
---|
364 | self.browser.open(self.login_path) |
---|
365 | self.browser.getControl(name="form.login").value = self.student_id |
---|
366 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
367 | self.browser.getControl("Login").click() |
---|
368 | |
---|
369 | # Students can book accommodation without AC ... |
---|
370 | self.browser.open(self.acco_path) |
---|
371 | IWorkflowInfo(self.student).fireTransition('admit') |
---|
372 | self.browser.getControl("Book accommodation").click() |
---|
373 | self.assertFalse('Activation Code:' in self.browser.contents) |
---|
374 | self.browser.getControl("Create bed ticket").click() |
---|
375 | # Bed is randomly selected but, since there is only |
---|
376 | # one bed for this student, we know that |
---|
377 | self.assertMatches('...Hall 1, Block A, Room 101, Bed A...', |
---|
378 | self.browser.contents) |
---|
379 | return |
---|
380 | |
---|
381 | def test_no_beds_for_iot(self): |
---|
382 | self.app['faculties']['fac1'].code = 'IOT' |
---|
383 | del self.student['accommodation']['2004'] |
---|
384 | # Login |
---|
385 | self.browser.open(self.login_path) |
---|
386 | self.browser.getControl(name="form.login").value = self.student_id |
---|
387 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
388 | self.browser.getControl("Login").click() |
---|
389 | |
---|
390 | self.browser.open(self.acco_path) |
---|
391 | IWorkflowInfo(self.student).fireTransition('admit') |
---|
392 | self.browser.getControl("Book accommodation").click() |
---|
393 | self.browser.getControl("Create bed ticket").click() |
---|
394 | self.assertTrue('There is no free bed in your category iot_male_fr.' in |
---|
395 | self.browser.contents) |
---|
396 | return |
---|
397 | |
---|
398 | def test_admission_pdf_slips(self): |
---|
399 | # Login |
---|
400 | self.browser.open(self.login_path) |
---|
401 | self.browser.getControl(name="form.login").value = self.student_id |
---|
402 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
403 | self.browser.getControl("Login").click() |
---|
404 | # admission slip |
---|
405 | IWorkflowState(self.student).setState('school fee paid') |
---|
406 | self.browser.open(self.student_path) |
---|
407 | self.browser.getLink("Download admission letter").click() |
---|
408 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
409 | self.assertEqual(self.browser.headers['Content-Type'], |
---|
410 | 'application/pdf') |
---|
411 | path = os.path.join(samples_dir(), 'admission_slip.pdf') |
---|
412 | open(path, 'wb').write(self.browser.contents) |
---|
413 | print "Sample PDF admission_slip_slip.pdf written to %s" % path |
---|
414 | self.browser.open(self.student_path) |
---|
415 | self.assertRaises( |
---|
416 | LinkNotFoundError, self.browser.getLink, 'Download admission notification') |
---|
417 | self.browser.open(self.student_path + '/admission_notification.pdf') |
---|
418 | self.assertTrue('Not allowed' in self.browser.contents) |
---|
419 | # admission notification |
---|
420 | IWorkflowState(self.student).setState('cleared') |
---|
421 | self.browser.open(self.student_path) |
---|
422 | self.browser.getLink("Download admission notification").click() |
---|
423 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
424 | self.assertEqual(self.browser.headers['Content-Type'], |
---|
425 | 'application/pdf') |
---|
426 | path = os.path.join(samples_dir(), 'admission_notification.pdf') |
---|
427 | open(path, 'wb').write(self.browser.contents) |
---|
428 | print "Sample PDF admission_notification.pdf written to %s" % path |
---|
429 | self.browser.open(self.student_path) |
---|
430 | self.assertRaises( |
---|
431 | LinkNotFoundError, self.browser.getLink, 'Download admission letter') |
---|
432 | self.browser.open(self.student_path + '/admission_slip.pdf') |
---|
433 | self.assertTrue('Not allowed' in self.browser.contents) |
---|
434 | return |
---|
435 | |
---|
436 | def test_registration_pdf_slips(self): |
---|
437 | # Student cant login if their password is not set |
---|
438 | IWorkflowState(self.student).setState('school fee paid') |
---|
439 | self.browser.open(self.login_path) |
---|
440 | self.browser.getControl(name="form.login").value = self.student_id |
---|
441 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
442 | self.browser.getControl("Login").click() |
---|
443 | self.browser.getLink("Course of Study").click() |
---|
444 | self.browser.getLink("Add course list").click() |
---|
445 | self.assertMatches('...Add current level 100 (Year 1)...', |
---|
446 | self.browser.contents) |
---|
447 | self.browser.getControl("Create course list now").click() |
---|
448 | # A level with one course ticket was created |
---|
449 | self.browser.getLink("100").click() |
---|
450 | self.browser.getLink("Download course profile slip").click() |
---|
451 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
452 | self.assertEqual(self.browser.headers['Content-Type'], |
---|
453 | 'application/pdf') |
---|
454 | path = os.path.join(samples_dir(), 'course_registration_slip.pdf') |
---|
455 | open(path, 'wb').write(self.browser.contents) |
---|
456 | print "Sample PDF course_registration_slip.pdf written to %s" % path |
---|
457 | |
---|
458 | self.browser.open(self.student_path) |
---|
459 | self.browser.getLink("Download registration form").click() |
---|
460 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
461 | self.assertEqual(self.browser.headers['Content-Type'], |
---|
462 | 'application/pdf') |
---|
463 | path = os.path.join(samples_dir(), 'registration_slip.pdf') |
---|
464 | open(path, 'wb').write(self.browser.contents) |
---|
465 | print "Sample PDF registration_form.pdf written to %s" % path |
---|
466 | |
---|
467 | return |
---|
468 | |
---|
469 | def test_payment_disabled(self): |
---|
470 | IWorkflowState(self.student).setState('returning') |
---|
471 | configuration = createObject('waeup.SessionConfiguration') |
---|
472 | configuration.academic_session = 2005 |
---|
473 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
474 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
475 | self.browser.open(self.payments_path) |
---|
476 | self.browser.getLink("Add current session payment ticket").click() |
---|
477 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
478 | self.browser.getControl("Create ticket").click() |
---|
479 | self.assertMatches('...ticket created...', |
---|
480 | self.browser.contents) |
---|
481 | self.app['configuration']['2005'].payment_disabled = ['sf_all'] |
---|
482 | self.browser.getLink("Add current session payment ticket").click() |
---|
483 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
484 | self.browser.getControl("Create ticket").click() |
---|
485 | self.assertMatches('...Payment temporarily disabled...', |
---|
486 | self.browser.contents) |
---|
487 | self.app['configuration']['2005'].payment_disabled = ['sf_non_pg'] |
---|
488 | # Non-PG students can't pay ... |
---|
489 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
490 | self.browser.getControl("Create ticket").click() |
---|
491 | self.assertMatches('...Payment temporarily disabled...', |
---|
492 | self.browser.contents) |
---|
493 | # ... but PG can pay. |
---|
494 | self.certificate.study_mode = 'pg_ft' |
---|
495 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
496 | self.browser.getControl("Create ticket").click() |
---|
497 | self.assertMatches('...ticket created...', |
---|
498 | self.browser.contents) |
---|
499 | return |
---|
500 | |
---|
501 | def test_student_course_registration(self): |
---|
502 | # Student cant login if their password is not set |
---|
503 | IWorkflowState(self.student).setState('school fee paid') |
---|
504 | self.student['studycourse'].current_level = 200 |
---|
505 | self.browser.open(self.login_path) |
---|
506 | self.browser.getControl(name="form.login").value = self.student_id |
---|
507 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
508 | self.browser.getControl("Login").click() |
---|
509 | self.browser.open(self.student_path + '/studycourse/add') |
---|
510 | # Now students can add the current study level |
---|
511 | self.assertMatches('...Add current level 200 (Year 2)...', |
---|
512 | self.browser.contents) |
---|
513 | self.browser.getControl("Create course list now").click() |
---|
514 | self.browser.getLink("200").click() |
---|
515 | self.browser.getLink("Edit course list").click() |
---|
516 | self.browser.getLink("here").click() |
---|
517 | self.browser.getControl(name="form.course").value = ['COURSE1'] |
---|
518 | self.course.credits = 100000 |
---|
519 | self.browser.getControl("Add course ticket").click() |
---|
520 | self.assertFalse( |
---|
521 | 'Total credits exceed ' in self.browser.contents) |
---|
522 | self.browser.getControl("Register course list").click() |
---|
523 | self.assertTrue( |
---|
524 | 'Course list has been registered' in self.browser.contents) |
---|
525 | self.assertEqual(self.student.state, 'courses registered') |
---|
526 | return |
---|
527 | |
---|
528 | def test_set_matric_number(self): |
---|
529 | # Login as student |
---|
530 | self.browser.open(self.login_path) |
---|
531 | IWorkflowState(self.student).setState('school fee paid') |
---|
532 | self.browser.open(self.login_path) |
---|
533 | self.browser.getControl(name="form.login").value = self.student_id |
---|
534 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
535 | self.browser.getControl("Login").click() |
---|
536 | self.assertRaises( |
---|
537 | LinkNotFoundError, |
---|
538 | self.browser.getLink, 'Get Matriculation Number') |
---|
539 | self.student.matric_number = None |
---|
540 | self.student['studycourse'].entry_mode = 'nd_ft' |
---|
541 | self.student['studycourse'].entry_session = 2014 |
---|
542 | self.browser.open(self.student_path) |
---|
543 | self.assertRaises( |
---|
544 | LinkNotFoundError, |
---|
545 | self.browser.getLink, 'Get Matriculation Number') |
---|
546 | self.student['studycourse'].entry_session = 2015 |
---|
547 | self.browser.open(self.student_path) |
---|
548 | self.browser.getLink("Get Matriculation Number").click() |
---|
549 | self.assertTrue('Matriculation number ND/15/dep1/FT/001 assigned.' |
---|
550 | in self.browser.contents) |
---|
551 | self.assertEqual(self.student.matric_number, 'ND/15/dep1/FT/001') |
---|
552 | self.assertRaises( |
---|
553 | LinkNotFoundError, |
---|
554 | self.browser.getLink, 'Get Matriculation Number') |
---|
555 | # Setting matric number is logged. |
---|
556 | logfile = os.path.join( |
---|
557 | self.app['datacenter'].storage, 'logs', 'students.log') |
---|
558 | logcontent = open(logfile).read() |
---|
559 | self.assertTrue('W1000000 - waeup.kwarapoly.students.browser.StudentGetMatricNumberView - ' |
---|
560 | 'W1000000 - ND/15/dep1/FT/001 assigned' in logcontent) |
---|
561 | return |
---|
562 | |
---|
563 | # deactivated on 5/11/15, see ticket 129 |
---|
564 | def xxx_test_student_fileupload(self): |
---|
565 | # Students can edit clearance data |
---|
566 | IWorkflowState(self.student).setState('clearance started') |
---|
567 | self.browser.open(self.login_path) |
---|
568 | self.browser.getControl(name="form.login").value = self.student_id |
---|
569 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
570 | self.browser.getControl("Login").click() |
---|
571 | self.browser.getLink("Clearance Data").click() |
---|
572 | self.browser.getLink("Edit").click() |
---|
573 | self.browser.getControl("Save and request clearance").click() |
---|
574 | self.assertMatches('...Required input is missing...', |
---|
575 | self.browser.contents) |
---|
576 | self.student.nationality = u'DE' |
---|
577 | self.browser.open(self.edit_clearance_path) |
---|
578 | self.browser.getControl("Save and request clearance").click() |
---|
579 | self.assertTrue( |
---|
580 | 'Missing: Birth Certificate, Acceptance Letter, LGA Identification, ' |
---|
581 | 'First Sitting Result, Result Statement, Guarantor/Referee Letter, ' |
---|
582 | 'Affidavit of Good Conduct' |
---|
583 | in self.browser.contents) |
---|
584 | # Students can upload documents |
---|
585 | ctrl = self.browser.getControl(name='birthcertificateupload') |
---|
586 | file_obj = open(SAMPLE_IMAGE, 'rb') |
---|
587 | file_ctrl = ctrl.mech_control |
---|
588 | file_ctrl.add_file(file_obj, filename='my_birth_certificate.jpg') |
---|
589 | self.browser.getControl( |
---|
590 | name='upload_birthcertificateupload').click() |
---|
591 | self.assertTrue( |
---|
592 | 'href="http://localhost/app/students/W1000000/birth_certificate"' |
---|
593 | in self.browser.contents) |
---|
594 | # The list of missing files is now slightly shorter |
---|
595 | self.browser.getControl("Save and request clearance").click() |
---|
596 | self.assertTrue( |
---|
597 | 'Missing: Acceptance Letter, LGA Identification, ' |
---|
598 | 'First Sitting Result, Result Statement, Guarantor/Referee Letter, ' |
---|
599 | 'Affidavit of Good Conduct' |
---|
600 | in self.browser.contents) |
---|
601 | return |
---|