Changeset 7101
- Timestamp:
- 13 Nov 2011, 06:36:31 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py
r7068 r7101 25 25 import shutil 26 26 import tempfile 27 import cStringIO27 from StringIO import StringIO 28 28 from datetime import datetime 29 29 import grok … … 357 357 return 358 358 359 def test_upload_file(self): 360 # Managers can upload a file via the StudentClearanceManageFormPage 361 # The image is stored even if form has errors 362 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 363 self.browser.open(self.edit_clearance_student_path) 364 # Create a pseudo image file and select it to be uploaded in form 365 # as birth certificate 366 pseudo_image = StringIO('I pretend to be a graphics file') 367 ctrl = self.browser.getControl(name='form.birth_certificate') 368 file_ctrl = ctrl.mech_control 369 file_ctrl.add_file(pseudo_image, filename='myphoto.jpg') 370 self.browser.getControl("Save").click() # submit form 371 # Form has errors ... 372 self.assertTrue( 373 'Required input is missing' in self.browser.contents) 374 # ... but file has been uploaded and a correct <img> link included 375 self.assertTrue( 376 '<a target="image" href="birth_certificate.jpg">' in self.browser.contents) 377 # There is a correct <img> link included 378 self.assertTrue( 379 '<a target="image" href="birth_certificate.jpg">' 380 in self.browser.contents) 381 # Browsing the link shows a real image 382 self.browser.open('birth_certificate.jpg') 383 self.assertEqual( 384 self.browser.headers['content-type'], 'image/jpeg') 385 self.assertEqual(len(self.browser.contents), 31) 386 # Reuploading a file which is bigger than 150k will raise an error 387 self.browser.open(self.edit_clearance_student_path) 388 photo_content = 'A' * 1024 * 151 # A string of 21 KB size 389 pseudo_image = StringIO(photo_content) 390 ctrl = self.browser.getControl(name='form.birth_certificate') 391 file_ctrl = ctrl.mech_control 392 file_ctrl.add_file(pseudo_image, filename='myphoto.jpg') 393 self.browser.getControl("Save").click() # submit form 394 self.assertTrue( 395 'Uploaded image is too big' in self.browser.contents) 396 359 397 def test_manage_course_lists(self): 360 398 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') … … 468 506 self.browser.open(datacenter_path) 469 507 self.browser.getLink('Upload CSV file').click() 470 filecontents = cStringIO.StringIO(open('students.csv', 'rb').read())508 filecontents = StringIO(open('students.csv', 'rb').read()) 471 509 filewidget = self.browser.getControl(name='uploadfile:file') 472 510 filewidget.add_file(filecontents, 'text/plain', 'students.csv') … … 494 532 self.browser.open(datacenter_path) 495 533 self.browser.getLink('Upload CSV file').click() 496 filecontents = cStringIO.StringIO(open('studycourses.csv', 'rb').read())534 filecontents = StringIO(open('studycourses.csv', 'rb').read()) 497 535 filewidget = self.browser.getControl(name='uploadfile:file') 498 536 filewidget.add_file(filecontents, 'text/plain', 'studycourses.csv')
Note: See TracChangeset for help on using the changeset viewer.