Changeset 10366 for main/waeup.imostate


Ignore:
Timestamp:
23 Jun 2013, 20:00:56 (11 years ago)
Author:
Henrik Bettermann
Message:

Add workflow test.

Location:
main/waeup.imostate/src/waeup/imostate/applicants
Files:
2 edited

Legend:

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

    r10350 r10366  
    7575        # Create a pseudo file and select it to be uploaded in form
    7676        pdf_content = 'A' * 1024 * 600  # A string of 600 KB size
    77         pseudo_pdf = StringIO(pdf_content)
    78         ctrl = self.browser.getControl(name='form.extraform')
    79         file_ctrl = ctrl.mech_control
    80         file_ctrl.add_file(pseudo_pdf, filename='myform.pdf')
     77        pseudo_file = StringIO(pdf_content)
     78        ctrl = self.browser.getControl(name='form.extraform')
     79        file_ctrl = ctrl.mech_control
     80        file_ctrl.add_file(pseudo_file, filename='myform.pdf')
    8181        self.browser.getControl("Save").click() # submit form
    8282        # We get a warning message
     
    8585        # Create a pseudo file with acceptable size
    8686        pdf_content = 'A' * 1024 * 300  # A string of 300 KB size
    87         pseudo_pdf = StringIO(pdf_content)
    88         ctrl = self.browser.getControl(name='form.extraform')
    89         file_ctrl = ctrl.mech_control
    90         file_ctrl.add_file(pseudo_pdf, filename='myform.pdf')
     87        pseudo_file = StringIO(pdf_content)
     88        ctrl = self.browser.getControl(name='form.extraform')
     89        file_ctrl = ctrl.mech_control
     90        file_ctrl.add_file(pseudo_file, filename='myform.pdf')
    9191        self.browser.getControl("Save").click() # submit form
    9292        # Even though the form could not be saved ...
     
    119119        # Create a pseudo file with acceptable size
    120120        pdf_content = 'A' * 1024 * 300  # A string of 300 KB size
    121         pseudo_pdf = StringIO(pdf_content)
    122         ctrl = self.browser.getControl(name='form.extraform')
    123         file_ctrl = ctrl.mech_control
    124         file_ctrl.add_file(pseudo_pdf, filename='myform.pdf')
     121        pseudo_file = StringIO(pdf_content)
     122        ctrl = self.browser.getControl(name='form.extraform')
     123        file_ctrl = ctrl.mech_control
     124        file_ctrl.add_file(pseudo_file, filename='myform.pdf')
    125125        self.browser.getControl("Save").click() # submit form
    126126        # Even though the form could not be saved ...
     
    166166        # Create a pseudo file and select it to be uploaded in form
    167167        pdf_content = 'A' * 1024 * 600  # A string of 600 KB size
    168         pseudo_pdf = StringIO(pdf_content)
    169         ctrl = self.browser.getControl(name='form.refereeform')
    170         file_ctrl = ctrl.mech_control
    171         file_ctrl.add_file(pseudo_pdf, filename='myform.pdf')
     168        pseudo_file = StringIO(pdf_content)
     169        ctrl = self.browser.getControl(name='form.refereeform')
     170        file_ctrl = ctrl.mech_control
     171        file_ctrl.add_file(pseudo_file, filename='myform.pdf')
    172172        self.browser.getControl("Save").click() # submit form
    173173        # We get a warning message
     
    176176        # Create a pseudo file with acceptable size
    177177        pdf_content = 'A' * 1024 * 300  # A string of 300 KB size
    178         pseudo_pdf = StringIO(pdf_content)
    179         ctrl = self.browser.getControl(name='form.refereeform')
    180         file_ctrl = ctrl.mech_control
    181         file_ctrl.add_file(pseudo_pdf, filename='myform.pdf')
     178        pseudo_file = StringIO(pdf_content)
     179        ctrl = self.browser.getControl(name='form.refereeform')
     180        file_ctrl = ctrl.mech_control
     181        file_ctrl.add_file(pseudo_file, filename='myform.pdf')
    182182        self.browser.getControl("Save").click() # submit form
    183183        # Even though the form could not be saved ...
     
    210210        # Create a pseudo file with acceptable size
    211211        pdf_content = 'A' * 1024 * 300  # A string of 300 KB size
    212         pseudo_pdf = StringIO(pdf_content)
    213         ctrl = self.browser.getControl(name='form.refereeform')
    214         file_ctrl = ctrl.mech_control
    215         file_ctrl.add_file(pseudo_pdf, filename='myform.pdf')
     212        pseudo_file = StringIO(pdf_content)
     213        ctrl = self.browser.getControl(name='form.refereeform')
     214        file_ctrl = ctrl.mech_control
     215        file_ctrl.add_file(pseudo_file, filename='myform.pdf')
    216216        self.browser.getControl("Save").click() # submit form
    217217        # Even though the form could not be saved ...
     
    252252        self.assertTrue(fd is None)
    253253
    254     def test_upload_credentials_by_manager(self):
    255         self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    256         self.browser.open(self.manage_path)
    257         # Create a pseudo file with acceptable size
    258         pdf_content = 'A' * 1024 * 300  # A string of 300 KB size
    259         pseudo_pdf = StringIO(pdf_content)
    260         # This is a ug applicant, thus the credentials is not
    261         # required
    262         self.assertFalse('credentials">' in self.browser.contents)
    263 
    264         # We have to add a pg applicants container
    265         container_name = u'pg%s' % (datetime.now().year - 1)
    266         applicantscontainer = ApplicantsContainer()
    267         applicantscontainer.code = container_name
    268         applicantscontainer.prefix = 'pgft'
    269         applicantscontainer.year = datetime.now().year - 1
    270         applicantscontainer.title = u'This is the %s container' % container_name
    271         applicantscontainer.application_category = 'pg_ft'
    272         applicantscontainer.mode = 'create'
    273         applicantscontainer.strict_deadline = True
    274         delta = timedelta(days=10)
    275         applicantscontainer.startdate = datetime.now(pytz.utc) - delta
    276         applicantscontainer.enddate = datetime.now(pytz.utc) + delta
    277         self.app['applicants'][container_name] = applicantscontainer
    278         applicant = createObject('waeup.Applicant')
    279         # reg_number is the only field which has to be preset here
    280         # because managers are allowed to edit this required field
    281         applicant.reg_number = u'2345'
    282         applicant.course1 = self.certificate
    283         self.app['applicants'][container_name].addApplicant(applicant)
    284         self.manage_path_pg = 'http://localhost/app/applicants/%s/%s/%s' % (
    285             container_name, applicant.application_number, 'manage')
    286         self.view_path_pg = 'http://localhost/app/applicants/%s/%s' % (
    287             container_name, applicant.application_number)
    288 
    289         self.browser.open(self.manage_path_pg)
    290         ctrl = self.browser.getControl(name='form.credentials')
    291         file_ctrl = ctrl.mech_control
    292         file_ctrl.add_file(pseudo_pdf, filename='myform.pdf')
    293         self.browser.getControl("Save").click() # submit form
    294         # Even though the form could not be saved ...
    295         self.assertTrue('Required input is missing' in self.browser.contents)
    296         # ... the file has been successfully uploaded
    297         pdf_url = self.manage_path_pg.replace('manage', 'credentials.pdf')
    298         self.browser.open(pdf_url)
    299         self.assertEqual(
    300             self.browser.headers['content-type'], 'application/pdf')
    301         self.assertEqual(len(self.browser.contents), 307200)
    302         # There is rally a file stored for the applicant
    303         storage = getUtility(IExtFileStore)
    304         file_id = IFileStoreNameChooser(applicant).chooseName(
    305             attr='credentials.pdf')
    306         # The stored file can be fetched
    307         fd = storage.getFile(file_id)
    308         file_len = len(fd.read())
    309         self.assertEqual(file_len, 307200)
    310         # A file link is displayed on the edit view ...
    311         self.browser.open(self.manage_path_pg)
    312         self.assertTrue('<a href="credentials.pdf">' in self.browser.contents)
    313         # ... and on the dislay view
    314         self.browser.open(self.view_path_pg)
    315         self.assertTrue('<a href="credentials.pdf">Credentials</a>'
    316             in self.browser.contents)
    317         # Adding file is properly logged
    318         logfile = os.path.join(
    319             self.app['datacenter'].storage, 'logs', 'applicants.log')
    320         logcontent = open(logfile).read()
    321         self.assertTrue(
    322             'zope.mgr - waeup.imostate.applicants.browser.CustomApplicantManageFormPage'
    323             ' - %s - saved: credentials'
    324             % (applicant.applicant_id)
    325             in logcontent)
    326         # When an applicant is removed, also the pdf files are gone.
    327         del self.app['applicants'][container_name][applicant.application_number]
    328         fd = storage.getFile(file_id)
    329         self.assertTrue(fd is None)
     254    def test_applicant_workflow(self):
     255        # Applicants can edit their record
     256        self.browser.open(self.login_path)
     257        self.login()
     258        self.assertTrue(
     259            'You logged in.' in self.browser.contents)
     260        self.browser.open(self.edit_path)
     261        self.assertTrue(self.browser.url != self.login_path)
     262        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     263        self.fill_correct_values()
     264        self.browser.getControl(name="form.nationality").value = ['NG']
     265        self.browser.getControl("Save").click()
     266        self.assertTrue('Form has been saved' in self.browser.contents)
     267        self.assertTrue('started ' in self.browser.contents)
     268
     269        pdf_content = 'A' * 1024 * 300  # A string of 300 KB size
     270        pseudo_file = StringIO(pdf_content)
     271        ctrl = self.browser.getControl(name='form.passport')
     272        file_ctrl = ctrl.mech_control
     273        file_ctrl.add_file(pseudo_file, filename='myphoto.jpg')
     274        ctrl = self.browser.getControl(name='form.extraform')
     275        file_ctrl = ctrl.mech_control
     276        file_ctrl.add_file(pseudo_file, filename='myform.pdf')
     277        ctrl = self.browser.getControl(name='form.refereeform')
     278        file_ctrl = ctrl.mech_control
     279        file_ctrl.add_file(pseudo_file, filename='myform.pdf')
     280
     281        self.browser.getControl(name="confirm_passport").value = True
     282        self.browser.getControl("Save").click()
     283        return
  • main/waeup.imostate/src/waeup/imostate/applicants/utils.py

    r10354 r10366  
    3737    APP_TYPES_DICT = {
    3838        'ymwp': ['Youths Must Work Programme', 'YMWP'],
     39        'app': ['General Studies', 'APP'],
    3940        }
Note: See TracChangeset for help on using the changeset viewer.