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

Last change on this file since 11770 was 11736, checked in by Henrik Bettermann, 11 years ago

Add permission waeup.uploadPassportPictures and role waeup.PassportPictureManager? and allow only officers with this role to upload passport pictures of applicants.

  • Property svn:keywords set to Id
File size: 4.7 KB
Line 
1## $Id: test_browser.py 11736 2014-07-05 12:21:13Z 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 zope.securitypolicy.interfaces import IPrincipalRoleManager
23from waeup.uniben.testing import FunctionalLayer
24from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup, PH_LEN
25
26class CustomApplicantUITests(ApplicantsFullSetup):
27    # Tests for uploading/browsing the passport image of appplicants
28
29    layer = FunctionalLayer
30
31    def test_applicant_access(self):
32        # Anonymous users can't see the application fee.
33        self.browser.open(self.container_path)
34        self.assertFalse('Application Fee' in self.browser.contents)
35        # Applicants can edit their record
36        self.browser.open(self.login_path)
37        self.login()
38        self.assertTrue(
39            'You logged in.' in self.browser.contents)
40        self.browser.open(self.edit_path)
41        self.assertTrue(self.browser.url != self.login_path)
42        self.assertEqual(self.browser.headers['Status'], '200 Ok')
43        self.fill_correct_values()
44        self.browser.getControl("Save").click()
45        self.assertMatches('...Form has been saved...', self.browser.contents)
46        # Applicants can't see the application fee.
47        self.browser.open(self.container_path)
48        self.assertFalse('Application Fee' in self.browser.contents)
49        return
50       
51    def image_url(self, filename):
52        return self.edit_path.replace('edit', filename)
53
54    def test_upload_passport_wo_permission(self):
55        # Create CRPU officer
56        self.app['users'].addUser('mrcrpu', 'mrcrpusecret')
57        self.app['users']['mrcrpu'].email = 'mrcrpu@foo.ng'
58        self.app['users']['mrcrpu'].title = 'Carlo Pitter'
59        prmglobal = IPrincipalRoleManager(self.app)
60        prmglobal.assignRoleToPrincipal('waeup.CCOfficer', 'mrcrpu')
61        # Login as CRPU officer
62        self.browser.open(self.login_path)
63        self.browser.getControl(name="form.login").value = 'mrcrpu'
64        self.browser.getControl(name="form.password").value = 'mrcrpusecret'
65        self.browser.getControl("Login").click()
66        self.assertMatches('...You logged in...', self.browser.contents)
67        # Let's try to change the passport image
68        self.browser.open(self.manage_path)
69        self.fill_correct_values()
70        # Create a pseudo image file and select it to be uploaded in form
71        pseudo_image = StringIO('I pretend to be a graphics file')
72        ctrl = self.browser.getControl(name='form.passport')
73        file_ctrl = ctrl.mech_control
74        file_ctrl.add_file(pseudo_image, filename='myphoto.jpg')
75        self.browser.getControl("Save").click()
76        self.assertMatches('...You are not entitled to upload passport pictures...',
77            self.browser.contents)
78        # The officer still sees the placeholder passport image
79        self.browser.open(self.image_url('passport.jpg'))
80        self.assertEqual(
81            self.browser.headers['content-type'], 'image/jpeg')
82        self.assertEqual(len(self.browser.contents), PH_LEN)
83        # After adding the additional role ...
84        prmglobal.assignRoleToPrincipal('waeup.PassportPictureManager', 'mrcrpu')
85        # ... passport pictures can be uploaded
86        self.browser.open(self.manage_path)
87        self.fill_correct_values()
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('...Form has been saved...', self.browser.contents)
94        # There is a correct <img> link included
95        self.assertTrue(
96            '<img src="passport.jpg" height="180px" />' in self.browser.contents)
97        # Browsing the link shows a real image
98        self.browser.open(self.image_url('passport.jpg'))
99        self.assertEqual(
100            self.browser.headers['content-type'], 'image/jpeg')
101        self.assertEqual(len(self.browser.contents), 31)
Note: See TracBrowser for help on using the repository browser.