1 | ## $Id: test_browser.py 13406 2015-11-07 12:05:48Z 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 | import pytz |
---|
22 | import grok |
---|
23 | from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState |
---|
24 | from datetime import datetime, timedelta, date |
---|
25 | from mechanize import LinkNotFoundError |
---|
26 | from hurry.workflow.interfaces import IWorkflowState |
---|
27 | from zope.component.hooks import setSite, clearSite |
---|
28 | from zope.component import getUtility, createObject, queryUtility |
---|
29 | from zope.catalog.interfaces import ICatalog |
---|
30 | from waeup.kofa.app import University |
---|
31 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
32 | from waeup.kofa.students.accommodation import BedTicket |
---|
33 | from waeup.kofa.testing import FunctionalTestCase |
---|
34 | from waeup.kofa.browser.tests.test_pdf import samples_dir |
---|
35 | from waeup.aaue.testing import FunctionalLayer |
---|
36 | |
---|
37 | SAMPLE_IMAGE = os.path.join(os.path.dirname(__file__), 'test_image.jpg') |
---|
38 | |
---|
39 | |
---|
40 | class StudentProcessorTest(FunctionalTestCase): |
---|
41 | """Perform some batching tests. |
---|
42 | """ |
---|
43 | |
---|
44 | layer = FunctionalLayer |
---|
45 | |
---|
46 | def setUp(self): |
---|
47 | super(StudentProcessorTest, self).setUp() |
---|
48 | # Setup a sample site for each test |
---|
49 | app = University() |
---|
50 | self.dc_root = tempfile.mkdtemp() |
---|
51 | app['datacenter'].setStoragePath(self.dc_root) |
---|
52 | |
---|
53 | # Prepopulate the ZODB... |
---|
54 | self.getRootFolder()['app'] = app |
---|
55 | # we add the site immediately after creation to the |
---|
56 | # ZODB. Catalogs and other local utilities are not setup |
---|
57 | # before that step. |
---|
58 | self.app = self.getRootFolder()['app'] |
---|
59 | # Set site here. Some of the following setup code might need |
---|
60 | # to access grok.getSite() and should get our new app then |
---|
61 | setSite(app) |
---|
62 | |
---|
63 | |
---|
64 | def tearDown(self): |
---|
65 | super(StudentProcessorTest, self).tearDown() |
---|
66 | shutil.rmtree(self.workdir) |
---|
67 | shutil.rmtree(self.dc_root) |
---|
68 | clearSite() |
---|
69 | return |
---|
70 | |
---|
71 | class OfficerUITests(StudentsFullSetup): |
---|
72 | # Tests for Student class views and pages |
---|
73 | |
---|
74 | layer = FunctionalLayer |
---|
75 | |
---|
76 | def test_gpa_calculation(self): |
---|
77 | studylevel = createObject(u'waeup.StudentStudyLevel') |
---|
78 | studylevel.level = 100 |
---|
79 | studylevel.level_session = 2005 |
---|
80 | self.student['studycourse'].entry_mode = 'ug_ft' |
---|
81 | self.student['studycourse'].addStudentStudyLevel( |
---|
82 | self.certificate, studylevel) |
---|
83 | # First course has been added automatically. |
---|
84 | # Set score. |
---|
85 | studylevel['COURSE1'].score = 55 |
---|
86 | # GPA is 3.0. |
---|
87 | self.assertEqual(studylevel.gpa_params[0], 3.0) |
---|
88 | courseticket = createObject('waeup.CourseTicket') |
---|
89 | courseticket.code = 'ANYCODE' |
---|
90 | courseticket.title = u'Any TITLE' |
---|
91 | courseticket.credits = 13 |
---|
92 | courseticket.score = 66 |
---|
93 | courseticket.semester = 1 |
---|
94 | courseticket.dcode = u'ANYDCODE' |
---|
95 | courseticket.fcode = u'ANYFCODE' |
---|
96 | studylevel['COURSE2'] = courseticket |
---|
97 | # total credits |
---|
98 | self.assertEqual(self.student['studycourse']['100'].gpa_params[1], 23) |
---|
99 | # weigheted credits = 3 * 10 + 4 * 13 |
---|
100 | self.assertEqual(self.student['studycourse']['100'].gpa_params[2], 82.0) |
---|
101 | # sgpa = 82 / 23 |
---|
102 | self.assertEqual(self.student['studycourse']['100'].gpa_params[0], 3.565) |
---|
103 | return |
---|
104 | |
---|
105 | def test_manage_payments(self): |
---|
106 | # Add missing configuration data |
---|
107 | self.app['configuration']['2004'].gown_fee = 150.0 |
---|
108 | self.app['configuration']['2004'].transfer_fee = 90.0 |
---|
109 | self.app['configuration']['2004'].booking_fee = 150.0 |
---|
110 | self.app['configuration']['2004'].maint_fee = 180.0 |
---|
111 | self.app['configuration']['2004'].late_fee = 80.0 |
---|
112 | |
---|
113 | # Managers can add online payment tickets |
---|
114 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
115 | self.browser.open(self.payments_path) |
---|
116 | self.browser.getLink("Add current session payment ticket").click() |
---|
117 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
118 | self.browser.getControl("Create ticket").click() |
---|
119 | self.assertMatches('...Wrong state...', |
---|
120 | self.browser.contents) |
---|
121 | IWorkflowState(self.student).setState('cleared') |
---|
122 | self.browser.open(self.payments_path + '/addop') |
---|
123 | self.browser.getControl("Create ticket").click() |
---|
124 | self.assertMatches('...Amount could not be determined...', |
---|
125 | self.browser.contents) |
---|
126 | #self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
127 | # Accepotance fee must be paid first |
---|
128 | #self.browser.getControl("Create ticket").click() |
---|
129 | #self.assertMatches('...Please pay acceptance fee first...', |
---|
130 | # self.browser.contents) |
---|
131 | self.app['configuration']['2004'].clearance_fee = 666.0 |
---|
132 | self.browser.getControl(name="form.p_category").value = ['clearance'] |
---|
133 | self.browser.getControl("Create ticket").click() |
---|
134 | ctrl = self.browser.getControl(name='val_id') |
---|
135 | cpt_value = ctrl.options[0] |
---|
136 | # School fee payment ticket can be added ... |
---|
137 | self.student['studycourse'].certificate.school_fee_1 = 6666.0 |
---|
138 | self.student.nationality = u'NG' |
---|
139 | self.browser.open(self.payments_path + '/addop') |
---|
140 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
141 | self.browser.getControl("Create ticket").click() |
---|
142 | self.assertMatches('...ticket created...', |
---|
143 | self.browser.contents) |
---|
144 | # ... but not paid through the query_history page. |
---|
145 | ctrl = self.browser.getControl(name='val_id') |
---|
146 | sfpt_value = ctrl.options[1] |
---|
147 | self.student['studycourse'].entry_session = 2013 |
---|
148 | self.browser.open(self.payments_path + '/' + sfpt_value) |
---|
149 | self.browser.getLink("Query eTranzact History").click() |
---|
150 | self.assertMatches('...alert-danger">Please pay acceptance fee first...', |
---|
151 | self.browser.contents) |
---|
152 | # If clearance/acceptance fee is paid ... |
---|
153 | self.student['payments'][cpt_value].approveStudentPayment() |
---|
154 | self.browser.getLink("Query eTranzact History").click() |
---|
155 | # ... query_history page is accessible. |
---|
156 | self.assertMatches( |
---|
157 | '...<h1 class="kofa-content-label">Requery eTranzact History</h1>...', |
---|
158 | self.browser.contents) |
---|
159 | # Managers can open school fee payment slip |
---|
160 | self.browser.open(self.payments_path + '/' + sfpt_value) |
---|
161 | self.browser.getLink("Download payment slip").click() |
---|
162 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
163 | self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf') |
---|
164 | # If school fee ticket is paid, the student is automatically set to |
---|
165 | # school fee paid... |
---|
166 | ticket = self.student['payments'][sfpt_value].approveStudentPayment() |
---|
167 | self.assertEqual(self.student.state, 'school fee paid') |
---|
168 | # ... no further school fee ticket can be added. |
---|
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('...Wrong state...', |
---|
173 | self.browser.contents) |
---|
174 | self.browser.open(self.payments_path + '/addop') |
---|
175 | self.browser.getControl(name="form.p_category").value = ['late_registration'] |
---|
176 | self.browser.getControl("Create ticket").click() |
---|
177 | self.assertMatches('...ticket created...', |
---|
178 | self.browser.contents) |
---|
179 | |
---|
180 | def deactivated_test_for_instalment_payments(self): |
---|
181 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
182 | self.browser.open(self.payments_path) |
---|
183 | self.browser.open(self.payments_path + '/addop') |
---|
184 | self.browser.getControl(name="form.p_category").value = ['schoolfee_1'] |
---|
185 | self.browser.getControl("Create ticket").click() |
---|
186 | self.assertMatches('...ticket created...', |
---|
187 | self.browser.contents) |
---|
188 | # We can't add the 2nd instalment ticket because the |
---|
189 | # first one has not yet been approved. |
---|
190 | self.browser.open(self.payments_path + '/addop') |
---|
191 | self.browser.getControl(name="form.p_category").value = ['schoolfee_2'] |
---|
192 | self.browser.getControl("Create ticket").click() |
---|
193 | self.assertMatches('...1st school fee instalment has not yet been paid...', |
---|
194 | self.browser.contents) |
---|
195 | # Ok, then we approve the first instalment ... |
---|
196 | self.browser.open(self.payments_path) |
---|
197 | ctrl = self.browser.getControl(name='val_id') |
---|
198 | p_id = ctrl.options[0] |
---|
199 | self.browser.open(self.payments_path + '/' + p_id + '/approve') |
---|
200 | # ... add the second instalment ... |
---|
201 | self.browser.open(self.payments_path + '/addop') |
---|
202 | self.browser.getControl(name="form.p_category").value = ['schoolfee_2'] |
---|
203 | self.browser.getControl("Create ticket").click() |
---|
204 | self.assertMatches('...ticket created...', |
---|
205 | self.browser.contents) |
---|
206 | # ... approve the second instalment ... |
---|
207 | ctrl = self.browser.getControl(name='val_id') |
---|
208 | p_id = ctrl.options[1] |
---|
209 | self.browser.open(self.payments_path + '/' + p_id + '/approve') |
---|
210 | # ... and finally add the 1st instalment for the next session |
---|
211 | # provided that student is returning. |
---|
212 | IWorkflowState(self.student).setState('returning') |
---|
213 | self.browser.open(self.payments_path + '/addop') |
---|
214 | self.browser.getControl(name="form.p_category").value = ['schoolfee_1'] |
---|
215 | self.browser.getControl("Create ticket").click() |
---|
216 | self.assertMatches('...Session configuration object is not...', |
---|
217 | self.browser.contents) |
---|
218 | # Uups, we forgot to add a session configuration for next session |
---|
219 | configuration = createObject('waeup.SessionConfiguration') |
---|
220 | configuration.academic_session = 2005 |
---|
221 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
222 | self.app['configuration']['2005'].school_base = 7777.0 |
---|
223 | self.browser.open(self.payments_path + '/addop') |
---|
224 | self.browser.getControl(name="form.p_category").value = ['schoolfee_1'] |
---|
225 | self.browser.getControl("Create ticket").click() |
---|
226 | self.assertMatches('...ticket created...', |
---|
227 | self.browser.contents) |
---|
228 | # If the session configuration doesn't exist an error message will |
---|
229 | # be shown. No other requirement is being checked. |
---|
230 | del self.app['configuration']['2004'] |
---|
231 | self.browser.open(self.payments_path) |
---|
232 | self.browser.getLink("Add current session payment ticket").click() |
---|
233 | self.browser.getControl("Create ticket").click() |
---|
234 | self.assertMatches('...Session configuration object is not...', |
---|
235 | self.browser.contents) |
---|
236 | |
---|
237 | def test_manage_payments_bypass_ac_creation(self): |
---|
238 | self.student['studycourse'].certificate.school_fee_1 = 6666.0 |
---|
239 | self.student.nationality = u'NG' |
---|
240 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
241 | self.browser.open(self.payments_path) |
---|
242 | IWorkflowState(self.student).setState('cleared') |
---|
243 | self.browser.getLink("Add current session payment ticket").click() |
---|
244 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
245 | self.browser.getControl("Create ticket").click() |
---|
246 | ctrl = self.browser.getControl(name='val_id') |
---|
247 | value = ctrl.options[0] |
---|
248 | self.browser.getLink(value).click() |
---|
249 | payment_url = self.browser.url |
---|
250 | logfile = os.path.join( |
---|
251 | self.app['datacenter'].storage, 'logs', 'students.log') |
---|
252 | # The ticket can be found in the payments_catalog |
---|
253 | cat = queryUtility(ICatalog, name='payments_catalog') |
---|
254 | results = list(cat.searchResults(p_state=('unpaid', 'unpaid'))) |
---|
255 | self.assertTrue(len(results), 1) |
---|
256 | self.assertTrue(results[0] is self.student['payments'][value]) |
---|
257 | # Managers can approve the payment |
---|
258 | self.browser.open(payment_url) |
---|
259 | self.browser.getLink("Approve payment").click() |
---|
260 | self.assertMatches('...Payment approved...', |
---|
261 | self.browser.contents) |
---|
262 | # Approval is logged in students.log ... |
---|
263 | logcontent = open(logfile).read() |
---|
264 | self.assertTrue( |
---|
265 | 'zope.mgr - students.browser.OnlinePaymentApproveView ' |
---|
266 | '- E1000000 - schoolfee payment approved' |
---|
267 | in logcontent) |
---|
268 | # ... and in payments.log |
---|
269 | logfile = os.path.join( |
---|
270 | self.app['datacenter'].storage, 'logs', 'payments.log') |
---|
271 | logcontent = open(logfile).read() |
---|
272 | self.assertTrue( |
---|
273 | '"zope.mgr",E1000000,%s,schoolfee,6666.0,AP,,,,,,\n' % value |
---|
274 | in logcontent) |
---|
275 | # Student is in state school fee paid, no activation |
---|
276 | # code was necessary. |
---|
277 | self.assertEqual(self.student.state, 'school fee paid') |
---|
278 | self.assertEqual(len(self.app['accesscodes']['SFE-0']),0) |
---|
279 | return |
---|
280 | |
---|
281 | class StudentUITests(StudentsFullSetup): |
---|
282 | """Tests for customized student class views and pages |
---|
283 | """ |
---|
284 | |
---|
285 | layer = FunctionalLayer |
---|
286 | |
---|
287 | def setUp(self): |
---|
288 | super(StudentUITests, self).setUp() |
---|
289 | |
---|
290 | bedticket = BedTicket() |
---|
291 | bedticket.booking_session = 2004 |
---|
292 | bedticket.bed_type = u'any bed type' |
---|
293 | bedticket.bed = self.app['hostels']['hall-1']['hall-1_A_101_A'] |
---|
294 | bedticket.bed_coordinates = u'My bed coordinates' |
---|
295 | self.student['accommodation'].addBedTicket(bedticket) |
---|
296 | |
---|
297 | def test_student_payments(self): |
---|
298 | self.certificate.study_mode = 'ug_ft' |
---|
299 | self.student['studycourse'].entry_session = 2013 |
---|
300 | self.student['studycourse'].certificate.school_fee_1 = 50250.0 |
---|
301 | self.app['configuration']['2004'].union_fee = 1000.0 |
---|
302 | self.app['configuration']['2004'].welfare_fee = 500.0 |
---|
303 | self.student.nationality = u'NG' |
---|
304 | # Login |
---|
305 | IWorkflowState(self.student).setState('cleared') |
---|
306 | self.browser.open(self.login_path) |
---|
307 | self.browser.getControl(name="form.login").value = self.student_id |
---|
308 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
309 | self.browser.getControl("Login").click() |
---|
310 | self.browser.open(self.student_path + '/payments') |
---|
311 | self.browser.getLink("Add current session payment ticket").click() |
---|
312 | self.browser.getControl(name="form.p_category").value = ['schoolfee_incl'] |
---|
313 | self.browser.getControl("Create ticket").click() |
---|
314 | self.assertTrue('ticket created' in self.browser.contents) |
---|
315 | ctrl = self.browser.getControl(name='val_id') |
---|
316 | value = ctrl.options[0] |
---|
317 | self.browser.getLink(value).click() |
---|
318 | self.assertTrue('Amount Authorized' in self.browser.contents) |
---|
319 | self.assertEqual(self.student['payments'][value].amount_auth, 51250.0) |
---|
320 | self.browser.open(self.browser.url + '/payment_slip.pdf') |
---|
321 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
322 | self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf') |
---|
323 | path = os.path.join(samples_dir(), 'payment_slip.pdf') |
---|
324 | open(path, 'wb').write(self.browser.contents) |
---|
325 | print "Sample PDF payment_slip.pdf written to %s" % path |
---|
326 | return |
---|
327 | |
---|
328 | def test_late_registration(self): |
---|
329 | # Login |
---|
330 | delta = timedelta(days=10) |
---|
331 | self.app['configuration'][ |
---|
332 | '2004'].coursereg_deadline = datetime.now(pytz.utc) - delta |
---|
333 | IWorkflowState(self.student).setState('school fee paid') |
---|
334 | # Current session is 2004. Here we test course registration for |
---|
335 | # returning students. |
---|
336 | self.student['studycourse'].entry_session = 2003 |
---|
337 | self.browser.open(self.login_path) |
---|
338 | self.browser.getControl(name="form.login").value = self.student_id |
---|
339 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
340 | self.browser.getControl("Login").click() |
---|
341 | self.browser.open(self.payments_path) |
---|
342 | self.browser.open(self.payments_path + '/addop') |
---|
343 | self.browser.getControl(name="form.p_category").value = ['late_registration'] |
---|
344 | self.browser.getControl("Create ticket").click() |
---|
345 | self.assertMatches('...ticket created...', |
---|
346 | self.browser.contents) |
---|
347 | self.browser.open(self.payments_path) |
---|
348 | ctrl = self.browser.getControl(name='val_id') |
---|
349 | value = ctrl.options[0] |
---|
350 | self.browser.getLink("Study Course").click() |
---|
351 | self.browser.getLink("Add course list").click() |
---|
352 | self.assertMatches('...Add current level 100 (Year 1)...', |
---|
353 | self.browser.contents) |
---|
354 | self.browser.getControl("Create course list now").click() |
---|
355 | self.browser.getLink("100").click() |
---|
356 | self.browser.getLink("Edit course list").click() |
---|
357 | self.browser.getControl("Register course list").click() |
---|
358 | self.assertTrue('Course registration has ended. Please pay' in self.browser.contents) |
---|
359 | self.student['payments'][value].approve() |
---|
360 | self.browser.getControl("Register course list").click() |
---|
361 | self.assertTrue('Course list has been registered' in self.browser.contents) |
---|
362 | self.assertEqual(self.student.state, 'courses registered') |
---|
363 | # Reset student and check if fresh students are always allowed to |
---|
364 | # register courses. |
---|
365 | self.student['studycourse'].entry_session = 2004 |
---|
366 | del self.student['payments'][value] |
---|
367 | IWorkflowState(self.student).setState('school fee paid') |
---|
368 | self.browser.open(self.studycourse_path + '/100/edit') |
---|
369 | self.browser.getControl("Register course list").click() |
---|
370 | self.assertTrue('Course list has been registered' in self.browser.contents) |
---|
371 | return |
---|
372 | |
---|
373 | |
---|
374 | def deactivated_test_student_course_registration(self): |
---|
375 | # Add more courses |
---|
376 | self.course2 = createObject('waeup.Course') |
---|
377 | self.course2.code = 'COURSE2' |
---|
378 | self.course2.semester = 2 |
---|
379 | self.course2.credits = 10 |
---|
380 | self.course2.passmark = 40 |
---|
381 | self.app['faculties']['fac1']['dep1'].courses.addCourse( |
---|
382 | self.course2) |
---|
383 | self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCertCourse( |
---|
384 | self.course2, level=100) |
---|
385 | self.course3 = createObject('waeup.Course') |
---|
386 | self.course3.code = 'COURSE3' |
---|
387 | self.course3.semester = 3 |
---|
388 | self.course3.credits = 10 |
---|
389 | self.course3.passmark = 40 |
---|
390 | self.app['faculties']['fac1']['dep1'].courses.addCourse( |
---|
391 | self.course3) |
---|
392 | self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCertCourse( |
---|
393 | self.course3, level=100) |
---|
394 | |
---|
395 | # Login as student |
---|
396 | self.browser.open(self.login_path) |
---|
397 | IWorkflowState(self.student).setState('school fee paid') |
---|
398 | self.browser.open(self.login_path) |
---|
399 | self.browser.getControl(name="form.login").value = self.student_id |
---|
400 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
401 | self.browser.getControl("Login").click() |
---|
402 | # Students can add the current study level |
---|
403 | self.browser.getLink("Study Course").click() |
---|
404 | self.browser.getLink("Add course list").click() |
---|
405 | self.assertMatches('...Add current level 100 (Year 1)...', |
---|
406 | self.browser.contents) |
---|
407 | self.browser.getControl("Create course list now").click() |
---|
408 | # Student has not paid second instalment, therefore a level |
---|
409 | # with two course ticket was created (semester 1 and combined) |
---|
410 | self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 2) |
---|
411 | self.browser.getLink("100").click() |
---|
412 | self.browser.getLink("Edit course list").click() |
---|
413 | self.browser.getControl("Add course ticket").click() |
---|
414 | # Student can't add second semester course |
---|
415 | self.assertTrue('<option value="COURSE1">' in self.browser.contents) |
---|
416 | self.assertTrue('<option value="COURSE3">' in self.browser.contents) |
---|
417 | self.assertFalse('<option value="COURSE2">' in self.browser.contents) |
---|
418 | |
---|
419 | # Let's remove level and see what happens after 2nd instalment payment |
---|
420 | del(self.student['studycourse']['100']) |
---|
421 | payment2 = createObject('waeup.StudentOnlinePayment') |
---|
422 | payment2.p_category = u'schoolfee_2' |
---|
423 | payment2.p_session = self.student.current_session |
---|
424 | self.student['payments']['anykey'] = payment2 |
---|
425 | self.browser.open(self.studycourse_path) |
---|
426 | self.browser.getLink("Add course list").click() |
---|
427 | self.browser.getControl("Create course list now").click() |
---|
428 | # Still only 2 tickets have been created since payment ticket |
---|
429 | # was not paid |
---|
430 | self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 2) |
---|
431 | payment2.p_state = u'paid' |
---|
432 | del(self.student['studycourse']['100']) |
---|
433 | self.browser.open(self.studycourse_path) |
---|
434 | self.browser.getLink("Add course list").click() |
---|
435 | self.browser.getControl("Create course list now").click() |
---|
436 | # Now 2nd semester course has been added |
---|
437 | self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 3) |
---|
438 | # Student can add second semester course |
---|
439 | self.browser.getLink("100").click() |
---|
440 | self.browser.getLink("Edit course list").click() |
---|
441 | self.browser.getControl("Add course ticket").click() |
---|
442 | self.assertTrue('<option value="COURSE1">' in self.browser.contents) |
---|
443 | self.assertTrue('<option value="COURSE2">' in self.browser.contents) |
---|
444 | self.assertTrue('<option value="COURSE3">' in self.browser.contents) |
---|
445 | return |
---|
446 | |
---|
447 | def test_set_matric_number(self): |
---|
448 | # Login as student |
---|
449 | self.browser.open(self.login_path) |
---|
450 | IWorkflowState(self.student).setState('school fee paid') |
---|
451 | self.browser.open(self.login_path) |
---|
452 | self.browser.getControl(name="form.login").value = self.student_id |
---|
453 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
454 | self.browser.getControl("Login").click() |
---|
455 | self.assertRaises( |
---|
456 | LinkNotFoundError, |
---|
457 | self.browser.getLink, 'Get Matriculation Number') |
---|
458 | self.student.matric_number = None |
---|
459 | site = grok.getSite() |
---|
460 | site['configuration'].next_matric_integer = 1 |
---|
461 | self.student['studycourse'].certificate.study_mode = 'ug_pt' |
---|
462 | self.browser.open(self.student_path) |
---|
463 | self.assertRaises( |
---|
464 | LinkNotFoundError, |
---|
465 | self.browser.getLink, 'Download matriculation number slip') |
---|
466 | self.browser.getLink("Get Matriculation Number").click() |
---|
467 | self.assertTrue('Matriculation number PTP/fac1/dep1/04/00001 assigned.' |
---|
468 | in self.browser.contents) |
---|
469 | self.assertEqual(self.student.matric_number, 'PTP/fac1/dep1/04/00001') |
---|
470 | self.assertRaises( |
---|
471 | LinkNotFoundError, |
---|
472 | self.browser.getLink, 'Get Matriculation Number') |
---|
473 | # Setting matric number is logged. |
---|
474 | logfile = os.path.join( |
---|
475 | self.app['datacenter'].storage, 'logs', 'students.log') |
---|
476 | logcontent = open(logfile).read() |
---|
477 | self.assertTrue('E1000000 - waeup.aaue.students.browser.StudentGetMatricNumberPage - ' |
---|
478 | 'E1000000 - PTP/fac1/dep1/04/00001 assigned' in logcontent) |
---|
479 | # Matric Number Slip can be downloaded |
---|
480 | self.browser.getLink("Download matriculation number slip").click() |
---|
481 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
482 | self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf') |
---|
483 | path = os.path.join(samples_dir(), 'matric_number_slip.pdf') |
---|
484 | open(path, 'wb').write(self.browser.contents) |
---|
485 | print "Sample PDF matric_number_slip.pdf written to %s" % path |
---|
486 | return |
---|
487 | |
---|
488 | def test_student_course_registration(self): |
---|
489 | IWorkflowState(self.student).setState('school fee paid') |
---|
490 | self.browser.open(self.login_path) |
---|
491 | self.browser.getControl(name="form.login").value = self.student_id |
---|
492 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
493 | self.browser.getControl("Login").click() |
---|
494 | # Now students can add the current study level |
---|
495 | self.browser.getLink("Study Course").click() |
---|
496 | self.browser.getLink("Add course list").click() |
---|
497 | self.assertMatches('...Add current level 100 (Year 1)...', |
---|
498 | self.browser.contents) |
---|
499 | self.browser.getControl("Create course list now").click() |
---|
500 | # Students can't open the customized pdf course registration slip |
---|
501 | self.browser.open( |
---|
502 | self.student_path + '/studycourse/100/course_registration_slip.pdf') |
---|
503 | self.assertTrue('Forbidden' in self.browser.contents) |
---|
504 | # They can open slips from the previous session ... |
---|
505 | self.student['studycourse'].current_level = 200 |
---|
506 | self.browser.open(self.student_path + '/studycourse/100') |
---|
507 | self.browser.getLink("Download course registration slip").click() |
---|
508 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
509 | self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf') |
---|
510 | # or if they have registered their course list |
---|
511 | self.student['studycourse'].current_level = 200 |
---|
512 | IWorkflowState(self.student).setState('courses registered') |
---|
513 | self.browser.open(self.student_path + '/studycourse/100') |
---|
514 | self.browser.getLink("Download course registration slip").click() |
---|
515 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
516 | self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf') |
---|
517 | |
---|
518 | def test_student_clearance(self): |
---|
519 | # Student cant login if their password is not set |
---|
520 | IWorkflowInfo(self.student).fireTransition('admit') |
---|
521 | self.browser.open(self.login_path) |
---|
522 | self.browser.getControl(name="form.login").value = self.student_id |
---|
523 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
524 | self.browser.getControl("Login").click() |
---|
525 | self.assertMatches( |
---|
526 | '...You logged in...', self.browser.contents) |
---|
527 | # Admitted student can upload a passport picture |
---|
528 | self.browser.open(self.student_path + '/change_portrait') |
---|
529 | ctrl = self.browser.getControl(name='passportuploadedit') |
---|
530 | file_obj = open(SAMPLE_IMAGE, 'rb') |
---|
531 | file_ctrl = ctrl.mech_control |
---|
532 | file_ctrl.add_file(file_obj, filename='my_photo.jpg') |
---|
533 | self.browser.getControl( |
---|
534 | name='upload_passportuploadedit').click() |
---|
535 | self.assertTrue( |
---|
536 | 'src="http://localhost/app/students/E1000000/passport.jpg"' |
---|
537 | in self.browser.contents) |
---|
538 | # Student is redirected to the personal data form because |
---|
539 | # personal data form is not properly filled. |
---|
540 | self.browser.open(self.student_path + '/start_clearance') |
---|
541 | self.assertMatches('...Personal data form is not properly filled...', |
---|
542 | self.browser.contents) |
---|
543 | self.assertEqual(self.browser.url, self.student_path + '/edit_personal') |
---|
544 | self.student.father_name = u'Rudolf' |
---|
545 | self.browser.open(self.student_path + '/start_clearance') |
---|
546 | self.assertMatches('...<h1 class="kofa-content-label">Start clearance</h1>...', |
---|
547 | self.browser.contents) |
---|
548 | |
---|
549 | def test_student_accommodation(self): |
---|
550 | del self.student['accommodation']['2004'] |
---|
551 | # Login |
---|
552 | self.browser.open(self.login_path) |
---|
553 | self.browser.getControl(name="form.login").value = self.student_id |
---|
554 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
555 | self.browser.getControl("Login").click() |
---|
556 | # Students can book accommodation without AC ... |
---|
557 | self.browser.open(self.acco_path) |
---|
558 | IWorkflowInfo(self.student).fireTransition('admit') |
---|
559 | self.browser.getLink("Book accommodation").click() |
---|
560 | self.assertFalse('Activation Code:' in self.browser.contents) |
---|
561 | self.browser.getControl("Create bed ticket").click() |
---|
562 | # Bed is randomly selected but, since there is only |
---|
563 | # one bed for this student, we know that |
---|
564 | self.assertEqual(self.student['accommodation']['2004'].bed_coordinates, |
---|
565 | 'Hall 1, Block A, Room 101, Bed A (regular_male_fr)') |
---|
566 | # Only the hall name is displayed |
---|
567 | self.assertEqual(self.student['accommodation']['2004'].display_coordinates, |
---|
568 | 'Hall 1') |
---|
569 | self.assertFalse('Hall 1, Block A, Room 101, Bed A' |
---|
570 | in self.browser.contents) |
---|
571 | self.assertTrue('<td>Hall 1</td>' |
---|
572 | in self.browser.contents) |
---|
573 | return |
---|