Ignore:
Timestamp:
11 Nov 2011, 10:04:57 (13 years ago)
Author:
uli
Message:

Ensure in tests that the maximum upload size restriction really works.

File:
1 edited

Legend:

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

    r7074 r7083  
    661661        self.assertEqual(len(self.browser.contents), PH_LEN)
    662662
     663    def test_uploaded_image_respects_file_size_restriction(self):
     664        # When we upload an image that is too big ( > 10 KB) we will
     665        # get an error message
     666        self.login()
     667        # Create a pseudo image file and select it to be uploaded in form
     668        photo_content = 'A' * 1024 * 11  # A string of 11 GB size
     669        pseudo_image = StringIO(photo_content)
     670        ctrl = self.browser.getControl(name='form.passport')
     671        file_ctrl = ctrl.mech_control
     672        file_ctrl.add_file(pseudo_image, filename='myphoto.jpg')
     673        self.browser.getControl("Save").click() # submit form
     674        # There is a correct <img> link included
     675        self.assertTrue(
     676            '<img src="passport.jpg" />' in self.browser.contents)
     677        # We get a warning message
     678        self.assertTrue(
     679            'Uploaded image is too big' in self.browser.contents)
     680        # Browsing the image gives us the default image, not the
     681        # uploaded one.
     682        self.browser.open(self.image_url('passport.jpg'))
     683        self.assertEqual(
     684            self.browser.headers['content-type'], 'image/jpeg')
     685        self.assertEqual(len(self.browser.contents), PH_LEN)
     686        # There is really no file stored for the applicant
     687        img = getUtility(IExtFileStore).getFile(
     688            IFileStoreNameChooser(self.applicant).chooseName())
     689        self.assertTrue(img is None)
     690
    663691    def test_uploaded_image_browsable_w_errors(self):
    664692        # We can upload a different image and browse it after submit,
Note: See TracChangeset for help on using the changeset viewer.