Changeset 9038


Ignore:
Timestamp:
21 Jul 2012, 16:41:08 (12 years ago)
Author:
Henrik Bettermann
Message:

Do not allow to upload file with filename which already exists in finished or unfinished folder.

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

Legend:

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

    r9033 r9038  
    844844                self.flash(_("Only csv files are allowed."))
    845845                return
    846             target = os.path.join(self.context.storage,
    847                                   self.getNormalizedFileName(filename))
     846            normalized_filename = self.getNormalizedFileName(filename)
     847            finished_file = os.path.join(
     848                self.context.storage, 'finished', normalized_filename)
     849            unfinished_file = os.path.join(
     850                self.context.storage, 'unfinished', normalized_filename)
     851            if os.path.exists(finished_file) or os.path.exists(unfinished_file):
     852                self.flash(_("File with same name was uploaded earlier."))
     853                return
     854            target = os.path.join(self.context.storage, normalized_filename)
    848855            open(target, 'wb').write(uploadfile.read())
    849856            os.chmod(target, 0664)
  • main/waeup.kofa/trunk/src/waeup/kofa/university/tests/test_batching.py

    r9002 r9038  
    2626from zope.securitypolicy.interfaces import (
    2727    IPrincipalRoleMap, IPrincipalRoleManager)
     28from zope.testbrowser.testing import Browser
    2829from zope.interface.verify import verifyClass, verifyObject
    2930from waeup.kofa.interfaces import IBatchProcessor
     
    115116    def setUp(self):
    116117        super(TestFacultyProcessor, self).setUp()
     118
     119        self.browser = Browser()
     120        self.browser.handleErrors = False
     121        self.datacenter_path = 'http://localhost/app/datacenter'
     122        self.app['datacenter'].setStoragePath(self.dc_root)
    117123
    118124        self.proc = FacultyProcessor()
     
    284290        self.assertEqual(local_role, 'alfonsrole')
    285291        shutil.rmtree(os.path.dirname(fin_file))
     292        return
     293
     294    def test_upload_import_reupload(self):
     295        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     296        self.browser.open(self.datacenter_path)
     297        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     298        self.assertEqual(self.browser.url, self.datacenter_path)
     299        self.browser.getLink("Upload data").click()
     300        file = open(self.csv_file_faculty)
     301        ctrl = self.browser.getControl(name='uploadfile:file')
     302        file_ctrl = ctrl.mech_control
     303        file_ctrl.add_file(file, filename='sample_faculty_data.csv')
     304        self.browser.getControl('Upload').click()
     305        self.browser.getLink('Process data').click()
     306        self.browser.getControl(name="select").click()
     307        importerselect = self.browser.getControl(name='importer')
     308        importerselect.getControl('Faculty Processor').selected = True
     309        modeselect = self.browser.getControl(name='mode')
     310        modeselect.getControl(value='create').selected = True
     311        self.browser.getControl('Proceed to step 3').click()
     312        self.assertTrue('Header fields OK' in self.browser.contents)
     313        self.browser.getControl('Perform import').click()
     314        self.assertTrue('Successfully processed 1 rows' in self.browser.contents)
     315        # We import the same file a second time.
     316        self.browser.open(self.datacenter_path)
     317        self.browser.getLink("Upload data").click()
     318        file = open(self.csv_file_faculty)
     319        ctrl = self.browser.getControl(name='uploadfile:file')
     320        file_ctrl = ctrl.mech_control
     321        file_ctrl.add_file(file, filename='sample_faculty_data.csv')
     322        self.browser.getControl('Upload').click()
     323        self.assertTrue(
     324            'File with same name was uploaded earlier' in self.browser.contents)
    286325        return
    287326
Note: See TracChangeset for help on using the changeset viewer.