source: main/waeup.aaue/trunk/src/waeup/aaue/applicants/tests/test_browser.py @ 15803

Last change on this file since 15803 was 15803, checked in by Henrik Bettermann, 5 years ago

Adjust tests to changes in Nigeria package.

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