1 | # -*- coding: utf-8 -*- |
---|
2 | ## $Id: test_browser.py 16504 2021-06-12 05:05:15Z henrik $ |
---|
3 | ## |
---|
4 | ## Copyright (C) 2013 Uli Fouquet & Henrik Bettermann |
---|
5 | ## This program is free software; you can redistribute it and/or modify |
---|
6 | ## it under the terms of the GNU General Public License as published by |
---|
7 | ## the Free Software Foundation; either version 2 of the License, or |
---|
8 | ## (at your option) any later version. |
---|
9 | ## |
---|
10 | ## This program is distributed in the hope that it will be useful, |
---|
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | ## GNU General Public License for more details. |
---|
14 | ## |
---|
15 | ## You should have received a copy of the GNU General Public License |
---|
16 | ## along with this program; if not, write to the Free Software |
---|
17 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
18 | ## |
---|
19 | """ |
---|
20 | Test the applicant-related UI components. |
---|
21 | """ |
---|
22 | import os |
---|
23 | import datetime |
---|
24 | import pytz |
---|
25 | from StringIO import StringIO |
---|
26 | from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState |
---|
27 | from zope.securitypolicy.interfaces import IPrincipalRoleManager |
---|
28 | from zope.component import createObject, getUtility |
---|
29 | from waeup.kofa.interfaces import IUserAccount |
---|
30 | from waeup.kofa.browser.tests.test_pdf import samples_dir |
---|
31 | from waeup.kofa.applicants.container import ApplicantsContainer |
---|
32 | from waeup.uniben.testing import FunctionalLayer |
---|
33 | from waeup.uniben.configuration import CustomSessionConfiguration |
---|
34 | from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup, PH_LEN |
---|
35 | |
---|
36 | session_1 = datetime.datetime.now().year - 2 |
---|
37 | SAMPLE_IMAGE = os.path.join(os.path.dirname(__file__), 'test_image.jpg') |
---|
38 | |
---|
39 | class CustomApplicantUITests(ApplicantsFullSetup): |
---|
40 | # Tests for uploading/browsing the passport image of appplicants |
---|
41 | |
---|
42 | layer = FunctionalLayer |
---|
43 | |
---|
44 | #def setUp(self): |
---|
45 | # super(CustomApplicantUITests, self).setUp() |
---|
46 | # return |
---|
47 | |
---|
48 | def test_applicant_access(self): |
---|
49 | # Anonymous users can't see the application fee. |
---|
50 | self.browser.open(self.container_path) |
---|
51 | self.assertFalse('Application Fee' in self.browser.contents) |
---|
52 | # Applicants can edit their record |
---|
53 | self.browser.open(self.login_path) |
---|
54 | self.login() |
---|
55 | self.assertTrue( |
---|
56 | 'You logged in.' in self.browser.contents) |
---|
57 | self.browser.open(self.edit_path) |
---|
58 | self.assertTrue(self.browser.url != self.login_path) |
---|
59 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
60 | self.fill_correct_values() |
---|
61 | self.browser.getControl("Save").click() |
---|
62 | self.assertMatches('...Form has been saved...', self.browser.contents) |
---|
63 | # Applicants can't see the application fee. |
---|
64 | self.browser.open(self.container_path) |
---|
65 | self.assertFalse('Application Fee' in self.browser.contents) |
---|
66 | return |
---|
67 | |
---|
68 | def image_url(self, filename): |
---|
69 | return self.edit_path.replace('edit', filename) |
---|
70 | |
---|
71 | def test_upload_passport_wo_permission(self): |
---|
72 | # Create CRPU officer |
---|
73 | self.app['users'].addUser('mrcrpu', 'mrCrpusecret1') |
---|
74 | self.app['users']['mrcrpu'].email = 'mrcrpu@foo.ng' |
---|
75 | self.app['users']['mrcrpu'].title = 'Carlo Pitter' |
---|
76 | prmglobal = IPrincipalRoleManager(self.app) |
---|
77 | prmglobal.assignRoleToPrincipal('waeup.CCOfficer', 'mrcrpu') |
---|
78 | # Login as CRPU officer |
---|
79 | self.browser.open(self.login_path) |
---|
80 | self.browser.getControl(name="form.login").value = 'mrcrpu' |
---|
81 | self.browser.getControl(name="form.password").value = 'mrCrpusecret1' |
---|
82 | self.browser.getControl("Login").click() |
---|
83 | self.assertMatches('...You logged in...', self.browser.contents) |
---|
84 | # Let's try to change the passport image |
---|
85 | self.browser.open(self.manage_path) |
---|
86 | self.fill_correct_values() |
---|
87 | # Create a pseudo image file and select it to be uploaded in form |
---|
88 | pseudo_image = StringIO('I pretend to be a graphics file') |
---|
89 | ctrl = self.browser.getControl(name='form.passport') |
---|
90 | file_ctrl = ctrl.mech_control |
---|
91 | file_ctrl.add_file(pseudo_image, filename='myphoto.jpg') |
---|
92 | self.browser.getControl("Save").click() |
---|
93 | self.assertMatches('...You are not entitled to upload passport pictures...', |
---|
94 | self.browser.contents) |
---|
95 | # The officer still sees the placeholder passport image |
---|
96 | self.browser.open(self.image_url('passport.jpg')) |
---|
97 | self.assertEqual( |
---|
98 | self.browser.headers['content-type'], 'image/jpeg') |
---|
99 | self.assertEqual(len(self.browser.contents), PH_LEN) |
---|
100 | # After adding the additional role ... |
---|
101 | prmglobal.assignRoleToPrincipal('waeup.PassportPictureManager', 'mrcrpu') |
---|
102 | # ... passport pictures can be uploaded |
---|
103 | self.browser.open(self.manage_path) |
---|
104 | self.fill_correct_values() |
---|
105 | pseudo_image = StringIO('I pretend to be a graphics file') |
---|
106 | ctrl = self.browser.getControl(name='form.passport') |
---|
107 | file_ctrl = ctrl.mech_control |
---|
108 | file_ctrl.add_file(pseudo_image, filename='myphoto.jpg') |
---|
109 | self.browser.getControl("Save").click() |
---|
110 | self.assertMatches('...Form has been saved...', self.browser.contents) |
---|
111 | # There is a correct <img> link included |
---|
112 | self.assertTrue( |
---|
113 | '<img src="passport.jpg" height="180px" />' in self.browser.contents) |
---|
114 | # Browsing the link shows a real image |
---|
115 | self.browser.open(self.image_url('passport.jpg')) |
---|
116 | self.assertEqual( |
---|
117 | self.browser.headers['content-type'], 'image/jpeg') |
---|
118 | self.assertEqual(len(self.browser.contents), 31) |
---|
119 | |
---|
120 | def test_pay_admission_checking_fee(self): |
---|
121 | IWorkflowState(self.applicant).setState('admitted') |
---|
122 | self.applicant.screening_score = 55 |
---|
123 | self.applicant.course_admitted = self.certificate |
---|
124 | self.login() |
---|
125 | # SessionConfiguration is not set, thus admission checking payment |
---|
126 | # is not necessary. Screening results and course admitted are visible. |
---|
127 | self.assertFalse( |
---|
128 | 'Add admission checking payment ticket' in self.browser.contents) |
---|
129 | self.assertTrue('<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">CERT1 - Unnamed Certificate</a>' in self.browser.contents) |
---|
130 | self.assertTrue('<span>55</span>' in self.browser.contents) |
---|
131 | configuration = CustomSessionConfiguration() |
---|
132 | configuration.academic_session = datetime.datetime.now().year - 2 |
---|
133 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
134 | # Admission checking fee is 0, thus admission checking payment |
---|
135 | # is not necessary. Screening results and course admitted are visible. |
---|
136 | self.browser.open(self.view_path) |
---|
137 | self.assertFalse( |
---|
138 | 'Add admission checking payment ticket' in self.browser.contents) |
---|
139 | self.assertTrue('<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">CERT1 - Unnamed Certificate</a>' in self.browser.contents) |
---|
140 | self.assertTrue('<span>55</span>' in self.browser.contents) |
---|
141 | configuration.admchecking_fee = 22.0 |
---|
142 | # Admission checking payment button is now visible, but screening results |
---|
143 | # and course admitted are not. |
---|
144 | self.browser.open(self.view_path) |
---|
145 | self.assertTrue( |
---|
146 | 'Add admission checking payment ticket' in self.browser.contents) |
---|
147 | self.assertFalse('<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">CERT1 - Unnamed Certificate</a>' in self.browser.contents) |
---|
148 | self.assertFalse('<span>55</span>' in self.browser.contents) |
---|
149 | # Application slip can't be downloaded |
---|
150 | self.assertFalse('Download application slip' in self.browser.contents) |
---|
151 | slip_path = self.view_path + '/application_slip.pdf' |
---|
152 | self.browser.open(slip_path) |
---|
153 | self.assertTrue( |
---|
154 | 'Please pay admission checking fee before trying to download' |
---|
155 | in self.browser.contents) |
---|
156 | # Pay admission checking fee. |
---|
157 | self.browser.getControl("Add admission checking").click() |
---|
158 | p_id = self.applicant.keys()[0] |
---|
159 | self.applicant[p_id].p_state = 'paid' |
---|
160 | # Screening results and course admitted are visible after payment. |
---|
161 | self.browser.open(self.view_path) |
---|
162 | self.assertFalse( |
---|
163 | 'Add admission checking payment ticket' in self.browser.contents) |
---|
164 | self.assertTrue('<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">CERT1 - Unnamed Certificate</a>' in self.browser.contents) |
---|
165 | self.assertTrue('<span>55</span>' in self.browser.contents) |
---|
166 | # Application slip can be downloaded again. |
---|
167 | self.browser.getLink("Download application slip").click() |
---|
168 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
169 | self.assertEqual(self.browser.headers['Content-Type'], |
---|
170 | 'application/pdf') |
---|
171 | return |
---|
172 | |
---|
173 | def test_application_slips(self): |
---|
174 | |
---|
175 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
176 | self.browser.open(self.manage_path) |
---|
177 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
178 | self.fill_correct_values() |
---|
179 | self.browser.getControl("Save").click() |
---|
180 | IWorkflowState(self.applicant).setState('submitted') |
---|
181 | self.browser.open(self.view_path) |
---|
182 | self.browser.getLink("Download application slip").click() |
---|
183 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
184 | self.assertEqual(self.browser.headers['Content-Type'], |
---|
185 | 'application/pdf') |
---|
186 | path = os.path.join(samples_dir(), 'application_slip.pdf') |
---|
187 | open(path, 'wb').write(self.browser.contents) |
---|
188 | print "Sample application_slip.pdf written to %s" % path |
---|
189 | # Screening invitation letter is not yet available |
---|
190 | self.browser.open(self.view_path) |
---|
191 | self.assertFalse('invitation slip' in self.browser.contents) |
---|
192 | self.browser.open(self.view_path + '/screening_invitation_slip.pdf') |
---|
193 | self.assertTrue('Forbidden' in self.browser.contents) |
---|
194 | self.applicant.screening_date = u'any date' |
---|
195 | self.applicant.screening_venue = u'MAIN AUDITORIUM' |
---|
196 | self.applicantscontainer.application_slip_notice = u'This is an additional notice.' |
---|
197 | # The invitation letter can be printed |
---|
198 | self.browser.open(self.view_path) |
---|
199 | self.browser.getLink("invitation").click() |
---|
200 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
201 | self.assertEqual(self.browser.headers['Content-Type'], |
---|
202 | 'application/pdf') |
---|
203 | path = os.path.join(samples_dir(), 'screening_invitation_slip.pdf') |
---|
204 | open(path, 'wb').write(self.browser.contents) |
---|
205 | print "Sample screening_invitation_slip.pdf written to %s" % path |
---|
206 | |
---|
207 | def test_akoka_application_slip(self): |
---|
208 | |
---|
209 | # Remove required FieldProperty attribute first ... |
---|
210 | delattr(ApplicantsContainer, 'prefix') |
---|
211 | # ... and replace by akoka |
---|
212 | self.applicantscontainer.prefix = 'akj' |
---|
213 | self.applicantscontainer.title = u'FCET Akoka JUPEB Pre-Degree (Foundation) Studies 2016/2017' |
---|
214 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
215 | self.slip_path = self.view_path + '/application_slip.pdf' |
---|
216 | self.browser.open(self.manage_path) |
---|
217 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
218 | self.fill_correct_values() |
---|
219 | self.browser.getControl("Save").click() |
---|
220 | IWorkflowState(self.applicant).setState('submitted') |
---|
221 | self.browser.open(self.view_path) |
---|
222 | self.browser.getLink("Download application slip").click() |
---|
223 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
224 | self.assertEqual(self.browser.headers['Content-Type'], |
---|
225 | 'application/pdf') |
---|
226 | path = os.path.join(samples_dir(), 'akoka_application_slip.pdf') |
---|
227 | open(path, 'wb').write(self.browser.contents) |
---|
228 | print "Sample akoka_application_slip.pdf written to %s" % path |
---|
229 | |
---|
230 | def test_nils_application_slip(self): |
---|
231 | |
---|
232 | # Remove required FieldProperty attribute first ... |
---|
233 | #delattr(ApplicantsContainer, 'prefix') |
---|
234 | # ... and replace by akoka |
---|
235 | self.applicantscontainer.prefix = 'pgn' |
---|
236 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
237 | self.slip_path = self.view_path + '/application_slip.pdf' |
---|
238 | self.browser.open(self.manage_path) |
---|
239 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
240 | self.fill_correct_values() |
---|
241 | self.browser.getControl("Save").click() |
---|
242 | IWorkflowState(self.applicant).setState('submitted') |
---|
243 | self.browser.open(self.view_path) |
---|
244 | self.browser.getLink("Download application slip").click() |
---|
245 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
246 | self.assertEqual(self.browser.headers['Content-Type'], |
---|
247 | 'application/pdf') |
---|
248 | path = os.path.join(samples_dir(), 'nils_application_slip.pdf') |
---|
249 | open(path, 'wb').write(self.browser.contents) |
---|
250 | print "Sample nils_application_slip.pdf written to %s" % path |
---|
251 | |
---|
252 | def test_ictwk_application(self): |
---|
253 | |
---|
254 | # Remove required FieldProperty attribute first ... |
---|
255 | #delattr(ApplicantsContainer, 'prefix') |
---|
256 | # ... and replace by ictw |
---|
257 | self.applicantscontainer.prefix = 'ictwk' |
---|
258 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
259 | self.slip_path = self.view_path + '/application_slip.pdf' |
---|
260 | self.browser.open(self.manage_path) |
---|
261 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
262 | self.browser.getControl(name="form.firstname").value = 'John' |
---|
263 | self.browser.getControl(name="form.middlename").value = 'Anthony' |
---|
264 | self.browser.getControl(name="form.lastname").value = 'Tester' |
---|
265 | #self.browser.getControl(name="form.date_of_birth").value = '09/09/1988' |
---|
266 | self.browser.getControl(name="form.sex").value = ['m'] |
---|
267 | self.browser.getControl(name="form.email").value = 'xx@yy.zz' |
---|
268 | image = open(SAMPLE_IMAGE, 'rb') |
---|
269 | ctrl = self.browser.getControl(name='form.passport') |
---|
270 | file_ctrl = ctrl.mech_control |
---|
271 | file_ctrl.add_file(image, filename='myphoto.jpg') |
---|
272 | self.browser.getControl("Save").click() |
---|
273 | self.applicant.registration_cats = ['group', 'corporate'] |
---|
274 | IWorkflowState(self.applicant).setState('started') |
---|
275 | configuration = CustomSessionConfiguration() |
---|
276 | configuration.academic_session = session_1 |
---|
277 | configuration.application_fee = 0.0 |
---|
278 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
279 | self.browser.getControl("Create and make online").click() |
---|
280 | self.assertMatches('...Payment ticket created...', |
---|
281 | self.browser.contents) |
---|
282 | self.assertEqual(self.applicant.values()[0].amount_auth, 450000) |
---|
283 | IWorkflowState(self.applicant).setState('submitted') |
---|
284 | self.browser.open(self.view_path) |
---|
285 | self.assertTrue('Group Registration @ ₦ 200000' in self.browser.contents) |
---|
286 | self.browser.open(self.view_path) |
---|
287 | self.browser.getLink("Download application slip").click() |
---|
288 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
289 | self.assertEqual(self.browser.headers['Content-Type'], |
---|
290 | 'application/pdf') |
---|
291 | path = os.path.join(samples_dir(), 'ictwk_application_slip.pdf') |
---|
292 | open(path, 'wb').write(self.browser.contents) |
---|
293 | print "Sample ictwk_application_slip.pdf written to %s" % path |
---|
294 | |
---|
295 | def test_transcript_application(self): |
---|
296 | configuration = CustomSessionConfiguration() |
---|
297 | configuration.academic_session = session_1 |
---|
298 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
299 | # Add special application container |
---|
300 | applicantscontainer = ApplicantsContainer() |
---|
301 | applicantscontainer.year = session_1 |
---|
302 | applicantscontainer.application_fee = 1.0 # Must be set but is not used. |
---|
303 | applicantscontainer.code = u'tsc1234' |
---|
304 | applicantscontainer.prefix = 'tscf' |
---|
305 | applicantscontainer.title = u'This is a tsc container' |
---|
306 | applicantscontainer.application_category = 'no' |
---|
307 | applicantscontainer.mode = 'create' |
---|
308 | applicantscontainer.strict_deadline = True |
---|
309 | applicantscontainer.with_picture = True |
---|
310 | delta = datetime.timedelta(days=10) |
---|
311 | applicantscontainer.startdate = datetime.datetime.now(pytz.utc) - delta |
---|
312 | applicantscontainer.enddate = datetime.datetime.now(pytz.utc) + delta |
---|
313 | self.app['applicants']['tsc1234'] = applicantscontainer |
---|
314 | # Add an applicant |
---|
315 | applicant = createObject('waeup.Applicant') |
---|
316 | # reg_number is the only field which has to be preset here |
---|
317 | # because managers are allowed to edit this required field |
---|
318 | applicant.reg_number = u'12345' |
---|
319 | self.app['applicants']['tsc1234'].addApplicant(applicant) |
---|
320 | IUserAccount( |
---|
321 | self.app['applicants']['tsc1234'][ |
---|
322 | applicant.application_number]).setPassword('apwd') |
---|
323 | # Login |
---|
324 | self.browser.open(self.login_path) |
---|
325 | self.browser.getControl( |
---|
326 | name="form.login").value = applicant.applicant_id |
---|
327 | self.browser.getControl(name="form.password").value = 'apwd' |
---|
328 | self.browser.getControl("Login").click() |
---|
329 | self.browser.getLink("Application record").click() |
---|
330 | self.browser.getControl(name="form.date_of_birth").value = '09/09/1988' |
---|
331 | self.browser.getControl(name="form.email").value = 'xx@yy.zz' |
---|
332 | self.browser.getControl(name="form.firstname").value = 'Angela' |
---|
333 | self.browser.getControl(name="form.lastname").value = 'Merkel' |
---|
334 | self.browser.getControl(name="form.sex").value = ['f'] |
---|
335 | self.browser.getControl(name="form.no_copies").value = ['2'] |
---|
336 | self.browser.getControl(name="form.course_studied").value = ['CERT1'] |
---|
337 | self.browser.getControl(name="form.matric_number").value = '234' |
---|
338 | self.browser.getControl(name="form.dispatch_address").value = 'Kuensche\nMarsch 5' |
---|
339 | self.browser.getControl(name="form.entry_mode").value = ['ug_ft'] |
---|
340 | self.browser.getControl(name="form.entry_session").value = ['2014'] |
---|
341 | self.browser.getControl(name="form.end_session").value = ['2015'] |
---|
342 | self.browser.getControl(name="form.phone.country").value = ['+234'] |
---|
343 | self.browser.getControl(name="form.phone.ext").value = '5678' |
---|
344 | self.browser.getControl(name="form.charge").value = ['nigeria'] |
---|
345 | image = open(SAMPLE_IMAGE, 'rb') |
---|
346 | ctrl = self.browser.getControl(name='form.passport') |
---|
347 | file_ctrl = ctrl.mech_control |
---|
348 | file_ctrl.add_file(image, filename='myphoto.jpg') |
---|
349 | self.browser.getControl("Save").click() |
---|
350 | applicant_url = self.browser.url |
---|
351 | self.browser.getControl("Create and make online").click() |
---|
352 | self.assertTrue('Payment ticket created' in self.browser.contents) |
---|
353 | self.assertTrue('<span>40000.0</span>' in self.browser.contents) |
---|
354 | self.assertEqual(applicant.values()[0].amount_auth, 40000.0) |
---|
355 | applicant.values()[0].p_state = 'paid' |
---|
356 | payment_url = self.browser.url |
---|
357 | IWorkflowState(applicant).setState('submitted') |
---|
358 | self.browser.open(payment_url) |
---|
359 | self.browser.getLink("Download payment slip").click() |
---|
360 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
361 | self.assertEqual(self.browser.headers['Content-Type'], |
---|
362 | 'application/pdf') |
---|
363 | path = os.path.join(samples_dir(), 'tscf_payment_slip.pdf') |
---|
364 | open(path, 'wb').write(self.browser.contents) |
---|
365 | print "Sample tscf_payment_slip.pdf written to %s" % path |
---|
366 | self.browser.open(applicant_url) |
---|
367 | self.browser.getLink("My Data").click() |
---|
368 | self.browser.getLink("Download application slip").click() |
---|
369 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
370 | self.assertEqual(self.browser.headers['Content-Type'], |
---|
371 | 'application/pdf') |
---|
372 | path = os.path.join(samples_dir(), 'tscf_application_slip.pdf') |
---|
373 | open(path, 'wb').write(self.browser.contents) |
---|
374 | print "Sample tscf_application_slip.pdf written to %s" % path |
---|
375 | return |
---|