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

Last change on this file since 13095 was 13081, checked in by Henrik Bettermann, 10 years ago

'55' may appear in ids.

  • Property svn:keywords set to Id
File size: 8.2 KB
Line 
1## $Id: test_browser.py 13081 2015-06-20 08:01:19Z 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"""
21from StringIO import StringIO
22from datetime import datetime
23from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
24from zope.securitypolicy.interfaces import IPrincipalRoleManager
25from waeup.uniben.testing import FunctionalLayer
26from waeup.uniben.configuration import CustomSessionConfiguration
27from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup, PH_LEN
28
29class CustomApplicantUITests(ApplicantsFullSetup):
30    # Tests for uploading/browsing the passport image of appplicants
31
32    layer = FunctionalLayer
33
34    #def setUp(self):
35    #    super(CustomApplicantUITests, self).setUp()
36    #    return
37
38    def test_applicant_access(self):
39        # Anonymous users can't see the application fee.
40        self.browser.open(self.container_path)
41        self.assertFalse('Application Fee' in self.browser.contents)
42        # Applicants can edit their record
43        self.browser.open(self.login_path)
44        self.login()
45        self.assertTrue(
46            'You logged in.' in self.browser.contents)
47        self.browser.open(self.edit_path)
48        self.assertTrue(self.browser.url != self.login_path)
49        self.assertEqual(self.browser.headers['Status'], '200 Ok')
50        self.fill_correct_values()
51        self.browser.getControl("Save").click()
52        self.assertMatches('...Form has been saved...', self.browser.contents)
53        # Applicants can't see the application fee.
54        self.browser.open(self.container_path)
55        self.assertFalse('Application Fee' in self.browser.contents)
56        return
57       
58    def image_url(self, filename):
59        return self.edit_path.replace('edit', filename)
60
61    def test_upload_passport_wo_permission(self):
62        # Create CRPU officer
63        self.app['users'].addUser('mrcrpu', 'mrcrpusecret')
64        self.app['users']['mrcrpu'].email = 'mrcrpu@foo.ng'
65        self.app['users']['mrcrpu'].title = 'Carlo Pitter'
66        prmglobal = IPrincipalRoleManager(self.app)
67        prmglobal.assignRoleToPrincipal('waeup.CCOfficer', 'mrcrpu')
68        # Login as CRPU officer
69        self.browser.open(self.login_path)
70        self.browser.getControl(name="form.login").value = 'mrcrpu'
71        self.browser.getControl(name="form.password").value = 'mrcrpusecret'
72        self.browser.getControl("Login").click()
73        self.assertMatches('...You logged in...', self.browser.contents)
74        # Let's try to change the passport image
75        self.browser.open(self.manage_path)
76        self.fill_correct_values()
77        # Create a pseudo image file and select it to be uploaded in form
78        pseudo_image = StringIO('I pretend to be a graphics file')
79        ctrl = self.browser.getControl(name='form.passport')
80        file_ctrl = ctrl.mech_control
81        file_ctrl.add_file(pseudo_image, filename='myphoto.jpg')
82        self.browser.getControl("Save").click()
83        self.assertMatches('...You are not entitled to upload passport pictures...',
84            self.browser.contents)
85        # The officer still sees the placeholder passport image
86        self.browser.open(self.image_url('passport.jpg'))
87        self.assertEqual(
88            self.browser.headers['content-type'], 'image/jpeg')
89        self.assertEqual(len(self.browser.contents), PH_LEN)
90        # After adding the additional role ...
91        prmglobal.assignRoleToPrincipal('waeup.PassportPictureManager', 'mrcrpu')
92        # ... passport pictures can be uploaded
93        self.browser.open(self.manage_path)
94        self.fill_correct_values()
95        pseudo_image = StringIO('I pretend to be a graphics file')
96        ctrl = self.browser.getControl(name='form.passport')
97        file_ctrl = ctrl.mech_control
98        file_ctrl.add_file(pseudo_image, filename='myphoto.jpg')
99        self.browser.getControl("Save").click()
100        self.assertMatches('...Form has been saved...', self.browser.contents)
101        # There is a correct <img> link included
102        self.assertTrue(
103            '<img src="passport.jpg" height="180px" />' in self.browser.contents)
104        # Browsing the link shows a real image
105        self.browser.open(self.image_url('passport.jpg'))
106        self.assertEqual(
107            self.browser.headers['content-type'], 'image/jpeg')
108        self.assertEqual(len(self.browser.contents), 31)
109
110    def test_pay_admission_checking_fee(self):
111        IWorkflowState(self.applicant).setState('admitted')
112        self.applicant.screening_score = 55
113        self.applicant.course_admitted = self.certificate
114        self.login()
115        # SessionConfiguration is not set, thus admission checking payment
116        # is not necessary. Screening results and course admitted are visible.
117        self.assertFalse(
118            'Add admission checking payment ticket' in self.browser.contents)
119        self.assertTrue('<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">CERT1 - Unnamed Certificate</a>' in self.browser.contents)
120        self.assertTrue('<span>55</span>' in self.browser.contents)
121        configuration = CustomSessionConfiguration()
122        configuration.academic_session = datetime.now().year - 2
123        self.app['configuration'].addSessionConfiguration(configuration)
124        # Admission checking fee is 0, thus admission checking payment
125        # is not necessary. Screening results and course admitted are visible.
126        self.browser.open(self.view_path)
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</span>' in self.browser.contents)
131        configuration.admchecking_fee = 22.0
132        # Admission checking payment button is now visible, but screening results
133        # and course admitted are not.
134        self.browser.open(self.view_path)
135        self.assertTrue(
136            'Add admission checking payment ticket' in self.browser.contents)
137        self.assertFalse('<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">CERT1 - Unnamed Certificate</a>' in self.browser.contents)
138        self.assertFalse('<span>55</span>' in self.browser.contents)
139        # Application slip can't be downloaded
140        self.assertFalse('Download application slip' in self.browser.contents)
141        slip_path = self.view_path + '/application_slip.pdf'
142        self.browser.open(slip_path)
143        self.assertTrue(
144            'Please pay admission checking fee before trying to download'
145            in self.browser.contents)
146        # Pay admission checking fee.
147        self.browser.getControl("Add admission checking").click()
148        p_id = self.applicant.keys()[0]
149        self.applicant[p_id].p_state = 'paid'
150        # Screening results and course admitted are visible after payment.
151        self.browser.open(self.view_path)
152        self.assertFalse(
153            'Add admission checking payment ticket' in self.browser.contents)
154        self.assertTrue('<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">CERT1 - Unnamed Certificate</a>' in self.browser.contents)
155        self.assertTrue('<span>55</span>' in self.browser.contents)
156        # Application slip can be downloaded again.
157        self.browser.getLink("Download application slip").click()
158        self.assertEqual(self.browser.headers['Status'], '200 Ok')
159        self.assertEqual(self.browser.headers['Content-Type'],
160                         'application/pdf')
161        return
Note: See TracBrowser for help on using the repository browser.