1 | # -*- coding: utf-8 -*- |
---|
2 | ## $Id: test_browser.py 14168 2016-09-13 13:30:05Z 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 | from StringIO import StringIO |
---|
24 | from datetime import datetime |
---|
25 | from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState |
---|
26 | from zope.securitypolicy.interfaces import IPrincipalRoleManager |
---|
27 | from waeup.kofa.browser.tests.test_pdf import samples_dir |
---|
28 | from waeup.kofa.applicants.container import ApplicantsContainer |
---|
29 | from waeup.uniben.testing import FunctionalLayer |
---|
30 | from waeup.uniben.configuration import CustomSessionConfiguration |
---|
31 | from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup, PH_LEN |
---|
32 | |
---|
33 | session_1 = datetime.now().year - 2 |
---|
34 | SAMPLE_IMAGE = os.path.join(os.path.dirname(__file__), 'test_image.jpg') |
---|
35 | |
---|
36 | class CustomApplicantUITests(ApplicantsFullSetup): |
---|
37 | # Tests for uploading/browsing the passport image of appplicants |
---|
38 | |
---|
39 | layer = FunctionalLayer |
---|
40 | |
---|
41 | #def setUp(self): |
---|
42 | # super(CustomApplicantUITests, self).setUp() |
---|
43 | # return |
---|
44 | |
---|
45 | def test_applicant_access(self): |
---|
46 | # Anonymous users can't see the application fee. |
---|
47 | self.browser.open(self.container_path) |
---|
48 | self.assertFalse('Application Fee' in self.browser.contents) |
---|
49 | # Applicants can edit their record |
---|
50 | self.browser.open(self.login_path) |
---|
51 | self.login() |
---|
52 | self.assertTrue( |
---|
53 | 'You logged in.' in self.browser.contents) |
---|
54 | self.browser.open(self.edit_path) |
---|
55 | self.assertTrue(self.browser.url != self.login_path) |
---|
56 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
57 | self.fill_correct_values() |
---|
58 | self.browser.getControl("Save").click() |
---|
59 | self.assertMatches('...Form has been saved...', self.browser.contents) |
---|
60 | # Applicants can't see the application fee. |
---|
61 | self.browser.open(self.container_path) |
---|
62 | self.assertFalse('Application Fee' in self.browser.contents) |
---|
63 | return |
---|
64 | |
---|
65 | def image_url(self, filename): |
---|
66 | return self.edit_path.replace('edit', filename) |
---|
67 | |
---|
68 | def test_upload_passport_wo_permission(self): |
---|
69 | # Create CRPU officer |
---|
70 | self.app['users'].addUser('mrcrpu', 'mrcrpusecret') |
---|
71 | self.app['users']['mrcrpu'].email = 'mrcrpu@foo.ng' |
---|
72 | self.app['users']['mrcrpu'].title = 'Carlo Pitter' |
---|
73 | prmglobal = IPrincipalRoleManager(self.app) |
---|
74 | prmglobal.assignRoleToPrincipal('waeup.CCOfficer', 'mrcrpu') |
---|
75 | # Login as CRPU officer |
---|
76 | self.browser.open(self.login_path) |
---|
77 | self.browser.getControl(name="form.login").value = 'mrcrpu' |
---|
78 | self.browser.getControl(name="form.password").value = 'mrcrpusecret' |
---|
79 | self.browser.getControl("Login").click() |
---|
80 | self.assertMatches('...You logged in...', self.browser.contents) |
---|
81 | # Let's try to change the passport image |
---|
82 | self.browser.open(self.manage_path) |
---|
83 | self.fill_correct_values() |
---|
84 | # Create a pseudo image file and select it to be uploaded in form |
---|
85 | pseudo_image = StringIO('I pretend to be a graphics file') |
---|
86 | ctrl = self.browser.getControl(name='form.passport') |
---|
87 | file_ctrl = ctrl.mech_control |
---|
88 | file_ctrl.add_file(pseudo_image, filename='myphoto.jpg') |
---|
89 | self.browser.getControl("Save").click() |
---|
90 | self.assertMatches('...You are not entitled to upload passport pictures...', |
---|
91 | self.browser.contents) |
---|
92 | # The officer still sees the placeholder passport image |
---|
93 | self.browser.open(self.image_url('passport.jpg')) |
---|
94 | self.assertEqual( |
---|
95 | self.browser.headers['content-type'], 'image/jpeg') |
---|
96 | self.assertEqual(len(self.browser.contents), PH_LEN) |
---|
97 | # After adding the additional role ... |
---|
98 | prmglobal.assignRoleToPrincipal('waeup.PassportPictureManager', 'mrcrpu') |
---|
99 | # ... passport pictures can be uploaded |
---|
100 | self.browser.open(self.manage_path) |
---|
101 | self.fill_correct_values() |
---|
102 | pseudo_image = StringIO('I pretend to be a graphics file') |
---|
103 | ctrl = self.browser.getControl(name='form.passport') |
---|
104 | file_ctrl = ctrl.mech_control |
---|
105 | file_ctrl.add_file(pseudo_image, filename='myphoto.jpg') |
---|
106 | self.browser.getControl("Save").click() |
---|
107 | self.assertMatches('...Form has been saved...', self.browser.contents) |
---|
108 | # There is a correct <img> link included |
---|
109 | self.assertTrue( |
---|
110 | '<img src="passport.jpg" height="180px" />' in self.browser.contents) |
---|
111 | # Browsing the link shows a real image |
---|
112 | self.browser.open(self.image_url('passport.jpg')) |
---|
113 | self.assertEqual( |
---|
114 | self.browser.headers['content-type'], 'image/jpeg') |
---|
115 | self.assertEqual(len(self.browser.contents), 31) |
---|
116 | |
---|
117 | def test_pay_admission_checking_fee(self): |
---|
118 | IWorkflowState(self.applicant).setState('admitted') |
---|
119 | self.applicant.screening_score = 55 |
---|
120 | self.applicant.course_admitted = self.certificate |
---|
121 | self.login() |
---|
122 | # SessionConfiguration is not set, thus admission checking payment |
---|
123 | # is not necessary. Screening results and course admitted are visible. |
---|
124 | self.assertFalse( |
---|
125 | 'Add admission checking payment ticket' in self.browser.contents) |
---|
126 | self.assertTrue('<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">CERT1 - Unnamed Certificate</a>' in self.browser.contents) |
---|
127 | self.assertTrue('<span>55</span>' in self.browser.contents) |
---|
128 | configuration = CustomSessionConfiguration() |
---|
129 | configuration.academic_session = datetime.now().year - 2 |
---|
130 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
131 | # Admission checking fee is 0, thus admission checking payment |
---|
132 | # is not necessary. Screening results and course admitted are visible. |
---|
133 | self.browser.open(self.view_path) |
---|
134 | self.assertFalse( |
---|
135 | 'Add admission checking payment ticket' in self.browser.contents) |
---|
136 | self.assertTrue('<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">CERT1 - Unnamed Certificate</a>' in self.browser.contents) |
---|
137 | self.assertTrue('<span>55</span>' in self.browser.contents) |
---|
138 | configuration.admchecking_fee = 22.0 |
---|
139 | # Admission checking payment button is now visible, but screening results |
---|
140 | # and course admitted are not. |
---|
141 | self.browser.open(self.view_path) |
---|
142 | self.assertTrue( |
---|
143 | 'Add admission checking payment ticket' in self.browser.contents) |
---|
144 | self.assertFalse('<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">CERT1 - Unnamed Certificate</a>' in self.browser.contents) |
---|
145 | self.assertFalse('<span>55</span>' in self.browser.contents) |
---|
146 | # Application slip can't be downloaded |
---|
147 | self.assertFalse('Download application slip' in self.browser.contents) |
---|
148 | slip_path = self.view_path + '/application_slip.pdf' |
---|
149 | self.browser.open(slip_path) |
---|
150 | self.assertTrue( |
---|
151 | 'Please pay admission checking fee before trying to download' |
---|
152 | in self.browser.contents) |
---|
153 | # Pay admission checking fee. |
---|
154 | self.browser.getControl("Add admission checking").click() |
---|
155 | p_id = self.applicant.keys()[0] |
---|
156 | self.applicant[p_id].p_state = 'paid' |
---|
157 | # Screening results and course admitted are visible after payment. |
---|
158 | self.browser.open(self.view_path) |
---|
159 | self.assertFalse( |
---|
160 | 'Add admission checking payment ticket' in self.browser.contents) |
---|
161 | self.assertTrue('<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">CERT1 - Unnamed Certificate</a>' in self.browser.contents) |
---|
162 | self.assertTrue('<span>55</span>' in self.browser.contents) |
---|
163 | # Application slip can be downloaded again. |
---|
164 | self.browser.getLink("Download application slip").click() |
---|
165 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
166 | self.assertEqual(self.browser.headers['Content-Type'], |
---|
167 | 'application/pdf') |
---|
168 | return |
---|
169 | |
---|
170 | def test_application_slips(self): |
---|
171 | |
---|
172 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
173 | self.slip_path = self.view_path + '/application_slip.pdf' |
---|
174 | self.browser.open(self.manage_path) |
---|
175 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
176 | self.fill_correct_values() |
---|
177 | self.browser.getControl("Save").click() |
---|
178 | IWorkflowState(self.applicant).setState('submitted') |
---|
179 | self.browser.open(self.manage_path) |
---|
180 | self.browser.getLink("Download application slip").click() |
---|
181 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
182 | self.assertEqual(self.browser.headers['Content-Type'], |
---|
183 | 'application/pdf') |
---|
184 | path = os.path.join(samples_dir(), 'application_slip.pdf') |
---|
185 | open(path, 'wb').write(self.browser.contents) |
---|
186 | print "Sample application_slip.pdf written to %s" % path |
---|
187 | # Screening invitation letter is not yet available |
---|
188 | self.browser.open(self.view_path) |
---|
189 | self.assertFalse('invitation slip' in self.browser.contents) |
---|
190 | self.browser.open(self.view_path + '/screening_invitation_slip.pdf') |
---|
191 | self.assertTrue('Forbidden' in self.browser.contents) |
---|
192 | self.applicant.screening_date = u'any date' |
---|
193 | self.applicant.screening_venue = u'MAIN AUDITORIUM' |
---|
194 | self.applicantscontainer.application_slip_notice = u'This is an additional notice.' |
---|
195 | # The invitation letter can be printed |
---|
196 | self.browser.open(self.view_path) |
---|
197 | self.browser.getLink("invitation").click() |
---|
198 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
199 | self.assertEqual(self.browser.headers['Content-Type'], |
---|
200 | 'application/pdf') |
---|
201 | path = os.path.join(samples_dir(), 'screening_invitation_slip.pdf') |
---|
202 | open(path, 'wb').write(self.browser.contents) |
---|
203 | print "Sample screening_invitation_slip.pdf written to %s" % path |
---|
204 | |
---|
205 | def test_akoka_application_slip(self): |
---|
206 | |
---|
207 | # Remove required FieldProperty attribute first ... |
---|
208 | delattr(ApplicantsContainer, 'prefix') |
---|
209 | # ... and replace by akoka |
---|
210 | self.applicantscontainer.prefix = 'akj' |
---|
211 | self.applicantscontainer.title = u'FCET Akoka JUPEB Pre-Degree (Foundation) Studies 2016/2017' |
---|
212 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
213 | self.slip_path = self.view_path + '/application_slip.pdf' |
---|
214 | self.browser.open(self.manage_path) |
---|
215 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
216 | self.fill_correct_values() |
---|
217 | self.browser.getControl("Save").click() |
---|
218 | IWorkflowState(self.applicant).setState('submitted') |
---|
219 | self.browser.open(self.manage_path) |
---|
220 | self.browser.getLink("Download application slip").click() |
---|
221 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
222 | self.assertEqual(self.browser.headers['Content-Type'], |
---|
223 | 'application/pdf') |
---|
224 | path = os.path.join(samples_dir(), 'akoka_application_slip.pdf') |
---|
225 | open(path, 'wb').write(self.browser.contents) |
---|
226 | print "Sample akoka_application_slip.pdf written to %s" % path |
---|
227 | |
---|
228 | def test_nils_application_slip(self): |
---|
229 | |
---|
230 | # Remove required FieldProperty attribute first ... |
---|
231 | #delattr(ApplicantsContainer, 'prefix') |
---|
232 | # ... and replace by akoka |
---|
233 | self.applicantscontainer.prefix = 'pgn' |
---|
234 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
235 | self.slip_path = self.view_path + '/application_slip.pdf' |
---|
236 | self.browser.open(self.manage_path) |
---|
237 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
238 | self.fill_correct_values() |
---|
239 | self.browser.getControl("Save").click() |
---|
240 | IWorkflowState(self.applicant).setState('submitted') |
---|
241 | self.browser.open(self.manage_path) |
---|
242 | self.browser.getLink("Download application slip").click() |
---|
243 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
244 | self.assertEqual(self.browser.headers['Content-Type'], |
---|
245 | 'application/pdf') |
---|
246 | path = os.path.join(samples_dir(), 'nils_application_slip.pdf') |
---|
247 | open(path, 'wb').write(self.browser.contents) |
---|
248 | print "Sample nils_application_slip.pdf written to %s" % path |
---|
249 | |
---|
250 | def test_ictwk_application(self): |
---|
251 | |
---|
252 | # Remove required FieldProperty attribute first ... |
---|
253 | #delattr(ApplicantsContainer, 'prefix') |
---|
254 | # ... and replace by ictw |
---|
255 | self.applicantscontainer.prefix = 'ictwk' |
---|
256 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
257 | self.slip_path = self.view_path + '/application_slip.pdf' |
---|
258 | self.browser.open(self.manage_path) |
---|
259 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
260 | self.browser.getControl(name="form.firstname").value = 'John' |
---|
261 | self.browser.getControl(name="form.middlename").value = 'Anthony' |
---|
262 | self.browser.getControl(name="form.lastname").value = 'Tester' |
---|
263 | #self.browser.getControl(name="form.date_of_birth").value = '09/09/1988' |
---|
264 | self.browser.getControl(name="form.sex").value = ['m'] |
---|
265 | self.browser.getControl(name="form.email").value = 'xx@yy.zz' |
---|
266 | image = open(SAMPLE_IMAGE, 'rb') |
---|
267 | ctrl = self.browser.getControl(name='form.passport') |
---|
268 | file_ctrl = ctrl.mech_control |
---|
269 | file_ctrl.add_file(image, filename='myphoto.jpg') |
---|
270 | self.browser.getControl("Save").click() |
---|
271 | self.applicant.registration_cats = ['group', 'corporate'] |
---|
272 | IWorkflowState(self.applicant).setState('started') |
---|
273 | configuration = CustomSessionConfiguration() |
---|
274 | configuration.academic_session = session_1 |
---|
275 | configuration.application_fee = 0.0 |
---|
276 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
277 | self.browser.getControl("Add online payment ticket").click() |
---|
278 | self.assertMatches('...Payment ticket created...', |
---|
279 | self.browser.contents) |
---|
280 | self.assertEqual(self.applicant.values()[0].amount_auth, 450000) |
---|
281 | IWorkflowState(self.applicant).setState('submitted') |
---|
282 | self.browser.open(self.view_path) |
---|
283 | self.assertTrue('Group Registration @ ₦ 200000' in self.browser.contents) |
---|
284 | self.browser.open(self.manage_path) |
---|
285 | self.browser.getLink("Download application slip").click() |
---|
286 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
287 | self.assertEqual(self.browser.headers['Content-Type'], |
---|
288 | 'application/pdf') |
---|
289 | path = os.path.join(samples_dir(), 'ictwk_application_slip.pdf') |
---|
290 | open(path, 'wb').write(self.browser.contents) |
---|
291 | print "Sample ictwk_application_slip.pdf written to %s" % path |
---|