1 | ## $Id: test_browser.py 11621 2014-05-05 17:14:11Z 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 grok |
---|
22 | from mechanize import LinkNotFoundError |
---|
23 | from hurry.workflow.interfaces import IWorkflowState |
---|
24 | from zope.component.hooks import setSite, clearSite |
---|
25 | from zope.component import getUtility, createObject |
---|
26 | from waeup.kofa.app import University |
---|
27 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
28 | from waeup.kofa.students.accommodation import BedTicket |
---|
29 | from waeup.kofa.testing import FunctionalTestCase |
---|
30 | from waeup.kofa.browser.tests.test_pdf import samples_dir |
---|
31 | from waeup.aaue.testing import FunctionalLayer |
---|
32 | |
---|
33 | |
---|
34 | class StudentProcessorTest(FunctionalTestCase): |
---|
35 | """Perform some batching tests. |
---|
36 | """ |
---|
37 | |
---|
38 | layer = FunctionalLayer |
---|
39 | |
---|
40 | def setUp(self): |
---|
41 | super(StudentProcessorTest, self).setUp() |
---|
42 | # Setup a sample site for each test |
---|
43 | app = University() |
---|
44 | self.dc_root = tempfile.mkdtemp() |
---|
45 | app['datacenter'].setStoragePath(self.dc_root) |
---|
46 | |
---|
47 | # Prepopulate the ZODB... |
---|
48 | self.getRootFolder()['app'] = app |
---|
49 | # we add the site immediately after creation to the |
---|
50 | # ZODB. Catalogs and other local utilities are not setup |
---|
51 | # before that step. |
---|
52 | self.app = self.getRootFolder()['app'] |
---|
53 | # Set site here. Some of the following setup code might need |
---|
54 | # to access grok.getSite() and should get our new app then |
---|
55 | setSite(app) |
---|
56 | |
---|
57 | |
---|
58 | def tearDown(self): |
---|
59 | super(StudentProcessorTest, self).tearDown() |
---|
60 | shutil.rmtree(self.workdir) |
---|
61 | shutil.rmtree(self.dc_root) |
---|
62 | clearSite() |
---|
63 | return |
---|
64 | |
---|
65 | class OfficerUITests(StudentsFullSetup): |
---|
66 | # Tests for Student class views and pages |
---|
67 | |
---|
68 | layer = FunctionalLayer |
---|
69 | |
---|
70 | def test_gpa_calculation(self): |
---|
71 | studylevel = createObject(u'waeup.StudentStudyLevel') |
---|
72 | studylevel.level = 100 |
---|
73 | studylevel.level_session = 2005 |
---|
74 | self.student['studycourse'].entry_mode = 'ug_ft' |
---|
75 | self.student['studycourse'].addStudentStudyLevel( |
---|
76 | self.certificate, studylevel) |
---|
77 | # First course has been added automatically. |
---|
78 | # Set score. |
---|
79 | studylevel['COURSE1'].score = 55 |
---|
80 | # GPA is 3.0. |
---|
81 | self.assertEqual(studylevel.gpa_params[0], 3.0) |
---|
82 | courseticket = createObject('waeup.CourseTicket') |
---|
83 | courseticket.code = 'ANYCODE' |
---|
84 | courseticket.title = u'Any TITLE' |
---|
85 | courseticket.credits = 13 |
---|
86 | courseticket.score = 66 |
---|
87 | courseticket.semester = 1 |
---|
88 | courseticket.dcode = u'ANYDCODE' |
---|
89 | courseticket.fcode = u'ANYFCODE' |
---|
90 | studylevel['COURSE2'] = courseticket |
---|
91 | # total credits |
---|
92 | self.assertEqual(self.student['studycourse']['100'].gpa_params[1], 23) |
---|
93 | # weigheted credits = 3 * 10 + 4 * 13 |
---|
94 | self.assertEqual(self.student['studycourse']['100'].gpa_params[2], 82.0) |
---|
95 | # sgpa = 82 / 23 |
---|
96 | self.assertEqual(self.student['studycourse']['100'].gpa_params[0], 3.565) |
---|
97 | return |
---|
98 | |
---|
99 | class StudentUITests(StudentsFullSetup): |
---|
100 | """Tests for customized student class views and pages |
---|
101 | """ |
---|
102 | |
---|
103 | layer = FunctionalLayer |
---|
104 | |
---|
105 | def setUp(self): |
---|
106 | super(StudentUITests, self).setUp() |
---|
107 | |
---|
108 | bedticket = BedTicket() |
---|
109 | bedticket.booking_session = 2004 |
---|
110 | bedticket.bed_type = u'any bed type' |
---|
111 | bedticket.bed = self.app['hostels']['hall-1']['hall-1_A_101_A'] |
---|
112 | bedticket.bed_coordinates = u'My bed coordinates' |
---|
113 | self.student['accommodation'].addBedTicket(bedticket) |
---|
114 | |
---|
115 | def test_manage_payments(self): |
---|
116 | # Add missing configuration data |
---|
117 | self.app['configuration']['2004'].gown_fee = 150.0 |
---|
118 | self.app['configuration']['2004'].transfer_fee = 90.0 |
---|
119 | self.app['configuration']['2004'].booking_fee = 150.0 |
---|
120 | self.app['configuration']['2004'].maint_fee = 180.0 |
---|
121 | self.app['configuration']['2004'].late_fee = 80.0 |
---|
122 | |
---|
123 | # Managers can add online payment tickets |
---|
124 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
125 | self.browser.open(self.payments_path) |
---|
126 | self.browser.getLink("Add current session payment ticket").click() |
---|
127 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
128 | self.browser.getControl("Create ticket").click() |
---|
129 | self.assertMatches('...Wrong state...', |
---|
130 | self.browser.contents) |
---|
131 | IWorkflowState(self.student).setState('cleared') |
---|
132 | self.browser.open(self.payments_path + '/addop') |
---|
133 | self.browser.getControl("Create ticket").click() |
---|
134 | self.assertMatches('...Amount could not be determined...', |
---|
135 | self.browser.contents) |
---|
136 | self.app['configuration']['2004'].school_fee = 6666.0 |
---|
137 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
138 | self.browser.getControl("Create ticket").click() |
---|
139 | self.assertMatches('...ticket created...', |
---|
140 | self.browser.contents) |
---|
141 | ctrl = self.browser.getControl(name='val_id') |
---|
142 | value = ctrl.options[0] |
---|
143 | self.browser.getLink(value).click() |
---|
144 | self.assertMatches('...Amount Authorized...', |
---|
145 | self.browser.contents) |
---|
146 | # Managers can open payment slip |
---|
147 | self.browser.getLink("Download payment slip").click() |
---|
148 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
149 | self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf') |
---|
150 | # Set ticket paid |
---|
151 | ticket = self.student['payments'].items()[0][1] |
---|
152 | ticket.p_state = 'paid' |
---|
153 | self.browser.open(self.payments_path + '/addop') |
---|
154 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
155 | self.browser.getControl("Create ticket").click() |
---|
156 | self.assertMatches('...This type of payment has already been made...', |
---|
157 | self.browser.contents) |
---|
158 | self.browser.open(self.payments_path + '/addop') |
---|
159 | self.browser.getControl(name="form.p_category").value = ['clearance'] |
---|
160 | self.browser.getControl("Create ticket").click() |
---|
161 | self.assertMatches('...ticket created...', |
---|
162 | self.browser.contents) |
---|
163 | |
---|
164 | |
---|
165 | def deactivated_test_for_instalment_payments(self): |
---|
166 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
167 | self.browser.open(self.payments_path) |
---|
168 | self.browser.open(self.payments_path + '/addop') |
---|
169 | self.browser.getControl(name="form.p_category").value = ['schoolfee_1'] |
---|
170 | self.browser.getControl("Create ticket").click() |
---|
171 | self.assertMatches('...ticket created...', |
---|
172 | self.browser.contents) |
---|
173 | # We can't add the 2nd instalment ticket because the |
---|
174 | # first one has not yet been approved. |
---|
175 | self.browser.open(self.payments_path + '/addop') |
---|
176 | self.browser.getControl(name="form.p_category").value = ['schoolfee_2'] |
---|
177 | self.browser.getControl("Create ticket").click() |
---|
178 | self.assertMatches('...1st school fee instalment has not yet been paid...', |
---|
179 | self.browser.contents) |
---|
180 | # Ok, then we approve the first instalment ... |
---|
181 | self.browser.open(self.payments_path) |
---|
182 | ctrl = self.browser.getControl(name='val_id') |
---|
183 | p_id = ctrl.options[0] |
---|
184 | self.browser.open(self.payments_path + '/' + p_id + '/approve') |
---|
185 | # ... add the second instalment ... |
---|
186 | self.browser.open(self.payments_path + '/addop') |
---|
187 | self.browser.getControl(name="form.p_category").value = ['schoolfee_2'] |
---|
188 | self.browser.getControl("Create ticket").click() |
---|
189 | self.assertMatches('...ticket created...', |
---|
190 | self.browser.contents) |
---|
191 | # ... approve the second instalment ... |
---|
192 | ctrl = self.browser.getControl(name='val_id') |
---|
193 | p_id = ctrl.options[1] |
---|
194 | self.browser.open(self.payments_path + '/' + p_id + '/approve') |
---|
195 | # ... and finally add the 1st instalment for the next session |
---|
196 | # provided that student is returning. |
---|
197 | IWorkflowState(self.student).setState('returning') |
---|
198 | self.browser.open(self.payments_path + '/addop') |
---|
199 | self.browser.getControl(name="form.p_category").value = ['schoolfee_1'] |
---|
200 | self.browser.getControl("Create ticket").click() |
---|
201 | self.assertMatches('...Session configuration object is not...', |
---|
202 | self.browser.contents) |
---|
203 | # Uups, we forgot to add a session configuration for next session |
---|
204 | configuration = createObject('waeup.SessionConfiguration') |
---|
205 | configuration.academic_session = 2005 |
---|
206 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
207 | self.app['configuration']['2005'].school_base = 7777.0 |
---|
208 | self.browser.open(self.payments_path + '/addop') |
---|
209 | self.browser.getControl(name="form.p_category").value = ['schoolfee_1'] |
---|
210 | self.browser.getControl("Create ticket").click() |
---|
211 | self.assertMatches('...ticket created...', |
---|
212 | self.browser.contents) |
---|
213 | # If the session configuration doesn't exist an error message will |
---|
214 | # be shown. No other requirement is being checked. |
---|
215 | del self.app['configuration']['2004'] |
---|
216 | self.browser.open(self.payments_path) |
---|
217 | self.browser.getLink("Add current session payment ticket").click() |
---|
218 | self.browser.getControl("Create ticket").click() |
---|
219 | self.assertMatches('...Session configuration object is not...', |
---|
220 | self.browser.contents) |
---|
221 | |
---|
222 | def test_student_payments(self): |
---|
223 | # Login |
---|
224 | IWorkflowState(self.student).setState('returning') |
---|
225 | self.browser.open(self.login_path) |
---|
226 | self.browser.getControl(name="form.login").value = self.student_id |
---|
227 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
228 | self.browser.getControl("Login").click() |
---|
229 | self.browser.open(self.student_path + '/payments') |
---|
230 | self.assertTrue( |
---|
231 | 'Add current session payment ticket' in self.browser.contents) |
---|
232 | self.assertFalse( |
---|
233 | 'Add previous session payment ticket' in self.browser.contents) |
---|
234 | return |
---|
235 | |
---|
236 | def deactivated_test_student_course_registration(self): |
---|
237 | |
---|
238 | # Add more courses |
---|
239 | self.course2 = createObject('waeup.Course') |
---|
240 | self.course2.code = 'COURSE2' |
---|
241 | self.course2.semester = 2 |
---|
242 | self.course2.credits = 10 |
---|
243 | self.course2.passmark = 40 |
---|
244 | self.app['faculties']['fac1']['dep1'].courses.addCourse( |
---|
245 | self.course2) |
---|
246 | self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCertCourse( |
---|
247 | self.course2, level=100) |
---|
248 | self.course3 = createObject('waeup.Course') |
---|
249 | self.course3.code = 'COURSE3' |
---|
250 | self.course3.semester = 3 |
---|
251 | self.course3.credits = 10 |
---|
252 | self.course3.passmark = 40 |
---|
253 | self.app['faculties']['fac1']['dep1'].courses.addCourse( |
---|
254 | self.course3) |
---|
255 | self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCertCourse( |
---|
256 | self.course3, level=100) |
---|
257 | |
---|
258 | # Login as student |
---|
259 | self.browser.open(self.login_path) |
---|
260 | IWorkflowState(self.student).setState('school fee paid') |
---|
261 | self.browser.open(self.login_path) |
---|
262 | self.browser.getControl(name="form.login").value = self.student_id |
---|
263 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
264 | self.browser.getControl("Login").click() |
---|
265 | # Students can add the current study level |
---|
266 | self.browser.getLink("Study Course").click() |
---|
267 | self.browser.getLink("Add course list").click() |
---|
268 | self.assertMatches('...Add current level 100 (Year 1)...', |
---|
269 | self.browser.contents) |
---|
270 | self.browser.getControl("Create course list now").click() |
---|
271 | # Student has not paid second instalment, therefore a level |
---|
272 | # with two course ticket was created (semester 1 and combined) |
---|
273 | self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 2) |
---|
274 | self.browser.getLink("100").click() |
---|
275 | self.browser.getLink("Edit course list").click() |
---|
276 | self.browser.getControl("Add course ticket").click() |
---|
277 | # Student can't add second semester course |
---|
278 | self.assertTrue('<option value="COURSE1">' in self.browser.contents) |
---|
279 | self.assertTrue('<option value="COURSE3">' in self.browser.contents) |
---|
280 | self.assertFalse('<option value="COURSE2">' in self.browser.contents) |
---|
281 | |
---|
282 | # Let's remove level and see what happens after 2nd instalment payment |
---|
283 | del(self.student['studycourse']['100']) |
---|
284 | payment2 = createObject('waeup.StudentOnlinePayment') |
---|
285 | payment2.p_category = u'schoolfee_2' |
---|
286 | payment2.p_session = self.student.current_session |
---|
287 | self.student['payments']['anykey'] = payment2 |
---|
288 | self.browser.open(self.studycourse_path) |
---|
289 | self.browser.getLink("Add course list").click() |
---|
290 | self.browser.getControl("Create course list now").click() |
---|
291 | # Still only 2 tickets have been created since payment ticket |
---|
292 | # was not paid |
---|
293 | self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 2) |
---|
294 | payment2.p_state = u'paid' |
---|
295 | del(self.student['studycourse']['100']) |
---|
296 | self.browser.open(self.studycourse_path) |
---|
297 | self.browser.getLink("Add course list").click() |
---|
298 | self.browser.getControl("Create course list now").click() |
---|
299 | # Now 2nd semester course has been added |
---|
300 | self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 3) |
---|
301 | # Student can add second semester course |
---|
302 | self.browser.getLink("100").click() |
---|
303 | self.browser.getLink("Edit course list").click() |
---|
304 | self.browser.getControl("Add course ticket").click() |
---|
305 | self.assertTrue('<option value="COURSE1">' in self.browser.contents) |
---|
306 | self.assertTrue('<option value="COURSE2">' in self.browser.contents) |
---|
307 | self.assertTrue('<option value="COURSE3">' in self.browser.contents) |
---|
308 | return |
---|
309 | |
---|
310 | def test_set_matric_number(self): |
---|
311 | # Login as student |
---|
312 | self.browser.open(self.login_path) |
---|
313 | IWorkflowState(self.student).setState('school fee paid') |
---|
314 | self.browser.open(self.login_path) |
---|
315 | self.browser.getControl(name="form.login").value = self.student_id |
---|
316 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
317 | self.browser.getControl("Login").click() |
---|
318 | self.assertRaises( |
---|
319 | LinkNotFoundError, |
---|
320 | self.browser.getLink, 'Get Matriculation Number') |
---|
321 | self.student.matric_number = None |
---|
322 | site = grok.getSite() |
---|
323 | site['configuration'].next_matric_integer = 1 |
---|
324 | self.student['studycourse'].certificate.study_mode = 'ug_pt' |
---|
325 | self.browser.open(self.student_path) |
---|
326 | self.assertRaises( |
---|
327 | LinkNotFoundError, |
---|
328 | self.browser.getLink, 'Download matriculation number slip') |
---|
329 | self.browser.getLink("Get Matriculation Number").click() |
---|
330 | self.assertTrue('Matriculation number PTP/fac1/dep1/04/00001 assigned.' |
---|
331 | in self.browser.contents) |
---|
332 | self.assertEqual(self.student.matric_number, 'PTP/fac1/dep1/04/00001') |
---|
333 | self.assertRaises( |
---|
334 | LinkNotFoundError, |
---|
335 | self.browser.getLink, 'Get Matriculation Number') |
---|
336 | # Setting matric number is logged. |
---|
337 | logfile = os.path.join( |
---|
338 | self.app['datacenter'].storage, 'logs', 'students.log') |
---|
339 | logcontent = open(logfile).read() |
---|
340 | self.assertTrue('E1000000 - waeup.aaue.students.browser.StudentGetMatricNumberPage - ' |
---|
341 | 'E1000000 - PTP/fac1/dep1/04/00001 assigned' in logcontent) |
---|
342 | # Matric Number Slip can be downloaded |
---|
343 | self.browser.getLink("Download matriculation number slip").click() |
---|
344 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
345 | self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf') |
---|
346 | path = os.path.join(samples_dir(), 'transcript.pdf') |
---|
347 | open(path, 'wb').write(self.browser.contents) |
---|
348 | print "Sample PDF matric_number_slip.pdf written to %s" % path |
---|
349 | return |
---|
350 | |
---|