Ignore:
Timestamp:
28 Sep 2016, 07:04:12 (8 years ago)
Author:
Henrik Bettermann
Message:

Add components for customer JPG documents.

Location:
main/ikobacustom.uniben/trunk/src/ikobacustom/uniben/customers/tests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/ikobacustom.uniben/trunk/src/ikobacustom/uniben/customers/tests/test_browser.py

    r14190 r14197  
    222222    def setup_customizable_params(self):
    223223        self._contract_category = u'riaa'
    224         self._document_factory = 'waeup.UnibenCustomerDocument'
     224        self._document_factory = 'waeup.UnibenCustomerPDFDocument'
    225225        self._contract_factory = 'waeup.RIAAContract'
    226226        return
    227227
    228     def test_manage_upload_sample_file(self):
     228    def test_manage_upload_pdf_file(self):
    229229        # Managers can upload a file via the DocumentManageFormPage
    230230        # The image is stored even if form has errors
     
    232232        self.browser.open(self.customer_path + '/documents/DOC1/manage')
    233233        # Create a pseudo image file and select it to be uploaded
    234         image = open(SAMPLE_IMAGE, 'rb')
    235         ctrl = self.browser.getControl(name='samplescanmanageupload')
     234        image = open(SAMPLE_PDF, 'rb')
     235        ctrl = self.browser.getControl(name='pdfscanmanageupload')
    236236        file_ctrl = ctrl.mech_control
    237         file_ctrl.add_file(image, filename='my_sample_scan.jpg')
     237        file_ctrl.add_file(image, filename='my_sample_scan.pdf')
    238238        # The Save action does not upload files
    239239        self.browser.getControl("Save").click() # submit form
    240240        self.assertFalse(
    241             'href="http://localhost/app/customers/B1000000/documents/DOC1/sample"'
     241            'href="http://localhost/app/customers/B1000000/documents/DOC1/scan.pdf"'
    242242            in self.browser.contents)
    243243        # ... but the correct upload submit button does
    244         image = open(SAMPLE_IMAGE)
    245         ctrl = self.browser.getControl(name='samplescanmanageupload')
     244        image = open(SAMPLE_PDF)
     245        ctrl = self.browser.getControl(name='pdfscanmanageupload')
    246246        file_ctrl = ctrl.mech_control
    247         file_ctrl.add_file(image, filename='my_sample_scan.jpg')
     247        file_ctrl.add_file(image, filename='my_sample_scan.pdf')
    248248        self.browser.getControl(
    249             name='upload_samplescanmanageupload').click()
     249            name='upload_pdfscanmanageupload').click()
    250250        self.assertTrue(
    251             'href="http://localhost/app/customers/B1000000/documents/DOC1/sample"'
     251            'href="http://localhost/app/customers/B1000000/documents/DOC1/scan.pdf"'
    252252            in self.browser.contents)
    253         # Browsing the link shows a real image
    254         self.browser.open('sample')
     253        # Browsing the link shows a real pdf file
     254        self.browser.open('scan.pdf')
    255255        self.assertEqual(
    256             self.browser.headers['content-type'], 'image/jpeg')
    257         self.assertEqual(len(self.browser.contents), 2787)
     256            self.browser.headers['content-type'], 'application/pdf')
     257        self.assertEqual(len(self.browser.contents), 24241)
    258258        # We can't reupload a file. The existing file must be deleted first.
    259259        self.browser.open(self.customer_path + '/documents/DOC1/manage')
    260260        self.assertFalse(
    261             'upload_samplescanmanageupload' in self.browser.contents)
     261            'upload_pdfscanmanageupload' in self.browser.contents)
    262262        # File must be deleted first
    263         self.browser.getControl(name='delete_samplescanmanageupload').click()
     263        self.browser.getControl(name='delete_pdfscanmanageupload').click()
    264264        self.assertTrue(
    265             'sample deleted' in self.browser.contents)
    266         # Uploading a file which is bigger than 150k will raise an error
    267         big_image = StringIO(open(SAMPLE_IMAGE, 'rb').read() * 75)
    268         ctrl = self.browser.getControl(name='samplescanmanageupload')
    269         file_ctrl = ctrl.mech_control
    270         file_ctrl.add_file(big_image, filename='my_sample_scan.jpg')
    271         self.browser.getControl(
    272             name='upload_samplescanmanageupload').click()
    273         self.assertTrue(
    274             'Uploaded file is too big' in self.browser.contents)
    275         # We do not rely on filename extensions given by uploaders
    276         image = open(SAMPLE_IMAGE, 'rb') # a jpg-file
    277         ctrl = self.browser.getControl(name='samplescanmanageupload')
    278         file_ctrl = ctrl.mech_control
    279         # Tell uploaded file is bmp
    280         file_ctrl.add_file(image, filename='my_sample_scan.bmp')
    281         self.browser.getControl(
    282             name='upload_samplescanmanageupload').click()
    283         self.assertTrue(
    284             # jpg file was recognized
    285             'File sample.jpg uploaded.' in self.browser.contents)
    286         # Delete file again
    287         self.browser.getControl(name='delete_samplescanmanageupload').click()
    288         self.assertTrue(
    289             'sample deleted' in self.browser.contents)
    290         # File names must meet several conditions
    291         bmp_image = open(SAMPLE_IMAGE_BMP, 'rb')
    292         ctrl = self.browser.getControl(name='samplescanmanageupload')
    293         file_ctrl = ctrl.mech_control
    294         file_ctrl.add_file(bmp_image, filename='my_sample_scan.bmp')
    295         self.browser.getControl(
    296             name='upload_samplescanmanageupload').click()
    297         self.assertTrue('Only the following extensions are allowed'
    298             in self.browser.contents)
     265            'scan.pdf deleted' in self.browser.contents)
     266
    299267
    300268class ContractUITests(CustomersFullSetup):
     
    305273    def setup_customizable_params(self):
    306274        self._contract_category = u'riaa'
    307         self._document_factory = 'waeup.UnibenCustomerDocument'
     275        self._document_factory = 'waeup.UnibenCustomerPDFDocument'
    308276        self._contract_factory = 'waeup.RIAAContract'
    309277        return
  • main/ikobacustom.uniben/trunk/src/ikobacustom/uniben/customers/tests/test_document.py

    r14181 r14197  
    2929
    3030from ikobacustom.uniben.testing import (FunctionalLayer, FunctionalTestCase)
    31 from ikobacustom.uniben.customers.documents import UnibenCustomerDocument
    32 from ikobacustom.uniben.customers.interfaces import IUnibenCustomerDocument
     31from ikobacustom.uniben.customers.documents import (
     32    UnibenCustomerPDFDocument, UnibenCustomerJPGDocument)
     33from ikobacustom.uniben.customers.interfaces import (
     34    IUnibenCustomerPDFDocument, IUnibenCustomerJPGDocument)
    3335
    3436
     
    3840
    3941    def test_interfaces(self):
    40         verify.verifyClass(IUnibenCustomerDocument, UnibenCustomerDocument)
    41         verify.verifyClass(ICustomerNavigation, UnibenCustomerDocument)
    42         verify.verifyObject(IUnibenCustomerDocument, UnibenCustomerDocument())
    43         verify.verifyObject(ICustomerNavigation, UnibenCustomerDocument())
     42        verify.verifyClass(IUnibenCustomerPDFDocument, UnibenCustomerPDFDocument)
     43        verify.verifyClass(ICustomerNavigation, UnibenCustomerPDFDocument)
     44        verify.verifyObject(IUnibenCustomerPDFDocument, UnibenCustomerPDFDocument())
     45        verify.verifyObject(ICustomerNavigation, UnibenCustomerPDFDocument())
     46        verify.verifyClass(IUnibenCustomerJPGDocument, UnibenCustomerJPGDocument)
     47        verify.verifyClass(ICustomerNavigation, UnibenCustomerJPGDocument)
     48        verify.verifyObject(IUnibenCustomerJPGDocument, UnibenCustomerJPGDocument())
     49        verify.verifyObject(ICustomerNavigation, UnibenCustomerJPGDocument())
    4450        return
    4551
    4652    def test_addDocument(self):
    4753        container = CustomerDocumentsContainer()
    48         document = createObject(u'waeup.UnibenCustomerDocument')
     54        document = createObject(u'waeup.UnibenCustomerPDFDocument')
    4955        id = document.document_id
    5056        container.addDocument(document)
    5157        self.assertEqual(container[id], document)
    5258        self.assertRaises(TypeError, container.addDocument, object())
    53         self.assertEqual(document.class_name, 'UnibenCustomerDocument')
     59        self.assertEqual(document.class_name, 'UnibenCustomerPDFDocument')
     60        document2 = createObject(u'waeup.UnibenCustomerJPGDocument')
     61        id = document2.document_id
     62        container.addDocument(document2)
     63        self.assertEqual(container[id], document2)
     64        self.assertRaises(TypeError, container.addDocument, object())
     65        self.assertEqual(document2.class_name, 'UnibenCustomerJPGDocument')
    5466        return
Note: See TracChangeset for help on using the changeset viewer.