- Timestamp:
- 28 Sep 2016, 07:04:12 (8 years ago)
- 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 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 -
main/ikobacustom.uniben/trunk/src/ikobacustom/uniben/customers/tests/test_document.py
r14181 r14197 29 29 30 30 from ikobacustom.uniben.testing import (FunctionalLayer, FunctionalTestCase) 31 from ikobacustom.uniben.customers.documents import UnibenCustomerDocument 32 from ikobacustom.uniben.customers.interfaces import IUnibenCustomerDocument 31 from ikobacustom.uniben.customers.documents import ( 32 UnibenCustomerPDFDocument, UnibenCustomerJPGDocument) 33 from ikobacustom.uniben.customers.interfaces import ( 34 IUnibenCustomerPDFDocument, IUnibenCustomerJPGDocument) 33 35 34 36 … … 38 40 39 41 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()) 44 50 return 45 51 46 52 def test_addDocument(self): 47 53 container = CustomerDocumentsContainer() 48 document = createObject(u'waeup.UnibenCustomer Document')54 document = createObject(u'waeup.UnibenCustomerPDFDocument') 49 55 id = document.document_id 50 56 container.addDocument(document) 51 57 self.assertEqual(container[id], document) 52 58 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') 54 66 return
Note: See TracChangeset for help on using the changeset viewer.