Changeset 11972


Ignore:
Timestamp:
16 Nov 2014, 18:04:16 (10 years ago)
Author:
Henrik Bettermann
Message:

Add more tests.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba/customers
Files:
1 added
2 edited

Legend:

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

    r11971 r11972  
    2525from waeup.ikoba.interfaces import MessageFactory as _
    2626from waeup.ikoba.browser import DEFAULT_IMAGE_PATH
    27 from waeup.ikoba.utils.helpers import string_from_bytes, file_size
     27from waeup.ikoba.utils.helpers import (
     28    string_from_bytes, file_size, get_fileformat)
    2829from waeup.ikoba.browser.layout import (
    2930    default_filedisplay_template,
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py

    r11971 r11972  
    323323        return
    324324
    325     def xxx_test_manage_upload_file(self):
    326         # Managers can upload a file via the CustomerClearanceManageFormPage
    327         # The image is stored even if form has errors
    328         self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    329         self.browser.open(self.manage_clearance_path)
    330         # No birth certificate has been uploaded yet
    331         # Browsing the link shows a placerholder image
    332         self.browser.open('birth_certificate')
    333         self.assertEqual(
    334             self.browser.headers['content-type'], 'image/jpeg')
    335         self.assertEqual(len(self.browser.contents), PH_LEN)
    336         # Create a pseudo image file and select it to be uploaded in form
    337         # as birth certificate
    338         self.browser.open(self.manage_clearance_path)
    339         image = open(SAMPLE_IMAGE, 'rb')
    340         ctrl = self.browser.getControl(name='birthcertificateupload')
    341         file_ctrl = ctrl.mech_control
    342         file_ctrl.add_file(image, filename='my_birth_certificate.jpg')
    343         # The Save action does not upload files
    344         self.browser.getControl("Save").click() # submit form
    345         self.assertFalse(
    346             '<a target="image" href="birth_certificate">'
    347             in self.browser.contents)
    348         # ... but the correct upload submit button does
    349         image = open(SAMPLE_IMAGE)
    350         ctrl = self.browser.getControl(name='birthcertificateupload')
    351         file_ctrl = ctrl.mech_control
    352         file_ctrl.add_file(image, filename='my_birth_certificate.jpg')
    353         self.browser.getControl(
    354             name='upload_birthcertificateupload').click()
    355         # There is a correct <img> link included
    356         self.assertTrue(
    357             'href="http://localhost/app/customers/K1000000/birth_certificate"'
    358             in self.browser.contents)
    359         # Browsing the link shows a real image
    360         self.browser.open('birth_certificate')
    361         self.assertEqual(
    362             self.browser.headers['content-type'], 'image/jpeg')
    363         self.assertEqual(len(self.browser.contents), 2787)
    364         # We can't reupload a file. The existing file must be deleted first.
    365         self.browser.open(self.manage_clearance_path)
    366         self.assertFalse(
    367             'upload_birthcertificateupload' in self.browser.contents)
    368         # File must be deleted first
    369         self.browser.getControl(name='delete_birthcertificateupload').click()
    370         self.assertTrue(
    371             'birth_certificate deleted' in self.browser.contents)
    372         # Uploading a file which is bigger than 150k will raise an error
    373         big_image = StringIO(open(SAMPLE_IMAGE, 'rb').read() * 75)
    374         ctrl = self.browser.getControl(name='birthcertificateupload')
    375         file_ctrl = ctrl.mech_control
    376         file_ctrl.add_file(big_image, filename='my_birth_certificate.jpg')
    377         self.browser.getControl(
    378             name='upload_birthcertificateupload').click()
    379         self.assertTrue(
    380             'Uploaded file is too big' in self.browser.contents)
    381         # we do not rely on filename extensions given by uploaders
    382         image = open(SAMPLE_IMAGE, 'rb') # a jpg-file
    383         ctrl = self.browser.getControl(name='birthcertificateupload')
    384         file_ctrl = ctrl.mech_control
    385         # tell uploaded file is bmp
    386         file_ctrl.add_file(image, filename='my_birth_certificate.bmp')
    387         self.browser.getControl(
    388             name='upload_birthcertificateupload').click()
    389         self.assertTrue(
    390             # jpg file was recognized
    391             'File birth_certificate.jpg uploaded.' in self.browser.contents)
    392         # Delete file again
    393         self.browser.getControl(name='delete_birthcertificateupload').click()
    394         self.assertTrue(
    395             'birth_certificate deleted' in self.browser.contents)
    396         # File names must meet several conditions
    397         bmp_image = open(SAMPLE_IMAGE_BMP, 'rb')
    398         ctrl = self.browser.getControl(name='birthcertificateupload')
    399         file_ctrl = ctrl.mech_control
    400         file_ctrl.add_file(bmp_image, filename='my_birth_certificate.bmp')
    401         self.browser.getControl(
    402             name='upload_birthcertificateupload').click()
    403         self.assertTrue('Only the following extensions are allowed'
    404             in self.browser.contents)
    405 
     325    def test_manage_upload_passport(self):
    406326        # Managers can upload a file via the CustomerBaseManageFormPage
     327        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    407328        self.browser.open(self.manage_customer_path)
    408329        image = open(SAMPLE_IMAGE_BMP, 'rb')
     
    426347        self.browser.open(self.manage_customer_path)
    427348        self.browser.getControl('Delete').click()
    428         self.browser.open(self.customer_path + '/clearance_slip.pdf')
    429         self.assertEqual(self.browser.headers['Status'], '200 Ok')
    430         self.assertEqual(self.browser.headers['Content-Type'],
    431                          'application/pdf')
     349        self.assertTrue('passport.jpg deleted' in self.browser.contents)
     350
    432351
    433352    def test_manage_workflow(self):
     
    440359        self.browser.getControl(name="transition").value = ['request']
    441360        self.browser.getControl("Save").click()
     361        self.browser.getControl(name="transition").value = ['reject']
     362        self.browser.getControl("Save").click()
     363        self.browser.getControl(name="transition").value = ['request']
     364        self.browser.getControl("Save").click()
    442365        self.browser.getControl(name="transition").value = ['approve']
    443366        self.browser.getControl("Save").click()
Note: See TracChangeset for help on using the changeset viewer.