- Timestamp:
- 24 May 2013, 06:51:01 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.futminna/trunk/src/waeup/futminna/applicants/tests/test_browser.py
r10216 r10220 249 249 self.assertTrue(fd is None) 250 250 251 def test_upload_credentialform_by_student(self): 252 self.login() 253 self.browser.open(self.edit_path) 254 # Create a pseudo file and select it to be uploaded in form 255 pdf_content = 'A' * 1024 * 600 # A string of 600 KB size 256 pseudo_pdf = StringIO(pdf_content) 257 ctrl = self.browser.getControl(name='form.credentialform') 258 file_ctrl = ctrl.mech_control 259 file_ctrl.add_file(pseudo_pdf, filename='myform.pdf') 260 self.browser.getControl("Save").click() # submit form 261 # We get a warning message 262 self.assertTrue( 263 'Uploaded file is too big' in self.browser.contents) 264 # Create a pseudo file with acceptable size 265 pdf_content = 'A' * 1024 * 300 # A string of 300 KB size 266 pseudo_pdf = StringIO(pdf_content) 267 ctrl = self.browser.getControl(name='form.credentialform') 268 file_ctrl = ctrl.mech_control 269 file_ctrl.add_file(pseudo_pdf, filename='myform.pdf') 270 self.browser.getControl("Save").click() # submit form 271 # Even though the form could not be saved ... 272 self.assertTrue('Required input is missing' in self.browser.contents) 273 # ... the file has been successfully uploaded 274 pdf_url = self.edit_path.replace('edit', 'credentialform.pdf') 275 self.browser.open(pdf_url) 276 self.assertEqual( 277 self.browser.headers['content-type'], 'application/pdf') 278 self.assertEqual(len(self.browser.contents), 307200) 279 # There is really a file stored for the applicant 280 storage = getUtility(IExtFileStore) 281 file_id = IFileStoreNameChooser(self.applicant).chooseName( 282 attr='credentialform.pdf') 283 # The stored file can be fetched 284 fd = storage.getFile(file_id) 285 file_len = len(fd.read()) 286 self.assertEqual(file_len, 307200) 287 # A file link is displayed on the edit view ... 288 self.browser.open(self.edit_path) 289 self.assertTrue('<a href="credentialform.pdf">' in self.browser.contents) 290 # ... and on the dislay view 291 self.browser.open(self.view_path) 292 self.assertTrue('<a href="credentialform.pdf">Credential Form</a>' 293 in self.browser.contents) 294 295 def test_upload_credentialform_by_manager(self): 296 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 297 self.browser.open(self.manage_path) 298 # Create a pseudo file with acceptable size 299 pdf_content = 'A' * 1024 * 300 # A string of 300 KB size 300 pseudo_pdf = StringIO(pdf_content) 301 ctrl = self.browser.getControl(name='form.credentialform') 302 file_ctrl = ctrl.mech_control 303 file_ctrl.add_file(pseudo_pdf, filename='myform.pdf') 304 self.browser.getControl("Save").click() # submit form 305 # Even though the form could not be saved ... 306 self.assertTrue('Required input is missing' in self.browser.contents) 307 # ... the file has been successfully uploaded 308 pdf_url = self.manage_path.replace('manage', 'credentialform.pdf') 309 self.browser.open(pdf_url) 310 self.assertEqual( 311 self.browser.headers['content-type'], 'application/pdf') 312 self.assertEqual(len(self.browser.contents), 307200) 313 # There is rally a file stored for the applicant 314 storage = getUtility(IExtFileStore) 315 file_id = IFileStoreNameChooser(self.applicant).chooseName( 316 attr='credentialform.pdf') 317 # The stored file can be fetched 318 fd = storage.getFile(file_id) 319 file_len = len(fd.read()) 320 self.assertEqual(file_len, 307200) 321 # A file link is displayed on the edit view ... 322 self.browser.open(self.manage_path) 323 self.assertTrue('<a href="credentialform.pdf">' in self.browser.contents) 324 # ... and on the dislay view 325 self.browser.open(self.view_path) 326 self.assertTrue('<a href="credentialform.pdf">Credential Form</a>' 327 in self.browser.contents) 328 # Adding file is properly logged 329 logfile = os.path.join( 330 self.app['datacenter'].storage, 'logs', 'applicants.log') 331 logcontent = open(logfile).read() 332 self.assertTrue( 333 'zope.mgr - waeup.futminna.applicants.browser.CustomApplicantManageFormPage' 334 ' - %s - saved: credentialform' 335 % (self.applicant.applicant_id) 336 in logcontent) 337 # When an applicant is removed, also the pdf files are gone. 338 del self.app['applicants']['app2011'][self.applicant.application_number] 339 fd = storage.getFile(file_id) 340 self.assertTrue(fd is None) 341 251 342 def test_certificate_source(self): 252 343 # We add a second 'alternative' certificate
Note: See TracChangeset for help on using the changeset viewer.