- Timestamp:
- 25 Jun 2013, 12:46:38 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.imostate/trunk/src/waeup/imostate/applicants/tests/test_browser.py
r10366 r10382 161 161 self.assertTrue(fd is None) 162 162 163 def test_upload_refereeform_by_student(self):164 self.login()165 self.browser.open(self.edit_path)166 # Create a pseudo file and select it to be uploaded in form167 pdf_content = 'A' * 1024 * 600 # A string of 600 KB size168 pseudo_file = StringIO(pdf_content)169 ctrl = self.browser.getControl(name='form.refereeform')170 file_ctrl = ctrl.mech_control171 file_ctrl.add_file(pseudo_file, filename='myform.pdf')172 self.browser.getControl("Save").click() # submit form173 # We get a warning message174 self.assertTrue(175 'Uploaded file is too big' in self.browser.contents)176 # Create a pseudo file with acceptable size177 pdf_content = 'A' * 1024 * 300 # A string of 300 KB size178 pseudo_file = StringIO(pdf_content)179 ctrl = self.browser.getControl(name='form.refereeform')180 file_ctrl = ctrl.mech_control181 file_ctrl.add_file(pseudo_file, filename='myform.pdf')182 self.browser.getControl("Save").click() # submit form183 # Even though the form could not be saved ...184 self.assertTrue('Required input is missing' in self.browser.contents)185 # ... the file has been successfully uploaded186 pdf_url = self.edit_path.replace('edit', 'refereeform.pdf')187 self.browser.open(pdf_url)188 self.assertEqual(189 self.browser.headers['content-type'], 'application/pdf')190 self.assertEqual(len(self.browser.contents), 307200)191 # There is really a file stored for the applicant192 storage = getUtility(IExtFileStore)193 file_id = IFileStoreNameChooser(self.applicant).chooseName(194 attr='refereeform.pdf')195 # The stored file can be fetched196 fd = storage.getFile(file_id)197 file_len = len(fd.read())198 self.assertEqual(file_len, 307200)199 # A file link is displayed on the edit view ...200 self.browser.open(self.edit_path)201 self.assertTrue('<a href="refereeform.pdf">' in self.browser.contents)202 # ... and on the dislay view203 self.browser.open(self.view_path)204 self.assertTrue('<a href="refereeform.pdf">Referee\'s Form</a>'205 in self.browser.contents)206 207 def test_upload_refereeform_by_manager(self):208 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')209 self.browser.open(self.manage_path)210 # Create a pseudo file with acceptable size211 pdf_content = 'A' * 1024 * 300 # A string of 300 KB size212 pseudo_file = StringIO(pdf_content)213 ctrl = self.browser.getControl(name='form.refereeform')214 file_ctrl = ctrl.mech_control215 file_ctrl.add_file(pseudo_file, filename='myform.pdf')216 self.browser.getControl("Save").click() # submit form217 # Even though the form could not be saved ...218 self.assertTrue('Required input is missing' in self.browser.contents)219 # ... the file has been successfully uploaded220 pdf_url = self.manage_path.replace('manage', 'refereeform.pdf')221 self.browser.open(pdf_url)222 self.assertEqual(223 self.browser.headers['content-type'], 'application/pdf')224 self.assertEqual(len(self.browser.contents), 307200)225 # There is rally a file stored for the applicant226 storage = getUtility(IExtFileStore)227 file_id = IFileStoreNameChooser(self.applicant).chooseName(228 attr='refereeform.pdf')229 # The stored file can be fetched230 fd = storage.getFile(file_id)231 file_len = len(fd.read())232 self.assertEqual(file_len, 307200)233 # A file link is displayed on the edit view ...234 self.browser.open(self.manage_path)235 self.assertTrue('<a href="refereeform.pdf">' in self.browser.contents)236 # ... and on the dislay view237 self.browser.open(self.view_path)238 self.assertTrue('<a href="refereeform.pdf">Referee\'s Form</a>'239 in self.browser.contents)240 # Adding file is properly logged241 logfile = os.path.join(242 self.app['datacenter'].storage, 'logs', 'applicants.log')243 logcontent = open(logfile).read()244 self.assertTrue(245 'zope.mgr - waeup.imostate.applicants.browser.CustomApplicantManageFormPage'246 ' - %s - saved: refereeform'247 % (self.applicant.applicant_id)248 in logcontent)249 # When an applicant is removed, also the pdf files are gone.250 del self.app['applicants']['app2011'][self.applicant.application_number]251 fd = storage.getFile(file_id)252 self.assertTrue(fd is None)253 254 163 def test_applicant_workflow(self): 255 164 # Applicants can edit their record … … 275 184 file_ctrl = ctrl.mech_control 276 185 file_ctrl.add_file(pseudo_file, filename='myform.pdf') 277 ctrl = self.browser.getControl(name='form.refereeform')278 file_ctrl = ctrl.mech_control279 file_ctrl.add_file(pseudo_file, filename='myform.pdf')280 186 281 187 self.browser.getControl(name="confirm_passport").value = True
Note: See TracChangeset for help on using the changeset viewer.