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

Last change on this file since 15327 was 15266, checked in by Henrik Bettermann, 6 years ago

Make most transcript and certificate application fields required.

  • Property svn:keywords set to Id
File size: 19.1 KB
Line 
1## $Id: test_browser.py 15266 2018-12-12 09:17:35Z 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        configuration = SessionConfiguration()
59        configuration.academic_session = session_1
60        self.app['configuration'].addSessionConfiguration(configuration)
61        self.applicantscontainer.application_fee = 200.0
62        self.login()
63        self.browser.open(self.edit_path)
64        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
65        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
66        #self.browser.getControl(name="form.programme_type").value = ['regular']
67        self.browser.getControl(name="form.nationality").value = ['NG']
68        self.browser.getControl(name="form.sex").value = ['m']
69        self.browser.getControl(name="form.lastname").value = 'Merkel'
70        self.browser.getControl(name="form.fst_sit_fname").value = 'name'
71        self.browser.getControl(name="form.fst_sit_no").value = 'no'
72        self.browser.getControl(name="form.fst_sit_sc_pin").value = 'pin'
73        self.browser.getControl(name="form.fst_sit_sc_serial_number").value = 'serial'
74        self.browser.getControl(name="form.fst_sit_date").value = '09/09/2000'
75        self.browser.getControl(name="form.fst_sit_type").value = ['ssce']
76        self.browser.getControl("Save").click()
77        self.browser.getControl("Add online payment ticket").click()
78        self.assertMatches('...Payment ticket created...',
79                           self.browser.contents)
80        # Payment tickets can be downloaded without submitting the form.
81        self.browser.getLink("Download payment slip").click()
82        self.assertEqual(self.browser.headers['Content-Type'],
83                 'application/pdf')
84        # AAUE applicants never see the 'Remove Selected Tickets' button.
85        self.browser.open(self.edit_path)
86        self.assertFalse('Remove' in self.browser.contents)
87        return
88
89    def test_screening_invitation_download(self):
90        self.login()
91        self.applicant.screening_date = u'29th August 2016 @ 8:30 am'
92        self.applicant.screening_venue = u'Main Auditorium'
93        self.applicant.lastname = u'Cox'
94        self.applicant.firstname = u'Jo'
95        self.applicant.email = 'xx@yy.zz'
96        self.browser.open(self.view_path)
97        self.assertFalse("Download application slip" in self.browser.contents)
98        IWorkflowState(self.applicant).setState('submitted')
99        self.browser.open(self.view_path)
100        self.browser.getLink("screening invitation").click()
101        self.assertEqual(self.browser.headers['Status'], '200 Ok')
102        self.assertEqual(
103            self.browser.headers['Content-Type'], 'application/pdf')
104        path = os.path.join(samples_dir(), 'screening_invitation.pdf')
105        open(path, 'wb').write(self.browser.contents)
106        print "Sample PDF screening_invitation.pdf written to %s" % path
107        return
108
109    def test_application_slips(self):
110        delattr(ApplicantsContainer, 'prefix')
111        self.applicantscontainer.prefix = 'ude'
112        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
113        self.slip_path = self.view_path + '/application_slip.pdf'
114        self.browser.open(self.manage_path)
115        self.assertEqual(self.browser.headers['Status'], '200 Ok')
116        self.fill_correct_values()
117        self.browser.getControl("Save").click()
118        IWorkflowState(self.applicant).setState('admitted')
119        self.applicant.course_admitted = self.certificate
120        self.browser.open(self.manage_path)
121        self.browser.getLink("Download application slip").click()
122        self.assertEqual(self.browser.headers['Status'], '200 Ok')
123        self.assertEqual(self.browser.headers['Content-Type'],
124                         'application/pdf')
125        path = os.path.join(samples_dir(), 'application_slip.pdf')
126        open(path, 'wb').write(self.browser.contents)
127        print "Sample application_slip.pdf written to %s" % path
128
129    def test_transcript_application_manage(self):
130        # Add trans applicants container
131        self.transcontainer = ApplicantsContainer()
132        self.transcontainer.mode = 'create'
133        self.transcontainer.code = u'trans%s' % session_1
134        self.transcontainer.prefix = u'trans'
135        self.transcontainer.application_category = u'no'
136        self.transcontainer.year = session_1
137        self.transcontainer.application_fee = 300.0
138        self.transcontainer.title = u'This is the trans%s container' % session_1
139        self.app['applicants'][self.transcontainer.code] = self.transcontainer
140        delta = datetime.timedelta(days=10)
141        self.transcontainer.startdate = datetime.datetime.now(pytz.utc) - delta
142        self.transcontainer.enddate = datetime.datetime.now(pytz.utc) + delta
143        # Add applicant
144        transapplicant = createObject(u'waeup.Applicant')
145        transapplicant.firstname = u'Anna'
146        transapplicant.lastname = u'Post'
147        self.app['applicants'][self.transcontainer.code].addApplicant(transapplicant)
148        self.transapplication_number = transapplicant.application_number
149        self.transapplicant = self.app['applicants'][self.transcontainer.code][
150            self.transapplication_number]
151        self.transapplicant_path = ('http://localhost/app/applicants/trans%s/%s'
152            % (session_1, self.transapplication_number))
153        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
154        self.browser.open(self.transapplicant_path)
155        self.assertEqual(self.browser.headers['Status'], '200 Ok')
156        self.assertTrue("Dispatch Address" in self.browser.contents)
157
158    def _prepare_cert_container(self):
159        # Add cert applicants container
160        self.certcontainer = ApplicantsContainer()
161        self.certcontainer.mode = 'update'
162        self.certcontainer.code = u'cert%s' % session_1
163        self.certcontainer.prefix = u'cert'
164        self.certcontainer.application_category = u'no'
165        self.certcontainer.year = session_1
166        self.certcontainer.application_fee = 300.0
167        self.certcontainer.title = u'This is the cert%s container' % session_1
168        self.app['applicants'][self.certcontainer.code] = self.certcontainer
169        delta = datetime.timedelta(days=10)
170        self.certcontainer.startdate = datetime.datetime.now(pytz.utc) - delta
171        self.certcontainer.enddate = datetime.datetime.now(pytz.utc) + delta
172        # Add applicant
173        certapplicant = createObject(u'waeup.Applicant')
174        certapplicant.firstname = u'Anna'
175        certapplicant.lastname = u'Post'
176        certapplicant.reg_number = u'1234%s' % self.certcontainer.code
177        self.app['applicants'][self.certcontainer.code].addApplicant(certapplicant)
178        self.certapplication_number = certapplicant.application_number
179        self.certapplicant = self.app['applicants'][self.certcontainer.code][
180            self.certapplication_number]
181        self.certcontainer_path = ('http://localhost/app/applicants/cert%s'
182            % session_1)
183        self.certapplicant_path = ('http://localhost/app/applicants/cert%s/%s'
184            % (session_1, self.certapplication_number))
185
186    def test_certificate_request_manage(self):
187        self._prepare_cert_container()
188        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
189        self.browser.open(self.certapplicant_path)
190        self.assertEqual(self.browser.headers['Status'], '200 Ok')
191        #self.assertTrue("Dispatch Address" in self.browser.contents)
192
193    def test_certificate_request_update(self):
194        self._prepare_cert_container()
195        #IWorkflowState(self.applicant).setState('initialized')
196        self.browser.open(self.certcontainer_path + '/register')
197        self.browser.getControl(name="form.lastname").value = 'post'
198        self.browser.getControl(name="form.reg_number").value = '1234'
199        self.browser.getControl(name="form.email").value = 'new@yy.zz'
200        self.browser.getControl("Send login credentials").click()
201        # Yeah, we succeded ...
202        self.assertTrue('Your registration was successful.'
203            in self.browser.contents)
204
205    def test_pg_application_manage(self):
206        # Add pg applicants container
207        self.pgcontainer = ApplicantsContainer()
208        self.pgcontainer.mode = 'create'
209        self.pgcontainer.code = u'pgft%s' % session_1
210        self.pgcontainer.prefix = u'pgft'
211        self.pgcontainer.application_category = u'no'
212        self.pgcontainer.year = session_1
213        self.pgcontainer.application_fee = 300.0
214        self.pgcontainer.title = u'This is the pgft%s container' % session_1
215        self.app['applicants'][self.pgcontainer.code] = self.pgcontainer
216        delta = datetime.timedelta(days=10)
217        self.pgcontainer.startdate = datetime.datetime.now(pytz.utc) - delta
218        self.pgcontainer.enddate = datetime.datetime.now(pytz.utc) + delta
219        # Add applicant
220        pgapplicant = createObject(u'waeup.Applicant')
221        pgapplicant.firstname = u'Anna'
222        pgapplicant.lastname = u'Post'
223        self.app['applicants'][self.pgcontainer.code].addApplicant(pgapplicant)
224        self.pgapplication_number = pgapplicant.application_number
225        self.pgapplicant = self.app['applicants'][self.pgcontainer.code][
226            self.pgapplication_number]
227        self.pgapplicant_path = ('http://localhost/app/applicants/pgft%s/%s'
228            % (session_1, self.pgapplication_number))
229        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
230        self.browser.open(self.pgapplicant_path)
231        self.assertEqual(self.browser.headers['Status'], '200 Ok')
232        self.assertTrue("3rd Higher Education Record" in self.browser.contents)
233
234    def test_transcript_payment(self):
235        configuration = SessionConfiguration()
236        configuration.academic_session = session_1
237        self.app['configuration'].addSessionConfiguration(configuration)
238        # Add special application container
239        applicantscontainer = ApplicantsContainer()
240        applicantscontainer.year = session_1
241        applicantscontainer.application_fee = 200.0
242        applicantscontainer.code = u'trans1234'
243        applicantscontainer.prefix = 'trans'
244        applicantscontainer.title = u'This is a trans container'
245        applicantscontainer.application_category = 'no'
246        applicantscontainer.mode = 'create'
247        applicantscontainer.strict_deadline = True
248        delta = datetime.timedelta(days=10)
249        applicantscontainer.startdate = datetime.datetime.now(pytz.utc) - delta
250        applicantscontainer.enddate = datetime.datetime.now(pytz.utc) + delta
251        self.app['applicants']['trans1234'] = applicantscontainer
252        # Add an applicant
253        applicant = createObject('waeup.Applicant')
254        # reg_number is the only field which has to be preset here
255        # because managers are allowed to edit this required field
256        applicant.reg_number = u'12345'
257        self.app['applicants']['trans1234'].addApplicant(applicant)
258        IUserAccount(
259            self.app['applicants']['trans1234'][
260            applicant.application_number]).setPassword('apwd')
261        # Login
262        self.browser.open(self.login_path)
263        self.browser.getControl(
264            name="form.login").value = applicant.applicant_id
265        self.browser.getControl(name="form.password").value = 'apwd'
266        self.browser.getControl("Login").click()
267        self.browser.getLink("Edit").click()
268        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
269        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
270        self.browser.getControl(name="form.nationality").value = ['NG']
271        #self.browser.getControl(name="form.sex").value = ['f']
272        self.browser.getControl(name="form.firstname").value = 'Angela'
273        self.browser.getControl(name="form.lastname").value = 'Merkel'
274        self.browser.getControl(name="form.no_copies").value = ['3']
275        self.browser.getControl(name="form.course_studied").value = ['CERT1']
276        self.browser.getControl(name="form.matric_number").value = '234'
277        self.browser.getControl(name="form.place_of_birth").value = 'Bochum'
278        self.browser.getControl(name="form.dispatch_address").value = 'Kuensche'
279        self.browser.getControl(name="form.perm_address").value = 'Kuensche'
280        self.browser.getControl(name="form.entry_mode").value = ['ug_ft']
281        self.browser.getControl(name="form.entry_session").value = ['2014']
282        self.browser.getControl(name="form.end_session").value = ['2015']
283        self.browser.getControl(name="form.phone.country").value = ['+234']
284        self.browser.getControl(name="form.phone.ext").value = '5678'
285        self.browser.getControl("Save").click()
286        self.browser.getControl("Add online payment ticket").click()
287        self.assertTrue('Payment ticket created' in self.browser.contents)
288        self.assertTrue('<span>100.0</span>' in self.browser.contents)
289        self.assertEqual(applicant.values()[0].amount_auth, 100.0)
290        return
291
292    def test_view_course_admitted(self):
293        self.applicant.course_admitted = self.certificate
294        self.login()
295        self.assertFalse('Admitted Course of Study' in self.browser.contents)
296        return
297
298    def test_upload_stateresult_by_manager(self):
299        # Add trans applicants container
300        self.transcontainer = ApplicantsContainer()
301        self.transcontainer.mode = 'create'
302        self.transcontainer.code = u'trans%s' % session_1
303        self.transcontainer.prefix = u'trans'
304        self.transcontainer.application_category = u'no'
305        self.transcontainer.year = session_1
306        self.transcontainer.application_fee = 300.0
307        self.transcontainer.title = u'This is the trans%s container' % session_1
308        self.app['applicants'][self.transcontainer.code] = self.transcontainer
309        delta = datetime.timedelta(days=10)
310        self.transcontainer.startdate = datetime.datetime.now(pytz.utc) - delta
311        self.transcontainer.enddate = datetime.datetime.now(pytz.utc) + delta
312        # Add applicant
313        transapplicant = createObject(u'waeup.Applicant')
314        transapplicant.firstname = u'Anna'
315        transapplicant.lastname = u'Post'
316        self.app['applicants'][self.transcontainer.code].addApplicant(transapplicant)
317        self.transapplicant = self.app['applicants'][self.transcontainer.code][
318            transapplicant.application_number]
319        self.transapplicant_view_path = ('http://localhost/app/applicants/trans%s/%s'
320            % (session_1, transapplicant.application_number))
321        self.transapplicant_manage_path = ('http://localhost/app/applicants/trans%s/%s/manage'
322            % (session_1, transapplicant.application_number))
323        # Login
324        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
325        self.browser.open(self.transapplicant_manage_path)
326        # Create a pseudo file with acceptable size
327        pdf_content = 'A' * 1024 * 300  # A string of 300 KB size
328        pseudo_pdf = StringIO(pdf_content)
329        ctrl = self.browser.getControl(name='form.stateresult')
330        file_ctrl = ctrl.mech_control
331        file_ctrl.add_file(pseudo_pdf, filename='myform.pdf')
332        self.browser.getControl("Save").click() # submit form
333        # Even though the form could not be saved ...
334        self.assertTrue('Required input is missing' in self.browser.contents)
335        # ... the file has been successfully uploaded
336        pdf_url = self.transapplicant_manage_path.replace('manage', 'stateresult.pdf')
337        self.browser.open(pdf_url)
338        self.assertEqual(
339            self.browser.headers['content-type'], 'application/pdf')
340        self.assertEqual(len(self.browser.contents), 307200)
341        # There is really a file stored for the applicant
342        storage = getUtility(IExtFileStore)
343        file_id = IFileStoreNameChooser(self.transapplicant).chooseName(
344            attr='stateresult.pdf')
345        # The stored file can be fetched
346        fd = storage.getFile(file_id)
347        file_len = len(fd.read())
348        self.assertEqual(file_len, 307200)
349        # A file link is displayed on the edit view ...
350        self.browser.open(self.transapplicant_manage_path)
351        self.assertTrue('<a href="stateresult.pdf">' in self.browser.contents)
352        # ... and on the dislay view
353        self.browser.open(self.transapplicant_view_path)
354        self.assertTrue('<a href="stateresult.pdf">Statement of Result</a>'
355            in self.browser.contents)
356        # Adding file is properly logged
357        logfile = os.path.join(
358            self.app['datacenter'].storage, 'logs', 'applicants.log')
359        logcontent = open(logfile).read()
360        self.assertTrue(
361            'zope.mgr - waeup.aaue.applicants.browser.CustomApplicantManageFormPage'
362            ' - %s - saved: stateresult'
363            % (self.transapplicant.applicant_id)
364            in logcontent)
365        # When an applicant is removed, also the pdf files are gone.
366        del self.app['applicants'][self.transcontainer.code][self.transapplicant.application_number]
367        fd = storage.getFile(file_id)
368        self.assertTrue(fd is None)
Note: See TracBrowser for help on using the repository browser.