Ignore:
Timestamp:
31 Jul 2019, 10:49:59 (5 years ago)
Author:
Henrik Bettermann
Message:

Implement Verification of Result/Transcript? and Certificate application form.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.aaue/trunk/src/waeup/aaue/applicants/tests/test_browser.py

    r15462 r15530  
    381381        fd = storage.getFile(file_id)
    382382        self.assertTrue(fd is None)
     383
     384    def test_upload_verificationdoc_by_manager(self):
     385        # Add ver applicants container
     386        self.vercontainer = ApplicantsContainer()
     387        self.vercontainer.mode = 'create'
     388        self.vercontainer.code = u'ver%s' % session_1
     389        self.vercontainer.prefix = u'ver'
     390        self.vercontainer.application_category = u'no'
     391        self.vercontainer.year = session_1
     392        self.vercontainer.application_fee = 300.0
     393        self.vercontainer.title = u'This is the ver%s container' % session_1
     394        self.app['applicants'][self.vercontainer.code] = self.vercontainer
     395        delta = datetime.timedelta(days=10)
     396        self.vercontainer.startdate = datetime.datetime.now(pytz.utc) - delta
     397        self.vercontainer.enddate = datetime.datetime.now(pytz.utc) + delta
     398        # Add applicant
     399        verapplicant = createObject(u'waeup.Applicant')
     400        verapplicant.firstname = u'Anna'
     401        verapplicant.lastname = u'Post'
     402        self.app['applicants'][self.vercontainer.code].addApplicant(verapplicant)
     403        self.verapplicant = self.app['applicants'][self.vercontainer.code][
     404            verapplicant.application_number]
     405        self.verapplicant_view_path = ('http://localhost/app/applicants/ver%s/%s'
     406            % (session_1, verapplicant.application_number))
     407        self.verapplicant_manage_path = ('http://localhost/app/applicants/ver%s/%s/manage'
     408            % (session_1, verapplicant.application_number))
     409        # Login
     410        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     411        self.browser.open(self.verapplicant_manage_path)
     412        # Create a pseudo file with acceptable size
     413        pdf_content = 'A' * 1024 * 300  # A string of 300 KB size
     414        pseudo_pdf = StringIO(pdf_content)
     415        ctrl = self.browser.getControl(name='form.verificationdoc')
     416        file_ctrl = ctrl.mech_control
     417        file_ctrl.add_file(pseudo_pdf, filename='myform.pdf')
     418        self.browser.getControl("Save").click() # submit form
     419        # Even though the form could not be saved ...
     420        self.assertTrue('Required input is missing' in self.browser.contents)
     421        # ... the file has been successfully uploaded
     422        pdf_url = self.verapplicant_manage_path.replace('manage', 'verificationdoc.pdf')
     423        self.browser.open(pdf_url)
     424        self.assertEqual(
     425            self.browser.headers['content-type'], 'application/pdf')
     426        self.assertEqual(len(self.browser.contents), 307200)
     427        # There is really a file stored for the applicant
     428        storage = getUtility(IExtFileStore)
     429        file_id = IFileStoreNameChooser(self.verapplicant).chooseName(
     430            attr='verificationdoc.pdf')
     431        # The stored file can be fetched
     432        fd = storage.getFile(file_id)
     433        file_len = len(fd.read())
     434        self.assertEqual(file_len, 307200)
     435        # A file link is displayed on the edit view ...
     436        self.browser.open(self.verapplicant_manage_path)
     437        self.assertTrue('<a href="verificationdoc.pdf">' in self.browser.contents)
     438        # ... and on the dislay view
     439        self.browser.open(self.verapplicant_view_path)
     440        self.assertTrue('<a href="verificationdoc.pdf">Result/Certificate Document</a>'
     441            in self.browser.contents)
     442        # Adding file is properly logged
     443        logfile = os.path.join(
     444            self.app['datacenter'].storage, 'logs', 'applicants.log')
     445        logcontent = open(logfile).read()
     446        self.assertTrue(
     447            'zope.mgr - waeup.aaue.applicants.browser.CustomApplicantManageFormPage'
     448            ' - %s - saved: verificationdoc'
     449            % (self.verapplicant.applicant_id)
     450            in logcontent)
     451        # When an applicant is removed, also the pdf files are gone.
     452        del self.app['applicants'][self.vercontainer.code][self.verapplicant.application_number]
     453        fd = storage.getFile(file_id)
     454        self.assertTrue(fd is None)
Note: See TracChangeset for help on using the changeset viewer.