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

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

Implement transcript applications.

  • Property svn:keywords set to Id
File size: 18.4 KB
Line 
1# -*- coding: utf-8 -*-
2## $Id: test_browser.py 16078 2020-05-02 20:07:43Z 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.configuration import SessionConfiguration
30from waeup.kofa.interfaces import IUserAccount
31from waeup.kofa.browser.tests.test_pdf import samples_dir
32from waeup.kofa.applicants.container import ApplicantsContainer
33from waeup.uniben.testing import FunctionalLayer
34from waeup.uniben.configuration import CustomSessionConfiguration
35from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup, PH_LEN
36
37session_1 = datetime.datetime.now().year - 2
38SAMPLE_IMAGE = os.path.join(os.path.dirname(__file__), 'test_image.jpg')
39
40class CustomApplicantUITests(ApplicantsFullSetup):
41    # Tests for uploading/browsing the passport image of appplicants
42
43    layer = FunctionalLayer
44
45    #def setUp(self):
46    #    super(CustomApplicantUITests, self).setUp()
47    #    return
48
49    def test_applicant_access(self):
50        # Anonymous users can't see the application fee.
51        self.browser.open(self.container_path)
52        self.assertFalse('Application Fee' in self.browser.contents)
53        # Applicants can edit their record
54        self.browser.open(self.login_path)
55        self.login()
56        self.assertTrue(
57            'You logged in.' in self.browser.contents)
58        self.browser.open(self.edit_path)
59        self.assertTrue(self.browser.url != self.login_path)
60        self.assertEqual(self.browser.headers['Status'], '200 Ok')
61        self.fill_correct_values()
62        self.browser.getControl("Save").click()
63        self.assertMatches('...Form has been saved...', self.browser.contents)
64        # Applicants can't see the application fee.
65        self.browser.open(self.container_path)
66        self.assertFalse('Application Fee' in self.browser.contents)
67        return
68       
69    def image_url(self, filename):
70        return self.edit_path.replace('edit', filename)
71
72    def test_upload_passport_wo_permission(self):
73        # Create CRPU officer
74        self.app['users'].addUser('mrcrpu', 'mrCrpusecret1')
75        self.app['users']['mrcrpu'].email = 'mrcrpu@foo.ng'
76        self.app['users']['mrcrpu'].title = 'Carlo Pitter'
77        prmglobal = IPrincipalRoleManager(self.app)
78        prmglobal.assignRoleToPrincipal('waeup.CCOfficer', 'mrcrpu')
79        # Login as CRPU officer
80        self.browser.open(self.login_path)
81        self.browser.getControl(name="form.login").value = 'mrcrpu'
82        self.browser.getControl(name="form.password").value = 'mrCrpusecret1'
83        self.browser.getControl("Login").click()
84        self.assertMatches('...You logged in...', self.browser.contents)
85        # Let's try to change the passport image
86        self.browser.open(self.manage_path)
87        self.fill_correct_values()
88        # Create a pseudo image file and select it to be uploaded in form
89        pseudo_image = StringIO('I pretend to be a graphics file')
90        ctrl = self.browser.getControl(name='form.passport')
91        file_ctrl = ctrl.mech_control
92        file_ctrl.add_file(pseudo_image, filename='myphoto.jpg')
93        self.browser.getControl("Save").click()
94        self.assertMatches('...You are not entitled to upload passport pictures...',
95            self.browser.contents)
96        # The officer still sees the placeholder passport image
97        self.browser.open(self.image_url('passport.jpg'))
98        self.assertEqual(
99            self.browser.headers['content-type'], 'image/jpeg')
100        self.assertEqual(len(self.browser.contents), PH_LEN)
101        # After adding the additional role ...
102        prmglobal.assignRoleToPrincipal('waeup.PassportPictureManager', 'mrcrpu')
103        # ... passport pictures can be uploaded
104        self.browser.open(self.manage_path)
105        self.fill_correct_values()
106        pseudo_image = StringIO('I pretend to be a graphics file')
107        ctrl = self.browser.getControl(name='form.passport')
108        file_ctrl = ctrl.mech_control
109        file_ctrl.add_file(pseudo_image, filename='myphoto.jpg')
110        self.browser.getControl("Save").click()
111        self.assertMatches('...Form has been saved...', self.browser.contents)
112        # There is a correct <img> link included
113        self.assertTrue(
114            '<img src="passport.jpg" height="180px" />' in self.browser.contents)
115        # Browsing the link shows a real image
116        self.browser.open(self.image_url('passport.jpg'))
117        self.assertEqual(
118            self.browser.headers['content-type'], 'image/jpeg')
119        self.assertEqual(len(self.browser.contents), 31)
120
121    def test_pay_admission_checking_fee(self):
122        IWorkflowState(self.applicant).setState('admitted')
123        self.applicant.screening_score = 55
124        self.applicant.course_admitted = self.certificate
125        self.login()
126        # SessionConfiguration is not set, thus admission checking payment
127        # is not necessary. Screening results and course admitted are visible.
128        self.assertFalse(
129            'Add admission checking payment ticket' in self.browser.contents)
130        self.assertTrue('<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">CERT1 - Unnamed Certificate</a>' in self.browser.contents)
131        self.assertTrue('<span>55</span>' in self.browser.contents)
132        configuration = CustomSessionConfiguration()
133        configuration.academic_session = datetime.datetime.now().year - 2
134        self.app['configuration'].addSessionConfiguration(configuration)
135        # Admission checking fee is 0, thus admission checking payment
136        # is not necessary. Screening results and course admitted are visible.
137        self.browser.open(self.view_path)
138        self.assertFalse(
139            'Add admission checking payment ticket' in self.browser.contents)
140        self.assertTrue('<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">CERT1 - Unnamed Certificate</a>' in self.browser.contents)
141        self.assertTrue('<span>55</span>' in self.browser.contents)
142        configuration.admchecking_fee = 22.0
143        # Admission checking payment button is now visible, but screening results
144        # and course admitted are not.
145        self.browser.open(self.view_path)
146        self.assertTrue(
147            'Add admission checking payment ticket' in self.browser.contents)
148        self.assertFalse('<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">CERT1 - Unnamed Certificate</a>' in self.browser.contents)
149        self.assertFalse('<span>55</span>' in self.browser.contents)
150        # Application slip can't be downloaded
151        self.assertFalse('Download application slip' in self.browser.contents)
152        slip_path = self.view_path + '/application_slip.pdf'
153        self.browser.open(slip_path)
154        self.assertTrue(
155            'Please pay admission checking fee before trying to download'
156            in self.browser.contents)
157        # Pay admission checking fee.
158        self.browser.getControl("Add admission checking").click()
159        p_id = self.applicant.keys()[0]
160        self.applicant[p_id].p_state = 'paid'
161        # Screening results and course admitted are visible after payment.
162        self.browser.open(self.view_path)
163        self.assertFalse(
164            'Add admission checking payment ticket' in self.browser.contents)
165        self.assertTrue('<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">CERT1 - Unnamed Certificate</a>' in self.browser.contents)
166        self.assertTrue('<span>55</span>' in self.browser.contents)
167        # Application slip can be downloaded again.
168        self.browser.getLink("Download application slip").click()
169        self.assertEqual(self.browser.headers['Status'], '200 Ok')
170        self.assertEqual(self.browser.headers['Content-Type'],
171                         'application/pdf')
172        return
173
174    def test_application_slips(self):
175
176        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
177        self.slip_path = self.view_path + '/application_slip.pdf'
178        self.browser.open(self.manage_path)
179        self.assertEqual(self.browser.headers['Status'], '200 Ok')
180        self.fill_correct_values()
181        self.browser.getControl("Save").click()
182        IWorkflowState(self.applicant).setState('submitted')
183        self.browser.open(self.manage_path)
184        self.browser.getLink("Download application slip").click()
185        self.assertEqual(self.browser.headers['Status'], '200 Ok')
186        self.assertEqual(self.browser.headers['Content-Type'],
187                         'application/pdf')
188        path = os.path.join(samples_dir(), 'application_slip.pdf')
189        open(path, 'wb').write(self.browser.contents)
190        print "Sample application_slip.pdf written to %s" % path
191        # Screening invitation letter is not yet available
192        self.browser.open(self.view_path)
193        self.assertFalse('invitation slip' in self.browser.contents)
194        self.browser.open(self.view_path + '/screening_invitation_slip.pdf')
195        self.assertTrue('Forbidden' in self.browser.contents)
196        self.applicant.screening_date = u'any date'
197        self.applicant.screening_venue = u'MAIN AUDITORIUM'
198        self.applicantscontainer.application_slip_notice = u'This is an additional notice.'
199        # The invitation letter can be printed
200        self.browser.open(self.view_path)
201        self.browser.getLink("invitation").click()
202        self.assertEqual(self.browser.headers['Status'], '200 Ok')
203        self.assertEqual(self.browser.headers['Content-Type'],
204                         'application/pdf')
205        path = os.path.join(samples_dir(), 'screening_invitation_slip.pdf')
206        open(path, 'wb').write(self.browser.contents)
207        print "Sample screening_invitation_slip.pdf written to %s" % path
208
209    def test_akoka_application_slip(self):
210
211        # Remove required FieldProperty attribute first ...
212        delattr(ApplicantsContainer, 'prefix')
213        # ... and replace by akoka
214        self.applicantscontainer.prefix = 'akj'
215        self.applicantscontainer.title = u'FCET Akoka JUPEB Pre-Degree (Foundation) Studies 2016/2017'
216        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
217        self.slip_path = self.view_path + '/application_slip.pdf'
218        self.browser.open(self.manage_path)
219        self.assertEqual(self.browser.headers['Status'], '200 Ok')
220        self.fill_correct_values()
221        self.browser.getControl("Save").click()
222        IWorkflowState(self.applicant).setState('submitted')
223        self.browser.open(self.manage_path)
224        self.browser.getLink("Download application slip").click()
225        self.assertEqual(self.browser.headers['Status'], '200 Ok')
226        self.assertEqual(self.browser.headers['Content-Type'],
227                         'application/pdf')
228        path = os.path.join(samples_dir(), 'akoka_application_slip.pdf')
229        open(path, 'wb').write(self.browser.contents)
230        print "Sample akoka_application_slip.pdf written to %s" % path
231
232    def test_nils_application_slip(self):
233
234        # Remove required FieldProperty attribute first ...
235        #delattr(ApplicantsContainer, 'prefix')
236        # ... and replace by akoka
237        self.applicantscontainer.prefix = 'pgn'
238        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
239        self.slip_path = self.view_path + '/application_slip.pdf'
240        self.browser.open(self.manage_path)
241        self.assertEqual(self.browser.headers['Status'], '200 Ok')
242        self.fill_correct_values()
243        self.browser.getControl("Save").click()
244        IWorkflowState(self.applicant).setState('submitted')
245        self.browser.open(self.manage_path)
246        self.browser.getLink("Download application slip").click()
247        self.assertEqual(self.browser.headers['Status'], '200 Ok')
248        self.assertEqual(self.browser.headers['Content-Type'],
249                         'application/pdf')
250        path = os.path.join(samples_dir(), 'nils_application_slip.pdf')
251        open(path, 'wb').write(self.browser.contents)
252        print "Sample nils_application_slip.pdf written to %s" % path
253
254    def test_ictwk_application(self):
255
256        # Remove required FieldProperty attribute first ...
257        #delattr(ApplicantsContainer, 'prefix')
258        # ... and replace by ictw
259        self.applicantscontainer.prefix = 'ictwk'
260        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
261        self.slip_path = self.view_path + '/application_slip.pdf'
262        self.browser.open(self.manage_path)
263        self.assertEqual(self.browser.headers['Status'], '200 Ok')
264        self.browser.getControl(name="form.firstname").value = 'John'
265        self.browser.getControl(name="form.middlename").value = 'Anthony'
266        self.browser.getControl(name="form.lastname").value = 'Tester'
267        #self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
268        self.browser.getControl(name="form.sex").value = ['m']
269        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
270        image = open(SAMPLE_IMAGE, 'rb')
271        ctrl = self.browser.getControl(name='form.passport')
272        file_ctrl = ctrl.mech_control
273        file_ctrl.add_file(image, filename='myphoto.jpg')
274        self.browser.getControl("Save").click()
275        self.applicant.registration_cats = ['group', 'corporate']
276        IWorkflowState(self.applicant).setState('started')
277        configuration = CustomSessionConfiguration()
278        configuration.academic_session = session_1
279        configuration.application_fee = 0.0
280        self.app['configuration'].addSessionConfiguration(configuration)
281        self.browser.getControl("Add online payment ticket").click()
282        self.assertMatches('...Payment ticket created...',
283                           self.browser.contents)
284        self.assertEqual(self.applicant.values()[0].amount_auth, 450000)
285        IWorkflowState(self.applicant).setState('submitted')
286        self.browser.open(self.view_path)
287        self.assertTrue('Group Registration @ ₦ 200000' in self.browser.contents)
288        self.browser.open(self.manage_path)
289        self.browser.getLink("Download application slip").click()
290        self.assertEqual(self.browser.headers['Status'], '200 Ok')
291        self.assertEqual(self.browser.headers['Content-Type'],
292                         'application/pdf')
293        path = os.path.join(samples_dir(), 'ictwk_application_slip.pdf')
294        open(path, 'wb').write(self.browser.contents)
295        print "Sample ictwk_application_slip.pdf written to %s" % path
296
297    def test_transcript_payment(self):
298        configuration = SessionConfiguration()
299        configuration.academic_session = session_1
300        self.app['configuration'].addSessionConfiguration(configuration)
301        # Add special application container
302        applicantscontainer = ApplicantsContainer()
303        applicantscontainer.year = session_1
304        applicantscontainer.application_fee = 200.0
305        applicantscontainer.code = u'trans1234'
306        applicantscontainer.prefix = 'trans'
307        applicantscontainer.title = u'This is a trans container'
308        applicantscontainer.application_category = 'no'
309        applicantscontainer.mode = 'create'
310        applicantscontainer.strict_deadline = True
311        applicantscontainer.with_picture = False
312        delta = datetime.timedelta(days=10)
313        applicantscontainer.startdate = datetime.datetime.now(pytz.utc) - delta
314        applicantscontainer.enddate = datetime.datetime.now(pytz.utc) + delta
315        self.app['applicants']['trans1234'] = applicantscontainer
316        # Add an applicant
317        applicant = createObject('waeup.Applicant')
318        # reg_number is the only field which has to be preset here
319        # because managers are allowed to edit this required field
320        applicant.reg_number = u'12345'
321        self.app['applicants']['trans1234'].addApplicant(applicant)
322        IUserAccount(
323            self.app['applicants']['trans1234'][
324            applicant.application_number]).setPassword('apwd')
325        # Login
326        self.browser.open(self.login_path)
327        self.browser.getControl(
328            name="form.login").value = applicant.applicant_id
329        self.browser.getControl(name="form.password").value = 'apwd'
330        self.browser.getControl("Login").click()
331        self.browser.getLink("Application record").click()
332        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
333        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
334        self.browser.getControl(name="form.nationality").value = ['NG']
335        self.browser.getControl(name="form.firstname").value = 'Angela'
336        self.browser.getControl(name="form.lastname").value = 'Merkel'
337        self.browser.getControl(name="form.sex").value = ['f']
338        self.browser.getControl(name="form.no_copies").value = ['3']
339        self.browser.getControl(name="form.course_studied").value = ['CERT1']
340        self.browser.getControl(name="form.matric_number").value = '234'
341        self.browser.getControl(name="form.place_of_birth").value = 'Bochum'
342        self.browser.getControl(name="form.dispatch_address").value = 'Kuensche'
343        self.browser.getControl(name="form.perm_address").value = 'Kuensche'
344        self.browser.getControl(name="form.entry_mode").value = ['ug_ft']
345        self.browser.getControl(name="form.entry_session").value = ['2014']
346        self.browser.getControl(name="form.end_session").value = ['2015']
347        self.browser.getControl(name="form.phone.country").value = ['+234']
348        self.browser.getControl(name="form.phone.ext").value = '5678'
349        self.browser.getControl("Save").click()
350        self.browser.getControl("Add online payment ticket").click()
351        self.assertTrue('Payment ticket created' in self.browser.contents)
352        self.assertTrue('<span>200.0</span>' in self.browser.contents)
353        self.assertEqual(applicant.values()[0].amount_auth, 200.0)
354        return
Note: See TracBrowser for help on using the repository browser.