Index: main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py
===================================================================
--- main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py	(revision 12036)
+++ main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py	(revision 12037)
@@ -884,2 +884,75 @@
         self.browser.open(self.documents_path + '/d102/edit')
         self.assertTrue('The requested form is locked' in self.browser.contents)
+
+    def test_manage_upload_file(self):
+        # Managers can upload a file via the DocumentManageFormPage
+        # The image is stored even if form has errors
+        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
+        self.browser.open(self.customer_path + '/documents/d101/manage')
+        # Create a pseudo image file and select it to be uploaded in form
+        # as generic document
+        image = open(SAMPLE_IMAGE, 'rb')
+        ctrl = self.browser.getControl(name='genericuploadmanage')
+        file_ctrl = ctrl.mech_control
+        file_ctrl.add_file(image, filename='my_generic_document.jpg')
+        # The Save action does not upload files
+        self.browser.getControl("Save").click() # submit form
+        self.assertFalse(
+            'href="http://localhost/app/customers/K1000000/documents/d101/generic"'
+            in self.browser.contents)
+        # ... but the correct upload submit button does
+        image = open(SAMPLE_IMAGE)
+        ctrl = self.browser.getControl(name='genericuploadmanage')
+        file_ctrl = ctrl.mech_control
+        file_ctrl.add_file(image, filename='my_generic_document.jpg')
+        self.browser.getControl(
+            name='upload_genericuploadmanage').click()
+        self.assertTrue(
+            'href="http://localhost/app/customers/K1000000/documents/d101/generic"'
+            in self.browser.contents)
+        # Browsing the link shows a real image
+        self.browser.open('generic')
+        self.assertEqual(
+            self.browser.headers['content-type'], 'image/jpeg')
+        self.assertEqual(len(self.browser.contents), 2787)
+        # We can't reupload a file. The existing file must be deleted first.
+        self.browser.open(self.customer_path + '/documents/d101/manage')
+        self.assertFalse(
+            'upload_genericuploadmanage' in self.browser.contents)
+        # File must be deleted first
+        self.browser.getControl(name='delete_genericuploadmanage').click()
+        self.assertTrue(
+            'generic deleted' in self.browser.contents)
+        # Uploading a file which is bigger than 150k will raise an error
+        big_image = StringIO(open(SAMPLE_IMAGE, 'rb').read() * 75)
+        ctrl = self.browser.getControl(name='genericuploadmanage')
+        file_ctrl = ctrl.mech_control
+        file_ctrl.add_file(big_image, filename='my_generic_document.jpg')
+        self.browser.getControl(
+            name='upload_genericuploadmanage').click()
+        self.assertTrue(
+            'Uploaded file is too big' in self.browser.contents)
+        # we do not rely on filename extensions given by uploaders
+        image = open(SAMPLE_IMAGE, 'rb') # a jpg-file
+        ctrl = self.browser.getControl(name='genericuploadmanage')
+        file_ctrl = ctrl.mech_control
+        # tell uploaded file is bmp
+        file_ctrl.add_file(image, filename='my_generic_document.bmp')
+        self.browser.getControl(
+            name='upload_genericuploadmanage').click()
+        self.assertTrue(
+            # jpg file was recognized
+            'File generic.jpg uploaded.' in self.browser.contents)
+        # Delete file again
+        self.browser.getControl(name='delete_genericuploadmanage').click()
+        self.assertTrue(
+            'generic deleted' in self.browser.contents)
+        # File names must meet several conditions
+        bmp_image = open(SAMPLE_IMAGE_BMP, 'rb')
+        ctrl = self.browser.getControl(name='genericuploadmanage')
+        file_ctrl = ctrl.mech_control
+        file_ctrl.add_file(bmp_image, filename='my_generic_document.bmp')
+        self.browser.getControl(
+            name='upload_genericuploadmanage').click()
+        self.assertTrue('Only the following extensions are allowed'
+            in self.browser.contents)
