Ignore:
Timestamp:
23 Apr 2013, 09:39:09 (12 years ago)
Author:
Henrik Bettermann
Message:

Simplify logging. files_uploaded attribute is redundant.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/applicants
Files:
2 edited

Legend:

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

    r10094 r10095  
    796796        self.wf_info = IWorkflowInfo(self.context)
    797797        self.max_upload_size = string_from_bytes(MAX_UPLOAD_SIZE)
    798         self.files_uploaded = []
    799798        self.upload_success = None
    800799        upload = self.request.form.get('form.passport', None)
     
    805804                upload, self.context, self)
    806805            if self.upload_success:
    807                 self.files_uploaded.append('passport')
     806                self.context.writeLogMessage(self, 'saved: passport')
    808807        return
    809808
     
    839838        if self.upload_success is False:  # False is not None!
    840839            # Error during image upload. Ignore other values.
    841             # In custom packages other file uploads might have been
    842             # successful.
    843             changed_fields = self.files_uploaded
    844             fields_string = ' + '.join(changed_fields)
    845             if fields_string:
    846                 self.context.writeLogMessage(self, 'saved: % s' % fields_string)
    847840            return
    848841        changed_fields = self.applyData(self.context, **data)
     
    852845        else:
    853846            changed_fields = []
    854         if self.upload_success:
    855             changed_fields += self.files_uploaded
    856847        if password:
    857848            # Now we know that the form has no errors and can set password ...
     
    995986        if self.upload_success is False:  # False is not None!
    996987            # Error during image upload. Ignore other values.
    997             # In custom packages other file uploads might have been
    998             # successful.
    999             changed_fields = self.files_uploaded
    1000             fields_string = ' + '.join(changed_fields)
    1001             if fields_string:
    1002                 self.context.writeLogMessage(self, 'saved: % s' % fields_string)
    1003988            return
    1004989        self.applyData(self.context, **data)
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py

    r10030 r10095  
    708708        self.assertTrue(passport1 == passport2)
    709709        return
     710
     711    def test_upload_image_by_manager_with_logging(self):
     712        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     713        self.browser.open(self.manage_path)
     714        # Create a pseudo image file and select it to be uploaded in form
     715        photo_content = 'A' * 1024 * 5  # A string of 5 KB size
     716        pseudo_image = StringIO(photo_content)
     717        ctrl = self.browser.getControl(name='form.passport')
     718        file_ctrl = ctrl.mech_control
     719        file_ctrl.add_file(pseudo_image, filename='myphoto.jpg')
     720        self.browser.getControl("Save").click() # submit form
     721        # Even though the form could not be saved ...
     722        self.assertTrue(
     723            'Required input is missing' in self.browser.contents)
     724        # ... the file has been successfully uploaded
     725        logfile = os.path.join(
     726            self.app['datacenter'].storage, 'logs', 'applicants.log')
     727        logcontent = open(logfile).read()
     728        self.assertTrue(
     729            'zope.mgr - applicants.browser.ApplicantManageFormPage - '
     730            '%s - saved: passport'
     731            % (self.applicant.applicant_id)
     732            in logcontent)
    710733
    711734    def test_pay_application_fee(self):
Note: See TracChangeset for help on using the changeset viewer.