Ignore:
Timestamp:
5 Jul 2014, 12:21:13 (11 years ago)
Author:
Henrik Bettermann
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.uniben/trunk/src/waeup/uniben/applicants/tests/test_browser.py

    r10589 r11736  
    1919Test the applicant-related UI components.
    2020"""
     21from StringIO import StringIO
     22from zope.securitypolicy.interfaces import IPrincipalRoleManager
    2123from waeup.uniben.testing import FunctionalLayer
    22 from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
     24from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup, PH_LEN
    2325
    2426class CustomApplicantUITests(ApplicantsFullSetup):
     
    4749        return
    4850       
     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 TracChangeset for help on using the changeset viewer.