Changeset 14197 for main/ikobacustom.uniben/trunk/src/ikobacustom/uniben/customers/tests/test_browser.py
- Timestamp:
- 28 Sep 2016, 07:04:12 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/ikobacustom.uniben/trunk/src/ikobacustom/uniben/customers/tests/test_browser.py
r14190 r14197 222 222 def setup_customizable_params(self): 223 223 self._contract_category = u'riaa' 224 self._document_factory = 'waeup.UnibenCustomer Document'224 self._document_factory = 'waeup.UnibenCustomerPDFDocument' 225 225 self._contract_factory = 'waeup.RIAAContract' 226 226 return 227 227 228 def test_manage_upload_ sample_file(self):228 def test_manage_upload_pdf_file(self): 229 229 # Managers can upload a file via the DocumentManageFormPage 230 230 # The image is stored even if form has errors … … 232 232 self.browser.open(self.customer_path + '/documents/DOC1/manage') 233 233 # 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') 236 236 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') 238 238 # The Save action does not upload files 239 239 self.browser.getControl("Save").click() # submit form 240 240 self.assertFalse( 241 'href="http://localhost/app/customers/B1000000/documents/DOC1/s ample"'241 'href="http://localhost/app/customers/B1000000/documents/DOC1/scan.pdf"' 242 242 in self.browser.contents) 243 243 # ... 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') 246 246 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') 248 248 self.browser.getControl( 249 name='upload_ samplescanmanageupload').click()249 name='upload_pdfscanmanageupload').click() 250 250 self.assertTrue( 251 'href="http://localhost/app/customers/B1000000/documents/DOC1/s ample"'251 'href="http://localhost/app/customers/B1000000/documents/DOC1/scan.pdf"' 252 252 in self.browser.contents) 253 # Browsing the link shows a real image254 self.browser.open('s ample')253 # Browsing the link shows a real pdf file 254 self.browser.open('scan.pdf') 255 255 self.assertEqual( 256 self.browser.headers['content-type'], ' image/jpeg')257 self.assertEqual(len(self.browser.contents), 2 787)256 self.browser.headers['content-type'], 'application/pdf') 257 self.assertEqual(len(self.browser.contents), 24241) 258 258 # We can't reupload a file. The existing file must be deleted first. 259 259 self.browser.open(self.customer_path + '/documents/DOC1/manage') 260 260 self.assertFalse( 261 'upload_ samplescanmanageupload' in self.browser.contents)261 'upload_pdfscanmanageupload' in self.browser.contents) 262 262 # File must be deleted first 263 self.browser.getControl(name='delete_ samplescanmanageupload').click()263 self.browser.getControl(name='delete_pdfscanmanageupload').click() 264 264 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 299 267 300 268 class ContractUITests(CustomersFullSetup): … … 305 273 def setup_customizable_params(self): 306 274 self._contract_category = u'riaa' 307 self._document_factory = 'waeup.UnibenCustomer Document'275 self._document_factory = 'waeup.UnibenCustomerPDFDocument' 308 276 self._contract_factory = 'waeup.RIAAContract' 309 277 return
Note: See TracChangeset for help on using the changeset viewer.