Ignore:
Timestamp:
22 Nov 2014, 18:42:57 (10 years ago)
Author:
Henrik Bettermann
Message:

Add test for managing customer document file uploads.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py

    r12036 r12037  
    884884        self.browser.open(self.documents_path + '/d102/edit')
    885885        self.assertTrue('The requested form is locked' in self.browser.contents)
     886
     887    def test_manage_upload_file(self):
     888        # Managers can upload a file via the DocumentManageFormPage
     889        # The image is stored even if form has errors
     890        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     891        self.browser.open(self.customer_path + '/documents/d101/manage')
     892        # Create a pseudo image file and select it to be uploaded in form
     893        # as generic document
     894        image = open(SAMPLE_IMAGE, 'rb')
     895        ctrl = self.browser.getControl(name='genericuploadmanage')
     896        file_ctrl = ctrl.mech_control
     897        file_ctrl.add_file(image, filename='my_generic_document.jpg')
     898        # The Save action does not upload files
     899        self.browser.getControl("Save").click() # submit form
     900        self.assertFalse(
     901            'href="http://localhost/app/customers/K1000000/documents/d101/generic"'
     902            in self.browser.contents)
     903        # ... but the correct upload submit button does
     904        image = open(SAMPLE_IMAGE)
     905        ctrl = self.browser.getControl(name='genericuploadmanage')
     906        file_ctrl = ctrl.mech_control
     907        file_ctrl.add_file(image, filename='my_generic_document.jpg')
     908        self.browser.getControl(
     909            name='upload_genericuploadmanage').click()
     910        self.assertTrue(
     911            'href="http://localhost/app/customers/K1000000/documents/d101/generic"'
     912            in self.browser.contents)
     913        # Browsing the link shows a real image
     914        self.browser.open('generic')
     915        self.assertEqual(
     916            self.browser.headers['content-type'], 'image/jpeg')
     917        self.assertEqual(len(self.browser.contents), 2787)
     918        # We can't reupload a file. The existing file must be deleted first.
     919        self.browser.open(self.customer_path + '/documents/d101/manage')
     920        self.assertFalse(
     921            'upload_genericuploadmanage' in self.browser.contents)
     922        # File must be deleted first
     923        self.browser.getControl(name='delete_genericuploadmanage').click()
     924        self.assertTrue(
     925            'generic deleted' in self.browser.contents)
     926        # Uploading a file which is bigger than 150k will raise an error
     927        big_image = StringIO(open(SAMPLE_IMAGE, 'rb').read() * 75)
     928        ctrl = self.browser.getControl(name='genericuploadmanage')
     929        file_ctrl = ctrl.mech_control
     930        file_ctrl.add_file(big_image, filename='my_generic_document.jpg')
     931        self.browser.getControl(
     932            name='upload_genericuploadmanage').click()
     933        self.assertTrue(
     934            'Uploaded file is too big' in self.browser.contents)
     935        # we do not rely on filename extensions given by uploaders
     936        image = open(SAMPLE_IMAGE, 'rb') # a jpg-file
     937        ctrl = self.browser.getControl(name='genericuploadmanage')
     938        file_ctrl = ctrl.mech_control
     939        # tell uploaded file is bmp
     940        file_ctrl.add_file(image, filename='my_generic_document.bmp')
     941        self.browser.getControl(
     942            name='upload_genericuploadmanage').click()
     943        self.assertTrue(
     944            # jpg file was recognized
     945            'File generic.jpg uploaded.' in self.browser.contents)
     946        # Delete file again
     947        self.browser.getControl(name='delete_genericuploadmanage').click()
     948        self.assertTrue(
     949            'generic deleted' in self.browser.contents)
     950        # File names must meet several conditions
     951        bmp_image = open(SAMPLE_IMAGE_BMP, 'rb')
     952        ctrl = self.browser.getControl(name='genericuploadmanage')
     953        file_ctrl = ctrl.mech_control
     954        file_ctrl.add_file(bmp_image, filename='my_generic_document.bmp')
     955        self.browser.getControl(
     956            name='upload_genericuploadmanage').click()
     957        self.assertTrue('Only the following extensions are allowed'
     958            in self.browser.contents)
Note: See TracChangeset for help on using the changeset viewer.