source: main/waeup.uniben/trunk/src/waeup/uniben/applicants/tests/test_browser.py @ 17654

Last change on this file since 17654 was 17593, checked in by Henrik Bettermann, 14 months ago

Make more fields required.

  • Property svn:keywords set to Id
File size: 19.6 KB
Line 
1# -*- coding: utf-8 -*-
2## $Id: test_browser.py 17593 2023-09-21 20:40:35Z 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"""
20Test the applicant-related UI components.
21"""
22import os
23import datetime
24import pytz
25from StringIO import StringIO
26from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
27from zope.securitypolicy.interfaces import IPrincipalRoleManager
28from zope.component import createObject, getUtility
29from waeup.kofa.interfaces import IUserAccount
30from waeup.kofa.browser.tests.test_pdf import samples_dir
31from waeup.kofa.applicants.container import ApplicantsContainer
32from waeup.uniben.testing import FunctionalLayer
33from waeup.uniben.configuration import CustomSessionConfiguration
34from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup, PH_LEN
35
36session_1 = datetime.datetime.now().year - 2
37SAMPLE_IMAGE = os.path.join(os.path.dirname(__file__), 'test_image.jpg')
38
39class 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 as an applicant.' 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.0
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.0</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.0</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.0</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.0</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        applicant.collected = True
320        self.app['applicants']['tsc1234'].addApplicant(applicant)
321        IUserAccount(
322            self.app['applicants']['tsc1234'][
323            applicant.application_number]).setPassword('apwd')
324        # Login
325        self.browser.open(self.login_path)
326        self.browser.getControl(
327            name="form.login").value = applicant.applicant_id
328        self.browser.getControl(name="form.password").value = 'apwd'
329        self.browser.getControl("Login").click()
330        self.browser.getLink("Application record").click()
331        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
332        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
333        self.browser.getControl(name="form.firstname").value = 'Angela'
334        self.browser.getControl(name="form.lastname").value = 'Merkel'
335        self.browser.getControl(name="form.sex").value = ['f']
336        self.browser.getControl(name="form.no_copies").value = ['2']
337        self.browser.getControl(name="form.course_studied").value = ['CERT1']
338        self.browser.getControl(name="form.matric_number").value = '234'
339        self.browser.getControl(name="form.dispatch_address").value = 'Kuensche\nMarsch 5'
340        self.browser.getControl(name="form.entry_mode").value = ['ug_ft']
341        self.browser.getControl(name="form.entry_session").value = ['2014']
342        self.browser.getControl(name="form.end_session").value = ['2015']
343        self.browser.getControl(name="form.phone.country").value = ['+234']
344        self.browser.getControl(name="form.phone.ext").value = '5678'
345        self.browser.getControl(name="form.charge").value = ['nigeria']
346        self.browser.getControl(name="form.order").value = ['o']
347        image = open(SAMPLE_IMAGE, 'rb')
348        ctrl = self.browser.getControl(name='form.passport')
349        file_ctrl = ctrl.mech_control
350        file_ctrl.add_file(image, filename='myphoto.jpg')
351        self.browser.getControl("Save").click()
352        applicant_url = self.browser.url
353        self.browser.getControl("Create and make online").click()
354        self.assertTrue('Payment ticket created' in self.browser.contents)
355        self.assertTrue('<span>40000.0</span>' in self.browser.contents)
356        self.assertEqual(applicant.values()[0].amount_auth, 40000.0)
357        applicant.values()[0].p_state = 'paid'
358        payment_url = self.browser.url
359        IWorkflowState(applicant).setState('submitted')
360        self.browser.open(payment_url)
361        self.browser.getLink("Download payment slip").click()
362        self.assertEqual(self.browser.headers['Status'], '200 Ok')
363        self.assertEqual(self.browser.headers['Content-Type'],
364                         'application/pdf')
365        path = os.path.join(samples_dir(), 'tscf_payment_slip.pdf')
366        open(path, 'wb').write(self.browser.contents)
367        print "Sample tscf_payment_slip.pdf written to %s" % path
368        self.browser.open(applicant_url)
369        self.browser.getLink("My Data").click()
370        self.browser.getLink("Download application slip").click()
371        self.assertEqual(self.browser.headers['Status'], '200 Ok')
372        self.assertEqual(self.browser.headers['Content-Type'],
373                         'application/pdf')
374        path = os.path.join(samples_dir(), 'tscf_application_slip.pdf')
375        open(path, 'wb').write(self.browser.contents)
376        print "Sample tscf_application_slip.pdf written to %s" % path
377        return
Note: See TracBrowser for help on using the repository browser.