Ignore:
Timestamp:
17 Nov 2011, 07:42:42 (13 years ago)
Author:
Henrik Bettermann
Message:

Allow upload of files with various extensions as defined in ALLOWED_FILE_EXTENSIONS. Check file extension in handle_file_upload, not in createFile.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py

    r7122 r7123  
    364364        # No birth certificate has been uploaded yet
    365365        # Browsing the link shows a placerholder image
    366         self.browser.open('birth_certificate.jpg')
     366        self.browser.open('birth_certificate')
    367367        self.assertEqual(
    368368            self.browser.headers['content-type'], 'image/jpeg')
     
    378378        self.browser.getControl("Save (no upload)").click() # submit form
    379379        self.assertFalse(
    380             '<a target="image" href="birth_certificate.jpg">'
     380            '<a target="image" href="birth_certificate">'
    381381            in self.browser.contents)
    382382        # ... but the correct upload submit button does
     
    389389        # There is a correct <img> link included
    390390        self.assertTrue(
    391             '<a target="image" href="birth_certificate.jpg">'
     391            '<a target="image" href="birth_certificate">'
    392392            in self.browser.contents)
    393393
    394394        # Browsing the link shows a real image
    395         self.browser.open('birth_certificate.jpg')
     395        self.browser.open('birth_certificate')
    396396        self.assertEqual(
    397397            self.browser.headers['content-type'], 'image/jpeg')
     
    428428        self.browser.getControl(
    429429            name='upload_birthcertificateuploadmanage').click()
    430         self.assertTrue('.jpg file extension expected' in self.browser.contents)
     430        self.assertTrue('Only the following extension are allowed'
     431            in self.browser.contents)
    431432        # Managers can delete files
    432433        self.browser.getControl(name='delete_birthcertificateuploadmanage').click()
    433434        self.assertTrue(
    434             'File birth_certificate.jpg deleted'
    435             in self.browser.contents)
     435            'birth_certificate deleted' in self.browser.contents)
    436436        # Managers can add and delete second file
    437437        self.browser.open(self.edit_clearance_student_path)
     
    443443            name='upload_acceptanceletteruploadmanage').click()
    444444        self.assertFalse(
    445             '<a target="image" href="acceptance_letter.jpg">'
     445            '<a target="image" href="acceptance_letter">'
    446446            in self.browser.contents)
    447447        ctrl = self.browser.getControl(name='acceptanceletteruploadmanage')
     
    451451            name='upload_acceptanceletteruploadmanage').click()
    452452        self.assertTrue(
    453             '<a target="image" href="acceptance_letter.jpg">'
     453            '<a target="image" href="acceptance_letter">'
    454454            in self.browser.contents)
    455455        self.browser.getControl(
    456456            name='delete_acceptanceletteruploadmanage').click()
    457457        self.assertTrue(
    458             'File acceptance_letter.jpg deleted'
     458            'acceptance_letter deleted'
     459            in self.browser.contents)
     460        # Managers can upload a file via the StudentBaseManageFormPage
     461        self.browser.open(self.manage_student_path)
     462        pseudo_image = StringIO('I pretend to be a graphics file')
     463        ctrl = self.browser.getControl(name='passportuploadmanage')
     464        file_ctrl = ctrl.mech_control
     465        file_ctrl.add_file(pseudo_image, filename='my_photo.bmp')
     466        self.browser.getControl(
     467            name='upload_passportuploadmanage').click()
     468        self.assertTrue('jpg file extension expected'
     469            in self.browser.contents)
     470        ctrl = self.browser.getControl(name='passportuploadmanage')
     471        file_ctrl = ctrl.mech_control
     472        file_ctrl.add_file(pseudo_image, filename='my_photo.jpg')
     473        self.browser.getControl(
     474            name='upload_passportuploadmanage').click()
     475        self.assertTrue(
     476            '<img align="middle" height="125px" src="passport.jpg" />'
    459477            in self.browser.contents)
    460478
Note: See TracChangeset for help on using the changeset viewer.