Changeset 15113 for main/waeup.aaue/trunk/src/waeup/aaue/applicants/tests
- Timestamp:
- 23 Aug 2018, 06:43:06 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.aaue/trunk/src/waeup/aaue/applicants/tests/test_browser.py
r15099 r15113 20 20 import pytz 21 21 import os 22 from StringIO import StringIO 22 23 from zope.event import notify 23 24 from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState 24 25 from zope.component import createObject, getUtility 25 26 from waeup.kofa.configuration import SessionConfiguration 26 from waeup.kofa.interfaces import IUserAccount 27 from waeup.kofa.interfaces import ( 28 IUserAccount, IExtFileStore, IFileStoreNameChooser) 27 29 from waeup.kofa.applicants.container import ApplicantsContainer 28 30 from waeup.kofa.browser.tests.test_pdf import samples_dir … … 285 287 self.assertFalse('Admitted Course of Study' in self.browser.contents) 286 288 return 289 290 def test_upload_stateresult_by_manager(self): 291 # Add trans applicants container 292 self.transcontainer = ApplicantsContainer() 293 self.transcontainer.mode = 'create' 294 self.transcontainer.code = u'trans%s' % session_1 295 self.transcontainer.prefix = u'trans' 296 self.transcontainer.application_category = u'no' 297 self.transcontainer.year = session_1 298 self.transcontainer.application_fee = 300.0 299 self.transcontainer.title = u'This is the trans%s container' % session_1 300 self.app['applicants'][self.transcontainer.code] = self.transcontainer 301 delta = datetime.timedelta(days=10) 302 self.transcontainer.startdate = datetime.datetime.now(pytz.utc) - delta 303 self.transcontainer.enddate = datetime.datetime.now(pytz.utc) + delta 304 # Add applicant 305 transapplicant = createObject(u'waeup.Applicant') 306 transapplicant.firstname = u'Anna' 307 transapplicant.lastname = u'Post' 308 self.app['applicants'][self.transcontainer.code].addApplicant(transapplicant) 309 self.transapplicant = self.app['applicants'][self.transcontainer.code][ 310 transapplicant.application_number] 311 self.transapplicant_view_path = ('http://localhost/app/applicants/trans%s/%s' 312 % (session_1, transapplicant.application_number)) 313 self.transapplicant_manage_path = ('http://localhost/app/applicants/trans%s/%s/manage' 314 % (session_1, transapplicant.application_number)) 315 # Login 316 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 317 self.browser.open(self.transapplicant_manage_path) 318 # Create a pseudo file with acceptable size 319 pdf_content = 'A' * 1024 * 300 # A string of 300 KB size 320 pseudo_pdf = StringIO(pdf_content) 321 ctrl = self.browser.getControl(name='form.stateresult') 322 file_ctrl = ctrl.mech_control 323 file_ctrl.add_file(pseudo_pdf, filename='myform.pdf') 324 self.browser.getControl("Save").click() # submit form 325 # Even though the form could not be saved ... 326 self.assertTrue('Required input is missing' in self.browser.contents) 327 # ... the file has been successfully uploaded 328 pdf_url = self.transapplicant_manage_path.replace('manage', 'stateresult.pdf') 329 self.browser.open(pdf_url) 330 self.assertEqual( 331 self.browser.headers['content-type'], 'application/pdf') 332 self.assertEqual(len(self.browser.contents), 307200) 333 # There is really a file stored for the applicant 334 storage = getUtility(IExtFileStore) 335 file_id = IFileStoreNameChooser(self.transapplicant).chooseName( 336 attr='stateresult.pdf') 337 # The stored file can be fetched 338 fd = storage.getFile(file_id) 339 file_len = len(fd.read()) 340 self.assertEqual(file_len, 307200) 341 # A file link is displayed on the edit view ... 342 self.browser.open(self.transapplicant_manage_path) 343 self.assertTrue('<a href="stateresult.pdf">' in self.browser.contents) 344 # ... and on the dislay view 345 self.browser.open(self.transapplicant_view_path) 346 self.assertTrue('<a href="stateresult.pdf">Statement of Result</a>' 347 in self.browser.contents) 348 # Adding file is properly logged 349 logfile = os.path.join( 350 self.app['datacenter'].storage, 'logs', 'applicants.log') 351 logcontent = open(logfile).read() 352 self.assertTrue( 353 'zope.mgr - waeup.aaue.applicants.browser.CustomApplicantManageFormPage' 354 ' - %s - saved: stateresult' 355 % (self.transapplicant.applicant_id) 356 in logcontent) 357 # When an applicant is removed, also the pdf files are gone. 358 del self.app['applicants'][self.transcontainer.code][self.transapplicant.application_number] 359 fd = storage.getFile(file_id) 360 self.assertTrue(fd is None)
Note: See TracChangeset for help on using the changeset viewer.