Changeset 12382
- Timestamp:
- 3 Jan 2015, 15:28:53 (10 years ago)
- Location:
- main/ikobacustom.skeleton/trunk/src/ikobacustom/skeleton/customers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/ikobacustom.skeleton/trunk/src/ikobacustom/skeleton/customers/fileviewlets.py
r12372 r12382 79 79 grok.view(PDFDocumentSlipPage) 80 80 81 82 class PDFScanManageUpload(FileUpload):83 """Scan upload viewlet for officers.84 """85 grok.view(DocumentManageFormPage)86 grok.context(SkeletonCustomerDocument)87 grok.require('waeup.manageCustomer')88 label = _(u'PDF File')89 title = _(u'PDF File')90 mus = 1024 * 20091 download_name = u'sample.pdf'92 tab_redirect = '#tab2'93 94 95 class PDFScanEditUpload(PDFScanManageUpload):96 """Scan upload viewlet for customer.97 """98 grok.view(DocumentEditFormPage)99 grok.require('waeup.handleCustomer')100 101 102 class PDFScanDisplay(FileDisplay):103 """Scan display viewlet.104 """105 grok.order(1)106 grok.context(SkeletonCustomerDocument)107 grok.require('waeup.viewCustomer')108 grok.view(DocumentDisplayFormPage)109 label = _(u'PDF Scan')110 title = _(u'PDF Scan')111 download_name = u'sample.pdf'112 113 114 class PDFScanImage(Image):115 """Scan document.116 """117 grok.name('sample.pdf')118 grok.context(SkeletonCustomerDocument)119 grok.require('waeup.viewCustomer')120 download_name = u'sample.pdf'121 122 class PDFScanSlip(PDFScanDisplay):123 grok.view(PDFDocumentSlipPage) -
main/ikobacustom.skeleton/trunk/src/ikobacustom/skeleton/customers/tests/test_browser.py
r12369 r12382 213 213 layer = FunctionalLayer 214 214 215 def test_manage_upload_ pdf_file(self):215 def test_manage_upload_sample_file(self): 216 216 # Managers can upload a file via the DocumentManageFormPage 217 217 # The image is stored even if form has errors 218 218 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 219 self.browser.open(self.customer_path + '/documents') 220 self.browser.getControl("Add document").click() 221 self.browser.getControl(name="doctype").value = ['SkeletonCustomerDocument'] 222 self.browser.getControl(name="form.title").value = 'My Skeleton Document' 223 self.browser.getControl("Add document").click() 224 docid = [i for i in self.customer['documents'].keys() if len(i) > 10][0] 225 self.browser.open(self.documents_path + '/%s/manage' % docid) 219 self.browser.open(self.customer_path + '/documents/DOC1/manage') 226 220 # Create a pseudo image file and select it to be uploaded 227 221 image = open(SAMPLE_IMAGE, 'rb') 228 ctrl = self.browser.getControl(name='pdfscanmanageupload') 222 ctrl = self.browser.getControl(name='samplescanmanageupload') 223 file_ctrl = ctrl.mech_control 224 file_ctrl.add_file(image, filename='my_sample_scan.jpg') 225 # The Save action does not upload files 226 self.browser.getControl("Save").click() # submit form 227 self.assertFalse( 228 'href="http://localhost/app/customers/K1000000/documents/DOC1/sample"' 229 in self.browser.contents) 230 # ... but the correct upload submit button does 231 image = open(SAMPLE_IMAGE) 232 ctrl = self.browser.getControl(name='samplescanmanageupload') 229 233 file_ctrl = ctrl.mech_control 230 234 file_ctrl.add_file(image, filename='my_sample_scan.jpg') 231 235 self.browser.getControl( 232 name='upload_pdfscanmanageupload').click() 233 self.assertTrue( 234 'pdf file extension expected' in self.browser.contents) 235 ctrl = self.browser.getControl(name='pdfscanmanageupload') 236 file_ctrl = ctrl.mech_control 237 file_ctrl.add_file(image, filename='my_sample_scan.pdf') 236 name='upload_samplescanmanageupload').click() 237 self.assertTrue( 238 'href="http://localhost/app/customers/K1000000/documents/DOC1/sample"' 239 in self.browser.contents) 240 # Browsing the link shows a real image 241 self.browser.open('sample') 242 self.assertEqual( 243 self.browser.headers['content-type'], 'image/jpeg') 244 self.assertEqual(len(self.browser.contents), 2787) 245 # We can't reupload a file. The existing file must be deleted first. 246 self.browser.open(self.customer_path + '/documents/DOC1/manage') 247 self.assertFalse( 248 'upload_samplescanmanageupload' in self.browser.contents) 249 # File must be deleted first 250 self.browser.getControl(name='delete_samplescanmanageupload').click() 251 self.assertTrue( 252 'sample deleted' in self.browser.contents) 253 # Uploading a file which is bigger than 150k will raise an error 254 big_image = StringIO(open(SAMPLE_IMAGE, 'rb').read() * 75) 255 ctrl = self.browser.getControl(name='samplescanmanageupload') 256 file_ctrl = ctrl.mech_control 257 file_ctrl.add_file(big_image, filename='my_sample_scan.jpg') 238 258 self.browser.getControl( 239 name='upload_pdfscanmanageupload').click() 240 self.assertTrue( 241 'Could not determine file type' in self.browser.contents) 242 pdf = open(SAMPLE_PDF, 'rb') 243 ctrl = self.browser.getControl(name='pdfscanmanageupload') 244 file_ctrl = ctrl.mech_control 245 file_ctrl.add_file(pdf, filename='my_sample_scan.pdf') 259 name='upload_samplescanmanageupload').click() 260 self.assertTrue( 261 'Uploaded file is too big' in self.browser.contents) 262 # We do not rely on filename extensions given by uploaders 263 image = open(SAMPLE_IMAGE, 'rb') # a jpg-file 264 ctrl = self.browser.getControl(name='samplescanmanageupload') 265 file_ctrl = ctrl.mech_control 266 # Tell uploaded file is bmp 267 file_ctrl.add_file(image, filename='my_sample_scan.bmp') 246 268 self.browser.getControl( 247 name='upload_pdfscanmanageupload').click() 248 self.assertTrue( 249 'href="http://localhost/app/customers/K1000000/documents/%s/sample.pdf">PDF File</a>' 250 % docid in self.browser.contents) 251 # Browsing the link shows a real pdf 252 self.browser.open('sample.pdf') 253 self.assertEqual( 254 self.browser.headers['content-type'], 'application/pdf') 269 name='upload_samplescanmanageupload').click() 270 self.assertTrue( 271 # jpg file was recognized 272 'File sample.jpg uploaded.' in self.browser.contents) 273 # Delete file again 274 self.browser.getControl(name='delete_samplescanmanageupload').click() 275 self.assertTrue( 276 'sample deleted' in self.browser.contents) 277 # File names must meet several conditions 278 bmp_image = open(SAMPLE_IMAGE_BMP, 'rb') 279 ctrl = self.browser.getControl(name='samplescanmanageupload') 280 file_ctrl = ctrl.mech_control 281 file_ctrl.add_file(bmp_image, filename='my_sample_scan.bmp') 282 self.browser.getControl( 283 name='upload_samplescanmanageupload').click() 284 self.assertTrue('Only the following extensions are allowed' 285 in self.browser.contents) 255 286 256 287 class ContractUITests(CustomersFullSetup):
Note: See TracChangeset for help on using the changeset viewer.