Changeset 8467 for main/waeup.kofa/trunk/src/waeup/kofa/students/tests
- Timestamp:
- 18 May 2012, 00:13:37 (12 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/students/tests
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py
r8436 r8467 26 26 import grok 27 27 from zope.event import notify 28 from zope.component import createObject, queryUtility , getUtility28 from zope.component import createObject, queryUtility 29 29 from zope.component.hooks import setSite, clearSite 30 30 from zope.catalog.interfaces import ICatalog … … 35 35 from waeup.kofa.testing import FunctionalLayer, FunctionalTestCase 36 36 from waeup.kofa.app import University 37 from waeup.kofa.configuration import SessionConfiguration38 37 from waeup.kofa.students.student import Student 39 38 from waeup.kofa.students.studylevel import StudentStudyLevel 40 39 from waeup.kofa.university.faculty import Faculty 41 40 from waeup.kofa.university.department import Department 42 from waeup.kofa.interfaces import IUserAccount , IKofaUtils41 from waeup.kofa.interfaces import IUserAccount 43 42 from waeup.kofa.authentication import LocalRoleSetEvent 44 43 from waeup.kofa.hostels.hostel import Hostel, Bed, NOT_OCCUPIED 45 44 46 45 PH_LEN = 2059 # Length of placeholder file 46 47 SAMPLE_IMAGE = os.path.join(os.path.dirname(__file__), 'test_image.jpg') 48 SAMPLE_IMAGE_BMP = os.path.join(os.path.dirname(__file__), 'test_image.bmp') 47 49 48 50 def lookup_submit_value(name, value, browser): … … 522 524 # as birth certificate 523 525 self.browser.open(self.manage_clearance_path) 524 pseudo_image = StringIO('I pretend to be a graphics file')526 image = open(SAMPLE_IMAGE, 'rb') 525 527 ctrl = self.browser.getControl(name='birthcertificateupload') 526 528 file_ctrl = ctrl.mech_control 527 file_ctrl.add_file( pseudo_image, filename='my_birth_certificate.jpg')529 file_ctrl.add_file(image, filename='my_birth_certificate.jpg') 528 530 # The Save action does not upload files 529 531 self.browser.getControl("Save").click() # submit form … … 532 534 in self.browser.contents) 533 535 # ... but the correct upload submit button does 534 pseudo_image = StringIO('I pretend to be a graphics file')536 image = open(SAMPLE_IMAGE) 535 537 ctrl = self.browser.getControl(name='birthcertificateupload') 536 538 file_ctrl = ctrl.mech_control 537 file_ctrl.add_file( pseudo_image, filename='my_birth_certificate.jpg')539 file_ctrl.add_file(image, filename='my_birth_certificate.jpg') 538 540 self.browser.getControl( 539 541 name='upload_birthcertificateupload').click() … … 546 548 self.assertEqual( 547 549 self.browser.headers['content-type'], 'image/jpeg') 548 self.assertEqual(len(self.browser.contents), 31)550 self.assertEqual(len(self.browser.contents), 2787) 549 551 # Reuploading a file which is bigger than 150k will raise an error 550 552 self.browser.open(self.manage_clearance_path) 551 photo_content = 'A' * 1024 * 151 # A string of 21 KB size552 pseudo_image = StringIO(photo_content)553 # An image > 150K 554 big_image = StringIO(open(SAMPLE_IMAGE, 'rb').read() * 75) 553 555 ctrl = self.browser.getControl(name='birthcertificateupload') 554 556 file_ctrl = ctrl.mech_control 555 file_ctrl.add_file( pseudo_image, filename='my_birth_certificate.jpg')557 file_ctrl.add_file(big_image, filename='my_birth_certificate.jpg') 556 558 self.browser.getControl( 557 559 name='upload_birthcertificateupload').click() 558 560 self.assertTrue( 559 561 'Uploaded file is too big' in self.browser.contents) 560 # File names must meet several conditions561 pseudo_image = StringIO('I pretend to be a graphics file')562 # we do not rely on filename extensions given by uploaders 563 image = open(SAMPLE_IMAGE, 'rb') # a jpg-file 562 564 ctrl = self.browser.getControl(name='birthcertificateupload') 563 565 file_ctrl = ctrl.mech_control 564 file_ctrl.add_file(pseudo_image, filename='my.photo.jpg') 566 # tell uploaded file is bmp 567 file_ctrl.add_file(image, filename='my_birth_certificate.bmp') 565 568 self.browser.getControl( 566 569 name='upload_birthcertificateupload').click() 567 self.assertTrue('File name contains more than one dot' 568 in self.browser.contents) 570 self.assertTrue( 571 # jpg file was recognized 572 'File birth_certificate.jpg uploaded.' in self.browser.contents) 573 # File names must meet several conditions 574 bmp_image = open(SAMPLE_IMAGE_BMP, 'rb') 569 575 ctrl = self.browser.getControl(name='birthcertificateupload') 570 576 file_ctrl = ctrl.mech_control 571 file_ctrl.add_file(pseudo_image, filename='my_birth_certificate') 572 self.browser.getControl( 573 name='upload_birthcertificateupload').click() 574 self.assertTrue('File name has no extension' in self.browser.contents) 575 ctrl = self.browser.getControl(name='birthcertificateupload') 576 file_ctrl = ctrl.mech_control 577 file_ctrl.add_file(pseudo_image, filename='my_birth_certificate.bmp') 577 file_ctrl.add_file(bmp_image, filename='my_birth_certificate.bmp') 578 578 self.browser.getControl( 579 579 name='upload_birthcertificateupload').click() … … 586 586 # Managers can add and delete second file 587 587 self.browser.open(self.manage_clearance_path) 588 pseudo_image = StringIO('I pretend to be a graphics file')588 image = open(SAMPLE_IMAGE, 'rb') 589 589 ctrl = self.browser.getControl(name='birthcertificateupload') 590 590 file_ctrl = ctrl.mech_control 591 file_ctrl.add_file( pseudo_image, filename='my_acceptance_letter.jpg')591 file_ctrl.add_file(image, filename='my_acceptance_letter.jpg') 592 592 self.browser.getControl( 593 593 name='upload_acceptanceletterupload').click() … … 597 597 ctrl = self.browser.getControl(name='acceptanceletterupload') 598 598 file_ctrl = ctrl.mech_control 599 file_ctrl.add_file(pseudo_image, filename='my_acceptance_letter.jpg') 599 image.seek(0) 600 file_ctrl.add_file(image, filename='my_acceptance_letter.jpg') 600 601 self.browser.getControl( 601 602 name='upload_acceptanceletterupload').click() … … 610 611 # Managers can upload a file via the StudentBaseManageFormPage 611 612 self.browser.open(self.manage_student_path) 612 pseudo_image = StringIO('I pretend to be a graphics file')613 image = open(SAMPLE_IMAGE_BMP, 'rb') 613 614 ctrl = self.browser.getControl(name='passportuploadmanage') 614 615 file_ctrl = ctrl.mech_control 615 file_ctrl.add_file( pseudo_image, filename='my_photo.bmp')616 file_ctrl.add_file(image, filename='my_photo.bmp') 616 617 self.browser.getControl( 617 618 name='upload_passportuploadmanage').click() … … 620 621 ctrl = self.browser.getControl(name='passportuploadmanage') 621 622 file_ctrl = ctrl.mech_control 622 file_ctrl.add_file(pseudo_image, filename='my_photo.jpg') 623 image = open(SAMPLE_IMAGE, 'rb') 624 file_ctrl.add_file(image, filename='my_photo.jpg') 623 625 self.browser.getControl( 624 626 name='upload_passportuploadmanage').click() … … 631 633 self.browser.open(self.student_path + '/clearance.pdf') 632 634 self.assertEqual(self.browser.headers['Status'], '200 Ok') 633 self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf') 635 self.assertEqual(self.browser.headers['Content-Type'], 636 'application/pdf') 634 637 635 638 def test_manage_course_lists(self): … … 1426 1429 IWorkflowInfo(self.student).fireTransition('admit') 1427 1430 self.browser.open(self.student_path + '/change_portrait') 1428 pseudo_image = StringIO('I pretend to be a graphics file')1431 image = open(SAMPLE_IMAGE, 'rb') 1429 1432 ctrl = self.browser.getControl(name='passportuploadedit') 1430 1433 file_ctrl = ctrl.mech_control 1431 file_ctrl.add_file( pseudo_image, filename='my_photo.jpg')1434 file_ctrl.add_file(image, filename='my_photo.jpg') 1432 1435 self.browser.getControl( 1433 1436 name='upload_passportuploadedit').click() -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_student.py
r8452 r8467 130 130 131 131 def create_passport_img(self, student): 132 # create some fakedpassport file for `student`132 # create some passport file for `student` 133 133 storage = getUtility(IExtFileStore) 134 image_path = os.path.join(os.path.dirname(__file__), 'test_image.jpg') 135 self.image_contents = open(image_path, 'rb').read() 134 136 file_id = IFileStoreNameChooser(student).chooseName( 135 137 attr='passport.jpg') 136 storage.createFile(file_id, StringIO( 'I am a fake image.'))138 storage.createFile(file_id, StringIO(self.image_contents)) 137 139 138 140 def test_backup_single_student_data(self): … … 144 146 del_dir = self.app['datacenter'].deleted_path 145 147 del_img_path = os.path.join( 146 del_dir, 'media', 'students', '0011 1', 'A111111',148 del_dir, 'media', 'students', '00110', 'A111111', 147 149 'passport_A111111.jpg') 148 150 … … 151 153 self.assertEqual( 152 154 open(del_img_path, 'rb').read(), 153 'I am a fake image.')155 self.image_contents) 154 156 155 157 # The student data were put into CSV files
Note: See TracChangeset for help on using the changeset viewer.