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

Last change on this file since 13802 was 13615, checked in by Henrik Bettermann, 9 years ago

Add NILS application type and category and customize slip.

  • Property svn:keywords set to Id
File size: 11.3 KB
Line 
1## $Id: test_browser.py 13615 2016-01-14 14:41:20Z henrik $
2##
3## Copyright (C) 2013 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"""
19Test the applicant-related UI components.
20"""
21import os
22from StringIO import StringIO
23from datetime import datetime
24from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
25from zope.securitypolicy.interfaces import IPrincipalRoleManager
26from waeup.kofa.browser.tests.test_pdf import samples_dir
27from waeup.kofa.applicants.container import ApplicantsContainer
28from waeup.uniben.testing import FunctionalLayer
29from waeup.uniben.configuration import CustomSessionConfiguration
30from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup, PH_LEN
31
32class CustomApplicantUITests(ApplicantsFullSetup):
33    # Tests for uploading/browsing the passport image of appplicants
34
35    layer = FunctionalLayer
36
37    #def setUp(self):
38    #    super(CustomApplicantUITests, self).setUp()
39    #    return
40
41    def test_applicant_access(self):
42        # Anonymous users can't see the application fee.
43        self.browser.open(self.container_path)
44        self.assertFalse('Application Fee' in self.browser.contents)
45        # Applicants can edit their record
46        self.browser.open(self.login_path)
47        self.login()
48        self.assertTrue(
49            'You logged in.' in self.browser.contents)
50        self.browser.open(self.edit_path)
51        self.assertTrue(self.browser.url != self.login_path)
52        self.assertEqual(self.browser.headers['Status'], '200 Ok')
53        self.fill_correct_values()
54        self.browser.getControl("Save").click()
55        self.assertMatches('...Form has been saved...', self.browser.contents)
56        # Applicants can't see the application fee.
57        self.browser.open(self.container_path)
58        self.assertFalse('Application Fee' in self.browser.contents)
59        return
60       
61    def image_url(self, filename):
62        return self.edit_path.replace('edit', filename)
63
64    def test_upload_passport_wo_permission(self):
65        # Create CRPU officer
66        self.app['users'].addUser('mrcrpu', 'mrcrpusecret')
67        self.app['users']['mrcrpu'].email = 'mrcrpu@foo.ng'
68        self.app['users']['mrcrpu'].title = 'Carlo Pitter'
69        prmglobal = IPrincipalRoleManager(self.app)
70        prmglobal.assignRoleToPrincipal('waeup.CCOfficer', 'mrcrpu')
71        # Login as CRPU officer
72        self.browser.open(self.login_path)
73        self.browser.getControl(name="form.login").value = 'mrcrpu'
74        self.browser.getControl(name="form.password").value = 'mrcrpusecret'
75        self.browser.getControl("Login").click()
76        self.assertMatches('...You logged in...', self.browser.contents)
77        # Let's try to change the passport image
78        self.browser.open(self.manage_path)
79        self.fill_correct_values()
80        # Create a pseudo image file and select it to be uploaded in form
81        pseudo_image = StringIO('I pretend to be a graphics file')
82        ctrl = self.browser.getControl(name='form.passport')
83        file_ctrl = ctrl.mech_control
84        file_ctrl.add_file(pseudo_image, filename='myphoto.jpg')
85        self.browser.getControl("Save").click()
86        self.assertMatches('...You are not entitled to upload passport pictures...',
87            self.browser.contents)
88        # The officer still sees the placeholder passport image
89        self.browser.open(self.image_url('passport.jpg'))
90        self.assertEqual(
91            self.browser.headers['content-type'], 'image/jpeg')
92        self.assertEqual(len(self.browser.contents), PH_LEN)
93        # After adding the additional role ...
94        prmglobal.assignRoleToPrincipal('waeup.PassportPictureManager', 'mrcrpu')
95        # ... passport pictures can be uploaded
96        self.browser.open(self.manage_path)
97        self.fill_correct_values()
98        pseudo_image = StringIO('I pretend to be a graphics file')
99        ctrl = self.browser.getControl(name='form.passport')
100        file_ctrl = ctrl.mech_control
101        file_ctrl.add_file(pseudo_image, filename='myphoto.jpg')
102        self.browser.getControl("Save").click()
103        self.assertMatches('...Form has been saved...', self.browser.contents)
104        # There is a correct <img> link included
105        self.assertTrue(
106            '<img src="passport.jpg" height="180px" />' in self.browser.contents)
107        # Browsing the link shows a real image
108        self.browser.open(self.image_url('passport.jpg'))
109        self.assertEqual(
110            self.browser.headers['content-type'], 'image/jpeg')
111        self.assertEqual(len(self.browser.contents), 31)
112
113    def test_pay_admission_checking_fee(self):
114        IWorkflowState(self.applicant).setState('admitted')
115        self.applicant.screening_score = 55
116        self.applicant.course_admitted = self.certificate
117        self.login()
118        # SessionConfiguration is not set, thus admission checking payment
119        # is not necessary. Screening results and course admitted are visible.
120        self.assertFalse(
121            'Add admission checking payment ticket' in self.browser.contents)
122        self.assertTrue('<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">CERT1 - Unnamed Certificate</a>' in self.browser.contents)
123        self.assertTrue('<span>55</span>' in self.browser.contents)
124        configuration = CustomSessionConfiguration()
125        configuration.academic_session = datetime.now().year - 2
126        self.app['configuration'].addSessionConfiguration(configuration)
127        # Admission checking fee is 0, thus admission checking payment
128        # is not necessary. Screening results and course admitted are visible.
129        self.browser.open(self.view_path)
130        self.assertFalse(
131            'Add admission checking payment ticket' in self.browser.contents)
132        self.assertTrue('<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">CERT1 - Unnamed Certificate</a>' in self.browser.contents)
133        self.assertTrue('<span>55</span>' in self.browser.contents)
134        configuration.admchecking_fee = 22.0
135        # Admission checking payment button is now visible, but screening results
136        # and course admitted are not.
137        self.browser.open(self.view_path)
138        self.assertTrue(
139            'Add admission checking payment ticket' in self.browser.contents)
140        self.assertFalse('<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">CERT1 - Unnamed Certificate</a>' in self.browser.contents)
141        self.assertFalse('<span>55</span>' in self.browser.contents)
142        # Application slip can't be downloaded
143        self.assertFalse('Download application slip' in self.browser.contents)
144        slip_path = self.view_path + '/application_slip.pdf'
145        self.browser.open(slip_path)
146        self.assertTrue(
147            'Please pay admission checking fee before trying to download'
148            in self.browser.contents)
149        # Pay admission checking fee.
150        self.browser.getControl("Add admission checking").click()
151        p_id = self.applicant.keys()[0]
152        self.applicant[p_id].p_state = 'paid'
153        # Screening results and course admitted are visible after payment.
154        self.browser.open(self.view_path)
155        self.assertFalse(
156            'Add admission checking payment ticket' in self.browser.contents)
157        self.assertTrue('<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">CERT1 - Unnamed Certificate</a>' in self.browser.contents)
158        self.assertTrue('<span>55</span>' in self.browser.contents)
159        # Application slip can be downloaded again.
160        self.browser.getLink("Download application slip").click()
161        self.assertEqual(self.browser.headers['Status'], '200 Ok')
162        self.assertEqual(self.browser.headers['Content-Type'],
163                         'application/pdf')
164        return
165
166    def test_application_slip(self):
167
168        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
169        self.slip_path = self.view_path + '/application_slip.pdf'
170        self.browser.open(self.manage_path)
171        self.assertEqual(self.browser.headers['Status'], '200 Ok')
172        self.fill_correct_values()
173        self.browser.getControl("Save").click()
174        IWorkflowState(self.applicant).setState('submitted')
175        self.browser.open(self.manage_path)
176        self.browser.getLink("Download application slip").click()
177        self.assertEqual(self.browser.headers['Status'], '200 Ok')
178        self.assertEqual(self.browser.headers['Content-Type'],
179                         'application/pdf')
180        path = os.path.join(samples_dir(), 'application_slip.pdf')
181        open(path, 'wb').write(self.browser.contents)
182        print "Sample application_slip.pdf written to %s" % path
183
184    def test_akoka_application_slip(self):
185
186        # Remove required FieldProperty attribute first ...
187        delattr(ApplicantsContainer, 'prefix')
188        # ... and replace by akoka
189        self.applicantscontainer.prefix = 'afak'
190        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
191        self.slip_path = self.view_path + '/application_slip.pdf'
192        self.browser.open(self.manage_path)
193        self.assertEqual(self.browser.headers['Status'], '200 Ok')
194        self.fill_correct_values()
195        self.browser.getControl("Save").click()
196        IWorkflowState(self.applicant).setState('submitted')
197        self.browser.open(self.manage_path)
198        self.browser.getLink("Download application slip").click()
199        self.assertEqual(self.browser.headers['Status'], '200 Ok')
200        self.assertEqual(self.browser.headers['Content-Type'],
201                         'application/pdf')
202        path = os.path.join(samples_dir(), 'akoka_application_slip.pdf')
203        open(path, 'wb').write(self.browser.contents)
204        print "Sample akoka_application_slip.pdf written to %s" % path
205
206    def test_nils_application_slip(self):
207
208        # Remove required FieldProperty attribute first ...
209        #delattr(ApplicantsContainer, 'prefix')
210        # ... and replace by akoka
211        self.applicantscontainer.prefix = 'pgn'
212        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
213        self.slip_path = self.view_path + '/application_slip.pdf'
214        self.browser.open(self.manage_path)
215        self.assertEqual(self.browser.headers['Status'], '200 Ok')
216        self.fill_correct_values()
217        self.browser.getControl("Save").click()
218        IWorkflowState(self.applicant).setState('submitted')
219        self.browser.open(self.manage_path)
220        self.browser.getLink("Download application slip").click()
221        self.assertEqual(self.browser.headers['Status'], '200 Ok')
222        self.assertEqual(self.browser.headers['Content-Type'],
223                         'application/pdf')
224        path = os.path.join(samples_dir(), 'nils_application_slip.pdf')
225        open(path, 'wb').write(self.browser.contents)
226        print "Sample nils_application_slip.pdf written to %s" % path
Note: See TracBrowser for help on using the repository browser.