1 | ## $Id: test_browser.py 17876 2024-08-09 19:33:38Z 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 grok |
---|
19 | import datetime |
---|
20 | import pytz |
---|
21 | import os |
---|
22 | from StringIO import StringIO |
---|
23 | from zope.event import notify |
---|
24 | from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState |
---|
25 | from zope.component import createObject, getUtility |
---|
26 | from waeup.kofa.configuration import SessionConfiguration |
---|
27 | from waeup.kofa.interfaces import ( |
---|
28 | IUserAccount, IExtFileStore, IFileStoreNameChooser) |
---|
29 | from waeup.kofa.applicants.container import ApplicantsContainer |
---|
30 | from waeup.kofa.browser.tests.test_pdf import samples_dir |
---|
31 | from waeup.aaue.testing import FunctionalLayer |
---|
32 | from waeup.kofa.applicants.tests.test_browser import ( |
---|
33 | ApplicantsFullSetup, container_name_1, session_1) |
---|
34 | |
---|
35 | SAMPLE_IMAGE = os.path.join(os.path.dirname(__file__), 'test_image.jpg') |
---|
36 | |
---|
37 | class CustomApplicantUITest(ApplicantsFullSetup): |
---|
38 | """Perform some browser tests. |
---|
39 | """ |
---|
40 | |
---|
41 | layer = FunctionalLayer |
---|
42 | |
---|
43 | def test_show_credentials_on_landing_page(self): |
---|
44 | # An applicant can register himself. |
---|
45 | self.applicant.reg_number = u'1234' |
---|
46 | notify(grok.ObjectModifiedEvent(self.applicant)) |
---|
47 | self.browser.open('http://localhost/app/applicants/%s/' % container_name_1) |
---|
48 | self.browser.getLink("Register for application").click() |
---|
49 | # Fill the edit form with suitable values |
---|
50 | self.browser.getControl(name="form.firstname").value = 'Klaus' |
---|
51 | self.browser.getControl(name="form.lastname").value = 'Lutz' |
---|
52 | self.browser.getControl(name="form.email").value = 'xx@yy.zz' |
---|
53 | self.browser.getControl("Send login credentials").click() |
---|
54 | self.assertMatches('...Your registration was successful...', |
---|
55 | self.browser.contents) |
---|
56 | self.assertTrue('<td>Password:</td>' in self.browser.contents) |
---|
57 | return |
---|
58 | |
---|
59 | def test_payment(self): |
---|
60 | certificate = createObject('waeup.Certificate') |
---|
61 | certificate.code = 'CERT2' |
---|
62 | certificate.title = 'New Certificate' |
---|
63 | certificate.application_category = 'basic' |
---|
64 | self.app['faculties']['fac1']['dep1'].certificates.addCertificate( |
---|
65 | certificate) |
---|
66 | certificate = createObject('waeup.Certificate') |
---|
67 | certificate.code = 'CERT3' |
---|
68 | certificate.title = 'New Certificate 2' |
---|
69 | certificate.application_category = 'basic' |
---|
70 | self.app['faculties']['fac1']['dep1'].certificates.addCertificate( |
---|
71 | certificate) |
---|
72 | configuration = SessionConfiguration() |
---|
73 | configuration.academic_session = session_1 |
---|
74 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
75 | self.applicantscontainer.application_fee = 200.0 |
---|
76 | self.applicant.jamb_score = 1000000 |
---|
77 | self.login() |
---|
78 | self.browser.open(self.edit_path) |
---|
79 | self.browser.getControl(name="form.course2").value = ['CERT2'] |
---|
80 | self.browser.getControl(name="form.course3").value = ['CERT3'] |
---|
81 | self.browser.getControl(name="form.date_of_birth").value = '09/09/1988' |
---|
82 | self.browser.getControl(name="form.email").value = 'xx@yy.zz' |
---|
83 | #self.browser.getControl(name="form.programme_type").value = ['regular'] |
---|
84 | self.browser.getControl(name="form.nationality").value = ['NG'] |
---|
85 | self.browser.getControl(name="form.sex").value = ['m'] |
---|
86 | self.browser.getControl(name="form.lastname").value = 'Merkel' |
---|
87 | self.browser.getControl(name="form.nin").value = '1234567' |
---|
88 | self.browser.getControl(name="form.fst_sit_fname").value = 'name' |
---|
89 | self.browser.getControl(name="form.fst_sit_no").value = 'no' |
---|
90 | self.browser.getControl(name="form.fst_sit_sc_pin").value = 'pin' |
---|
91 | self.browser.getControl(name="form.fst_sit_sc_serial_number").value = 'serial' |
---|
92 | self.browser.getControl(name="form.fst_sit_date").value = '09/09/2000' |
---|
93 | self.browser.getControl(name="form.fst_sit_type").value = ['ssce'] |
---|
94 | self.browser.getControl("Save").click() |
---|
95 | self.browser.getControl("Add online payment ticket").click() |
---|
96 | self.assertMatches('...Payment ticket created...', |
---|
97 | self.browser.contents) |
---|
98 | # Ticket can't be downloaded because payment gatewy is not specified |
---|
99 | self.assertFalse("Download payment slip" in self.browser.contents) |
---|
100 | self.applicant.payments[0].r_company = u'interswitch' |
---|
101 | self.browser.open(self.edit_path) |
---|
102 | self.browser.getLink(self.applicant.payments[0].p_id).click() |
---|
103 | # Payment tickets can now be downloaded without submitting the form. |
---|
104 | self.browser.getLink("Download payment slip").click() |
---|
105 | self.assertEqual(self.browser.headers['Content-Type'], |
---|
106 | 'application/pdf') |
---|
107 | # AAUE applicants never see the 'Remove Selected Tickets' button. |
---|
108 | self.browser.open(self.edit_path) |
---|
109 | self.assertFalse('Remove' in self.browser.contents) |
---|
110 | return |
---|
111 | |
---|
112 | def test_screening_invitation_download(self): |
---|
113 | self.login() |
---|
114 | self.applicant.screening_date = u'29th August 2016 @ 8:30 am' |
---|
115 | self.applicant.screening_venue = u'Main Auditorium' |
---|
116 | self.applicant.lastname = u'Cox' |
---|
117 | self.applicant.firstname = u'Jo' |
---|
118 | self.applicant.email = 'xx@yy.zz' |
---|
119 | self.browser.open(self.view_path) |
---|
120 | self.assertFalse("Download application slip" in self.browser.contents) |
---|
121 | IWorkflowState(self.applicant).setState('submitted') |
---|
122 | self.browser.open(self.view_path) |
---|
123 | self.browser.getLink("screening invitation").click() |
---|
124 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
125 | self.assertEqual( |
---|
126 | self.browser.headers['Content-Type'], 'application/pdf') |
---|
127 | path = os.path.join(samples_dir(), 'screening_invitation.pdf') |
---|
128 | open(path, 'wb').write(self.browser.contents) |
---|
129 | print "Sample PDF screening_invitation.pdf written to %s" % path |
---|
130 | return |
---|
131 | |
---|
132 | def test_application_slips(self): |
---|
133 | delattr(ApplicantsContainer, 'prefix') |
---|
134 | self.applicantscontainer.prefix = 'ude' |
---|
135 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
136 | self.slip_path = self.view_path + '/application_slip.pdf' |
---|
137 | self.browser.open(self.manage_path) |
---|
138 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
139 | self.fill_correct_values() |
---|
140 | self.browser.getControl("Save").click() |
---|
141 | IWorkflowState(self.applicant).setState('admitted') |
---|
142 | self.applicant.course_admitted = self.certificate |
---|
143 | self.browser.open(self.view_path) |
---|
144 | self.browser.getLink("Download application slip").click() |
---|
145 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
146 | self.assertEqual(self.browser.headers['Content-Type'], |
---|
147 | 'application/pdf') |
---|
148 | path = os.path.join(samples_dir(), 'application_slip.pdf') |
---|
149 | open(path, 'wb').write(self.browser.contents) |
---|
150 | print "Sample application_slip.pdf written to %s" % path |
---|
151 | |
---|
152 | def test_transcript_application_manage(self): |
---|
153 | # Add trans applicants container |
---|
154 | self.transcontainer = ApplicantsContainer() |
---|
155 | self.transcontainer.mode = 'create' |
---|
156 | self.transcontainer.code = u'trans%s' % session_1 |
---|
157 | self.transcontainer.prefix = u'trans' |
---|
158 | self.transcontainer.application_category = u'no' |
---|
159 | self.transcontainer.year = session_1 |
---|
160 | self.transcontainer.application_fee = 300.0 |
---|
161 | self.transcontainer.title = u'This is the trans%s container' % session_1 |
---|
162 | self.app['applicants'][self.transcontainer.code] = self.transcontainer |
---|
163 | delta = datetime.timedelta(days=10) |
---|
164 | self.transcontainer.startdate = datetime.datetime.now(pytz.utc) - delta |
---|
165 | self.transcontainer.enddate = datetime.datetime.now(pytz.utc) + delta |
---|
166 | # Add applicant |
---|
167 | transapplicant = createObject(u'waeup.Applicant') |
---|
168 | transapplicant.firstname = u'Anna' |
---|
169 | transapplicant.lastname = u'Post' |
---|
170 | self.app['applicants'][self.transcontainer.code].addApplicant(transapplicant) |
---|
171 | self.transapplication_number = transapplicant.application_number |
---|
172 | self.transapplicant = self.app['applicants'][self.transcontainer.code][ |
---|
173 | self.transapplication_number] |
---|
174 | self.transapplicant_path = ('http://localhost/app/applicants/trans%s/%s' |
---|
175 | % (session_1, self.transapplication_number)) |
---|
176 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
177 | self.browser.open(self.transapplicant_path) |
---|
178 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
179 | self.assertTrue("Dispatch Address" in self.browser.contents) |
---|
180 | |
---|
181 | def _prepare_cert_container(self): |
---|
182 | # Add cert applicants container |
---|
183 | self.certcontainer = ApplicantsContainer() |
---|
184 | self.certcontainer.mode = 'update' |
---|
185 | self.certcontainer.code = u'cert%s' % session_1 |
---|
186 | self.certcontainer.prefix = u'cert' |
---|
187 | self.certcontainer.application_category = u'no' |
---|
188 | self.certcontainer.year = session_1 |
---|
189 | self.certcontainer.application_fee = 300.0 |
---|
190 | self.certcontainer.title = u'This is the cert%s container' % session_1 |
---|
191 | self.app['applicants'][self.certcontainer.code] = self.certcontainer |
---|
192 | delta = datetime.timedelta(days=10) |
---|
193 | self.certcontainer.startdate = datetime.datetime.now(pytz.utc) - delta |
---|
194 | self.certcontainer.enddate = datetime.datetime.now(pytz.utc) + delta |
---|
195 | # Add applicant |
---|
196 | certapplicant = createObject(u'waeup.Applicant') |
---|
197 | certapplicant.firstname = u'Anna' |
---|
198 | certapplicant.lastname = u'Post' |
---|
199 | certapplicant.reg_number = u'1234%s' % self.certcontainer.code |
---|
200 | self.app['applicants'][self.certcontainer.code].addApplicant(certapplicant) |
---|
201 | self.certapplication_number = certapplicant.application_number |
---|
202 | self.certapplicant = self.app['applicants'][self.certcontainer.code][ |
---|
203 | self.certapplication_number] |
---|
204 | self.certcontainer_path = ('http://localhost/app/applicants/cert%s' |
---|
205 | % session_1) |
---|
206 | self.certapplicant_path = ('http://localhost/app/applicants/cert%s/%s' |
---|
207 | % (session_1, self.certapplication_number)) |
---|
208 | |
---|
209 | def test_certificate_request_manage(self): |
---|
210 | self._prepare_cert_container() |
---|
211 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
212 | self.browser.open(self.certapplicant_path) |
---|
213 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
214 | #self.assertTrue("Dispatch Address" in self.browser.contents) |
---|
215 | |
---|
216 | def test_certificate_request_update(self): |
---|
217 | self._prepare_cert_container() |
---|
218 | #IWorkflowState(self.applicant).setState('initialized') |
---|
219 | self.browser.open(self.certcontainer_path + '/register') |
---|
220 | self.browser.getControl(name="form.lastname").value = 'post' |
---|
221 | self.browser.getControl(name="form.reg_number").value = '1234' |
---|
222 | self.browser.getControl(name="form.email").value = 'new@yy.zz' |
---|
223 | self.browser.getControl("Send login credentials").click() |
---|
224 | # Yeah, we succeded ... |
---|
225 | self.assertTrue('Your registration was successful.' |
---|
226 | in self.browser.contents) |
---|
227 | |
---|
228 | def test_pg_application_manage(self): |
---|
229 | # Add pg applicants container |
---|
230 | self.pgcontainer = ApplicantsContainer() |
---|
231 | self.pgcontainer.mode = 'create' |
---|
232 | self.pgcontainer.code = u'pgft%s' % session_1 |
---|
233 | self.pgcontainer.prefix = u'pgft' |
---|
234 | self.pgcontainer.application_category = u'no' |
---|
235 | self.pgcontainer.year = session_1 |
---|
236 | self.pgcontainer.application_fee = 300.0 |
---|
237 | self.pgcontainer.title = u'This is the pgft%s container' % session_1 |
---|
238 | self.app['applicants'][self.pgcontainer.code] = self.pgcontainer |
---|
239 | delta = datetime.timedelta(days=10) |
---|
240 | self.pgcontainer.startdate = datetime.datetime.now(pytz.utc) - delta |
---|
241 | self.pgcontainer.enddate = datetime.datetime.now(pytz.utc) + delta |
---|
242 | # Add applicant |
---|
243 | pgapplicant = createObject(u'waeup.Applicant') |
---|
244 | pgapplicant.firstname = u'Anna' |
---|
245 | pgapplicant.lastname = u'Post' |
---|
246 | self.app['applicants'][self.pgcontainer.code].addApplicant(pgapplicant) |
---|
247 | self.pgapplication_number = pgapplicant.application_number |
---|
248 | self.pgapplicant = self.app['applicants'][self.pgcontainer.code][ |
---|
249 | self.pgapplication_number] |
---|
250 | self.pgapplicant_path = ('http://localhost/app/applicants/pgft%s/%s' |
---|
251 | % (session_1, self.pgapplication_number)) |
---|
252 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
253 | self.browser.open(self.pgapplicant_path) |
---|
254 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
255 | self.assertTrue("3rd Higher Education Record" in self.browser.contents) |
---|
256 | |
---|
257 | def test_transcript_payment(self): |
---|
258 | configuration = SessionConfiguration() |
---|
259 | configuration.academic_session = session_1 |
---|
260 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
261 | # Add special application container |
---|
262 | applicantscontainer = ApplicantsContainer() |
---|
263 | applicantscontainer.year = session_1 |
---|
264 | applicantscontainer.application_fee = 200.0 |
---|
265 | applicantscontainer.code = u'trans1234' |
---|
266 | applicantscontainer.prefix = 'trans' |
---|
267 | applicantscontainer.title = u'This is a trans container' |
---|
268 | applicantscontainer.application_category = 'no' |
---|
269 | applicantscontainer.mode = 'create' |
---|
270 | applicantscontainer.strict_deadline = True |
---|
271 | delta = datetime.timedelta(days=10) |
---|
272 | applicantscontainer.startdate = datetime.datetime.now(pytz.utc) - delta |
---|
273 | applicantscontainer.enddate = datetime.datetime.now(pytz.utc) + delta |
---|
274 | self.app['applicants']['trans1234'] = applicantscontainer |
---|
275 | # Add an applicant |
---|
276 | applicant = createObject('waeup.Applicant') |
---|
277 | # reg_number is the only field which has to be preset here |
---|
278 | # because managers are allowed to edit this required field |
---|
279 | applicant.reg_number = u'12345' |
---|
280 | self.app['applicants']['trans1234'].addApplicant(applicant) |
---|
281 | IUserAccount( |
---|
282 | self.app['applicants']['trans1234'][ |
---|
283 | applicant.application_number]).setPassword('apwd') |
---|
284 | # Login |
---|
285 | self.browser.open(self.login_path) |
---|
286 | self.browser.getControl( |
---|
287 | name="form.login").value = applicant.applicant_id |
---|
288 | self.browser.getControl(name="form.password").value = 'apwd' |
---|
289 | self.browser.getControl("Login").click() |
---|
290 | self.browser.getLink("Edit").click() |
---|
291 | self.browser.getControl(name="form.date_of_birth").value = '09/09/1988' |
---|
292 | self.browser.getControl(name="form.email").value = 'xx@yy.zz' |
---|
293 | self.browser.getControl(name="form.nationality").value = ['NG'] |
---|
294 | self.browser.getControl(name="form.firstname").value = 'Angela' |
---|
295 | self.browser.getControl(name="form.lastname").value = 'Merkel' |
---|
296 | self.browser.getControl(name="form.sex").value = ['f'] |
---|
297 | self.browser.getControl(name="form.no_copies").value = ['3'] |
---|
298 | self.browser.getControl(name="form.course_studied").value = ['CERT1'] |
---|
299 | self.browser.getControl(name="form.matric_number").value = '234' |
---|
300 | self.browser.getControl(name="form.place_of_birth").value = 'Bochum' |
---|
301 | self.browser.getControl(name="form.dispatch_address").value = 'Kuensche' |
---|
302 | self.browser.getControl(name="form.perm_address").value = 'Kuensche' |
---|
303 | self.browser.getControl(name="form.entry_mode").value = ['ug_ft'] |
---|
304 | self.browser.getControl(name="form.entry_session").value = ['2014'] |
---|
305 | self.browser.getControl(name="form.end_session").value = ['2015'] |
---|
306 | self.browser.getControl(name="form.phone.country").value = ['+234'] |
---|
307 | self.browser.getControl(name="form.phone.ext").value = '5678' |
---|
308 | self.browser.getControl("Save").click() |
---|
309 | self.browser.getControl("Add online payment ticket").click() |
---|
310 | self.assertTrue('Payment ticket created' in self.browser.contents) |
---|
311 | self.assertTrue('<span>200.0</span>' in self.browser.contents) |
---|
312 | self.assertEqual(applicant.values()[0].amount_auth, 200.0) |
---|
313 | return |
---|
314 | |
---|
315 | def test_view_course_admitted(self): |
---|
316 | self.applicant.course_admitted = self.certificate |
---|
317 | self.login() |
---|
318 | self.assertFalse('Admitted Course of Study' in self.browser.contents) |
---|
319 | return |
---|
320 | |
---|
321 | def test_upload_stateresult_by_manager(self): |
---|
322 | # Add trans applicants container |
---|
323 | self.transcontainer = ApplicantsContainer() |
---|
324 | self.transcontainer.mode = 'create' |
---|
325 | self.transcontainer.code = u'trans%s' % session_1 |
---|
326 | self.transcontainer.prefix = u'trans' |
---|
327 | self.transcontainer.application_category = u'no' |
---|
328 | self.transcontainer.year = session_1 |
---|
329 | self.transcontainer.application_fee = 300.0 |
---|
330 | self.transcontainer.title = u'This is the trans%s container' % session_1 |
---|
331 | self.app['applicants'][self.transcontainer.code] = self.transcontainer |
---|
332 | delta = datetime.timedelta(days=10) |
---|
333 | self.transcontainer.startdate = datetime.datetime.now(pytz.utc) - delta |
---|
334 | self.transcontainer.enddate = datetime.datetime.now(pytz.utc) + delta |
---|
335 | # Add applicant |
---|
336 | transapplicant = createObject(u'waeup.Applicant') |
---|
337 | transapplicant.firstname = u'Anna' |
---|
338 | transapplicant.lastname = u'Post' |
---|
339 | self.app['applicants'][self.transcontainer.code].addApplicant(transapplicant) |
---|
340 | self.transapplicant = self.app['applicants'][self.transcontainer.code][ |
---|
341 | transapplicant.application_number] |
---|
342 | self.transapplicant_view_path = ('http://localhost/app/applicants/trans%s/%s' |
---|
343 | % (session_1, transapplicant.application_number)) |
---|
344 | self.transapplicant_manage_path = ('http://localhost/app/applicants/trans%s/%s/manage' |
---|
345 | % (session_1, transapplicant.application_number)) |
---|
346 | # Login |
---|
347 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
348 | self.browser.open(self.transapplicant_manage_path) |
---|
349 | # Create a pseudo file with acceptable size |
---|
350 | #pdf_content = 'A' * 1024 * 300 # A string of 300 KB size |
---|
351 | #pseudo_pdf = StringIO(pdf_content) |
---|
352 | image = open(SAMPLE_IMAGE, 'rb') |
---|
353 | ctrl = self.browser.getControl(name='stateresult') |
---|
354 | file_ctrl = ctrl.mech_control |
---|
355 | file_ctrl.add_file(image, filename='my_scan.jpg') |
---|
356 | self.browser.getControl("Save").click() # submit form |
---|
357 | # Even though the form could not be saved ... |
---|
358 | self.assertTrue('Required input is missing' in self.browser.contents) |
---|
359 | # ... the file has been successfully uploaded |
---|
360 | image_url = self.transapplicant_manage_path.replace('manage', 'stateresult') |
---|
361 | self.browser.open(image_url) |
---|
362 | self.assertEqual( |
---|
363 | self.browser.headers['content-type'], 'image/jpeg') |
---|
364 | self.assertEqual(len(self.browser.contents), 2787) |
---|
365 | # There is really a file stored for the applicant |
---|
366 | storage = getUtility(IExtFileStore) |
---|
367 | file_id = IFileStoreNameChooser(self.transapplicant).chooseName( |
---|
368 | attr='stateresult.pdf') |
---|
369 | # The stored file can be fetched |
---|
370 | fd = storage.getFile(file_id) |
---|
371 | file_len = len(fd.read()) |
---|
372 | self.assertEqual(file_len, 2787) |
---|
373 | # A file link is displayed on the edit view ... |
---|
374 | self.browser.open(self.transapplicant_manage_path) |
---|
375 | self.assertTrue('<a href="stateresult">' in self.browser.contents) |
---|
376 | # ... and on the dislay view |
---|
377 | self.browser.open(self.transapplicant_view_path) |
---|
378 | self.assertTrue('stateresult">Statement of Result</a>' |
---|
379 | in self.browser.contents) |
---|
380 | # Adding file is properly logged |
---|
381 | logfile = os.path.join( |
---|
382 | self.app['datacenter'].storage, 'logs', 'applicants.log') |
---|
383 | logcontent = open(logfile).read() |
---|
384 | self.assertTrue( |
---|
385 | 'zope.mgr - waeup.aaue.applicants.browser.CustomApplicantManageFormPage' |
---|
386 | ' - %s - saved: stateresult' |
---|
387 | % (self.transapplicant.applicant_id) |
---|
388 | in logcontent) |
---|
389 | # When an applicant is removed, also the pdf files are gone. |
---|
390 | del self.app['applicants'][self.transcontainer.code][self.transapplicant.application_number] |
---|
391 | fd = storage.getFile(file_id) |
---|
392 | self.assertTrue(fd is None) |
---|
393 | |
---|
394 | def test_upload_verificationdoc_by_manager(self): |
---|
395 | # Add ver applicants container |
---|
396 | self.vercontainer = ApplicantsContainer() |
---|
397 | self.vercontainer.mode = 'create' |
---|
398 | self.vercontainer.code = u'ver%s' % session_1 |
---|
399 | self.vercontainer.prefix = u'ver' |
---|
400 | self.vercontainer.application_category = u'no' |
---|
401 | self.vercontainer.year = session_1 |
---|
402 | self.vercontainer.application_fee = 300.0 |
---|
403 | self.vercontainer.title = u'This is the ver%s container' % session_1 |
---|
404 | self.app['applicants'][self.vercontainer.code] = self.vercontainer |
---|
405 | delta = datetime.timedelta(days=10) |
---|
406 | self.vercontainer.startdate = datetime.datetime.now(pytz.utc) - delta |
---|
407 | self.vercontainer.enddate = datetime.datetime.now(pytz.utc) + delta |
---|
408 | # Add applicant |
---|
409 | verapplicant = createObject(u'waeup.Applicant') |
---|
410 | verapplicant.firstname = u'Anna' |
---|
411 | verapplicant.lastname = u'Post' |
---|
412 | self.app['applicants'][self.vercontainer.code].addApplicant(verapplicant) |
---|
413 | self.verapplicant = self.app['applicants'][self.vercontainer.code][ |
---|
414 | verapplicant.application_number] |
---|
415 | self.verapplicant_view_path = ('http://localhost/app/applicants/ver%s/%s' |
---|
416 | % (session_1, verapplicant.application_number)) |
---|
417 | self.verapplicant_manage_path = ('http://localhost/app/applicants/ver%s/%s/manage' |
---|
418 | % (session_1, verapplicant.application_number)) |
---|
419 | # Login |
---|
420 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
421 | self.browser.open(self.verapplicant_manage_path) |
---|
422 | # Create a pseudo file with acceptable size |
---|
423 | #pdf_content = 'A' * 1024 * 300 # A string of 300 KB size |
---|
424 | #pseudo_pdf = StringIO(pdf_content) |
---|
425 | image = open(SAMPLE_IMAGE, 'rb') |
---|
426 | ctrl = self.browser.getControl(name='verificationdoc') |
---|
427 | file_ctrl = ctrl.mech_control |
---|
428 | file_ctrl.add_file(image, filename='my_scan.jpg') |
---|
429 | self.browser.getControl("Save").click() # submit form |
---|
430 | # Even though the form could not be saved ... |
---|
431 | self.assertTrue('Required input is missing' in self.browser.contents) |
---|
432 | # ... the file has been successfully uploaded |
---|
433 | image_url = self.verapplicant_manage_path.replace('manage', 'verificationdoc') |
---|
434 | self.browser.open(image_url) |
---|
435 | self.assertEqual( |
---|
436 | self.browser.headers['content-type'], 'image/jpeg') |
---|
437 | self.assertEqual(len(self.browser.contents), 2787) |
---|
438 | # There is really a file stored for the applicant |
---|
439 | storage = getUtility(IExtFileStore) |
---|
440 | file_id = IFileStoreNameChooser(self.verapplicant).chooseName( |
---|
441 | attr='verificationdoc.pdf') |
---|
442 | # The stored file can be fetched |
---|
443 | fd = storage.getFile(file_id) |
---|
444 | file_len = len(fd.read()) |
---|
445 | self.assertEqual(file_len, 2787) |
---|
446 | # A file link is displayed on the edit view ... |
---|
447 | self.browser.open(self.verapplicant_manage_path) |
---|
448 | self.assertTrue('<a href="verificationdoc">' in self.browser.contents) |
---|
449 | # ... and on the dislay view |
---|
450 | self.browser.open(self.verapplicant_view_path) |
---|
451 | self.assertTrue('verificationdoc">Result/Certificate Document</a>' |
---|
452 | in self.browser.contents) |
---|
453 | # Adding file is properly logged |
---|
454 | logfile = os.path.join( |
---|
455 | self.app['datacenter'].storage, 'logs', 'applicants.log') |
---|
456 | logcontent = open(logfile).read() |
---|
457 | self.assertTrue( |
---|
458 | 'zope.mgr - waeup.aaue.applicants.browser.CustomApplicantManageFormPage' |
---|
459 | ' - %s - saved: verificationdoc' |
---|
460 | % (self.verapplicant.applicant_id) |
---|
461 | in logcontent) |
---|
462 | # When an applicant is removed, also the files are gone. |
---|
463 | del self.app['applicants'][self.vercontainer.code][self.verapplicant.application_number] |
---|
464 | fd = storage.getFile(file_id) |
---|
465 | self.assertTrue(fd is None) |
---|