Ignore:
Timestamp:
24 May 2013, 08:23:16 (11 years ago)
Author:
Henrik Bettermann
Message:

Credential upload is only for pg students. This requires a pg applicants container in tests.

File:
1 edited

Legend:

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

    r10220 r10224  
    2121
    2222import os
     23import pytz
    2324import grok
     25from datetime import datetime, date, timedelta
    2426from zope.event import notify
    2527from StringIO import StringIO
    2628from zope.component import createObject, getUtility
     29from waeup.kofa.applicants.container import ApplicantsContainer
    2730from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
    2831from waeup.kofa.interfaces import (
     
    249252        self.assertTrue(fd is None)
    250253
    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 
    295254    def test_upload_credentialform_by_manager(self):
    296255        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     
    299258        pdf_content = 'A' * 1024 * 300  # A string of 300 KB size
    300259        pseudo_pdf = StringIO(pdf_content)
     260        # This is a ug applicant, thus the credential form is not
     261        # required
     262        self.assertFalse('credentialform">' 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)
    301290        ctrl = self.browser.getControl(name='form.credentialform')
    302291        file_ctrl = ctrl.mech_control
     
    306295        self.assertTrue('Required input is missing' in self.browser.contents)
    307296        # ... the file has been successfully uploaded
    308         pdf_url = self.manage_path.replace('manage', 'credentialform.pdf')
     297        pdf_url = self.manage_path_pg.replace('manage', 'credentialform.pdf')
    309298        self.browser.open(pdf_url)
    310299        self.assertEqual(
     
    313302        # There is rally a file stored for the applicant
    314303        storage = getUtility(IExtFileStore)
    315         file_id = IFileStoreNameChooser(self.applicant).chooseName(
     304        file_id = IFileStoreNameChooser(applicant).chooseName(
    316305            attr='credentialform.pdf')
    317306        # The stored file can be fetched
     
    320309        self.assertEqual(file_len, 307200)
    321310        # A file link is displayed on the edit view ...
    322         self.browser.open(self.manage_path)
     311        self.browser.open(self.manage_path_pg)
    323312        self.assertTrue('<a href="credentialform.pdf">' in self.browser.contents)
    324313        # ... and on the dislay view
    325         self.browser.open(self.view_path)
     314        self.browser.open(self.view_path_pg)
    326315        self.assertTrue('<a href="credentialform.pdf">Credential Form</a>'
    327316            in self.browser.contents)
     
    333322            'zope.mgr - waeup.futminna.applicants.browser.CustomApplicantManageFormPage'
    334323            ' - %s - saved: credentialform'
    335             % (self.applicant.applicant_id)
     324            % (applicant.applicant_id)
    336325            in logcontent)
    337326        # When an applicant is removed, also the pdf files are gone.
    338         del self.app['applicants']['app2011'][self.applicant.application_number]
     327        del self.app['applicants'][container_name][applicant.application_number]
    339328        fd = storage.getFile(file_id)
    340329        self.assertTrue(fd is None)
Note: See TracChangeset for help on using the changeset viewer.