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.

Location:
main/waeup.futminna/trunk/src/waeup/futminna/applicants
Files:
3 edited

Legend:

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

    r10220 r10224  
    3838    PG_OMIT_PDF_FIELDS,
    3939    PG_OMIT_MANAGE_FIELDS,
     40    PG_OMIT_EDIT_FIELDS,
    4041    PUTME_OMIT_EDIT_FIELDS,
    4142    PUTME_OMIT_DISPLAY_FIELDS,
     
    101102    @property
    102103    def form_fields(self):
    103         target = getattr(self.context.__parent__, 'prefix', None)
    104         if target is not None and target.startswith('pg'):
     104        if self.target is not None and self.target.startswith('pg'):
    105105            form_fields = grok.AutoFields(ICustomPGApplicant)
    106106            for field in PG_OMIT_DISPLAY_FIELDS:
     
    136136    @property
    137137    def form_fields(self):
    138         target = getattr(self.context.__parent__, 'prefix', None)
    139         if target is not None and target.startswith('pg'):
     138        if self.target is not None and self.target.startswith('pg'):
    140139            form_fields = grok.AutoFields(ICustomPGApplicant)
    141140            for field in PG_OMIT_PDF_FIELDS:
    142141                form_fields = form_fields.omit(field)
    143         elif target is not None and target.startswith('putme'):
     142        elif self.target is not None and self.target.startswith('putme'):
    144143            form_fields = grok.AutoFields(ICustomUGApplicant)
    145144            if self._reduced_slip():
     
    169168    @property
    170169    def form_fields(self):
    171         target = getattr(self.context.__parent__, 'prefix', None)
    172         if target is not None and target.startswith('pg'):
     170        if self.target is not None and self.target.startswith('pg'):
    173171            form_fields = grok.AutoFields(ICustomPGApplicant)
    174172            for field in PG_OMIT_MANAGE_FIELDS:
    175173                form_fields = form_fields.omit(field)
    176         elif target is not None and target.startswith('putme'):
     174        elif self.target is not None and self.target.startswith('putme'):
    177175            form_fields = grok.AutoFields(ICustomUGApplicant)
    178176            for field in PUTME_OMIT_MANAGE_FIELDS:
     
    225223    @property
    226224    def form_fields(self):
    227         target = getattr(self.context.__parent__, 'prefix', None)
    228         if target is not None and target.startswith('pg'):
     225        if self.target is not None and self.target.startswith('pg'):
    229226            form_fields = grok.AutoFields(ICustomPGApplicantEdit)
    230227            for field in PG_OMIT_EDIT_FIELDS:
    231228                form_fields = form_fields.omit(field)
    232         elif target is not None and target.startswith('putme'):
     229        elif self.target is not None and self.target.startswith('putme'):
    233230            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
    234231            for field in PUTME_OMIT_EDIT_FIELDS:
     
    252249        if not store.getFileByContext(self.context, attr=u'refereeform.pdf'):
    253250            return _('No referee form pdf file uploaded.')
    254         if not store.getFileByContext(self.context, attr=u'credentialform.pdf'):
     251        if self.target is not None and self.target.startswith('pg') \
     252            and not store.getFileByContext(self.context, attr=u'credentialform.pdf'):
    255253            return _('No credential form pdf file uploaded.')
    256254        if not self.request.form.get('confirm_passport', False):
  • main/waeup.futminna/trunk/src/waeup/futminna/applicants/browser_templates/applicanteditpage.pt

    r10220 r10224  
    8585          <span tal:replace="view/max_file_upload_size">10 KB</span>
    8686      </tr>
    87       <tr>
     87      <tr tal:condition="python: view.target.startswith('pg')">
    8888        <td class="fieldname" i18n:translate="">
    8989          Credential Form:
  • 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.