Esempio n. 1
0
    def test_view_zip(self):
        """ Custom view of zipfile """
        from zipfile import ZipFile
        zfile = open(
            os.path.join(os.path.dirname(__file__), 'fixtures',
                         'one_file_zip.zip'), 'rb')

        upload_file = StringIO(zfile.read())
        upload_file.filename = 'test.zip'
        upload_file.headers = {'content-type': 'application/zip'}

        namelist = ZipFile(zfile).namelist()
        zfile.close()
        addNyBFile(self.portal.myfolder,
                   submitted=1,
                   contributor='contributor',
                   id='test',
                   title="test",
                   uploaded_file=upload_file)
        transaction.commit()

        #The result is a simple html with the contents of the zipfile (filepaths)
        self.browser.go(
            'http://localhost/portal/myfolder/test/download/1/test.zip?action=view'
        )
        html_content = self.browser.get_html()

        for filepath in namelist:
            self.assertTrue(filepath in html_content)
        zfile.close()
    def test_view_zip(self):
        """ Custom view of zipfile """
        from zipfile import ZipFile

        zfile = open(os.path.join(os.path.dirname(__file__), "fixtures", "one_file_zip.zip"), "rb")

        upload_file = StringIO(zfile.read())
        upload_file.filename = "test.zip"
        upload_file.headers = {"content-type": "application/zip"}

        namelist = ZipFile(zfile).namelist()
        zfile.close()
        addNyBFile(
            self.portal.myfolder,
            submitted=1,
            contributor="contributor",
            id="test",
            title="test",
            uploaded_file=upload_file,
        )
        transaction.commit()

        # The result is a simple html with the contents of the zipfile (filepaths)
        self.browser.go("http://localhost/portal/myfolder/test/download/en/1/test.zip?action=view")
        html_content = self.browser.get_html()

        for filepath in namelist:
            self.assertTrue(filepath in html_content)
        zfile.close()
    def afterSetUp(self):
        self.portal.manage_install_pluggableitem("Naaya Blob File")
        from Products.Naaya.NyFolder import addNyFolder
        from naaya.content.bfile.bfile_item import addNyBFile

        addNyFolder(self.portal, "fol", contributor="contributor", submitted=1)
        addNyBFile(self.portal.fol, id="multiver", title="Mulitple versions", submitted=1, contributor="contributor")
        self.ob_url = "http://localhost/portal/fol/multiver"
        transaction.commit()
        self.the_file = self.portal.fol.multiver
Esempio n. 4
0
 def afterSetUp(self):
     self.portal.manage_install_pluggableitem('Naaya Blob File')
     from Products.Naaya.NyFolder import addNyFolder
     from naaya.content.bfile.bfile_item import addNyBFile
     addNyFolder(self.portal, 'fol', contributor='contributor', submitted=1)
     addNyBFile(self.portal.fol, id='multiver', title='Mulitple versions',
         submitted=1, contributor='contributor')
     self.ob_url = 'http://localhost/portal/fol/multiver'
     transaction.commit()
     self.the_file = self.portal.fol.multiver
Esempio n. 5
0
 def afterSetUp(self):
     self.portal.manage_install_pluggableitem('Naaya Blob File')
     from Products.Naaya.NyFolder import addNyFolder
     from naaya.content.bfile.bfile_item import addNyBFile
     addNyFolder(self.portal, 'fol', contributor='contributor', submitted=1)
     addNyBFile(self.portal.fol, id='multiver', title='Mulitple versions',
         submitted=1, contributor='contributor')
     self.ob_url = 'http://localhost/portal/fol/multiver'
     transaction.commit()
     self.the_file = self.portal.fol.multiver
Esempio n. 6
0
 def afterSetUp(self):
     self.portal.manage_install_pluggableitem('Naaya Blob File')
     addNyFolder(self.portal,
                 'myfolder',
                 contributor='contributor',
                 submitted=1)
     addNyBFile(self.portal.myfolder,
                id='mybfile',
                title='My file',
                submitted=1,
                contributor='contributor')
     transaction.commit()
    def afterSetUp(self):
        self.portal.manage_install_pluggableitem("Naaya Blob File")
        from Products.Naaya.NyFolder import addNyFolder
        from naaya.content.bfile.bfile_item import addNyBFile

        addNyFolder(self.portal, "fol", contributor="contributor", submitted=1)
        addNyBFile(self.portal.fol, id="secur", title="Mulitple versions", submitted=1, contributor="contributor")
        self.ob_url = "http://localhost/portal/fol/secur"
        transaction.commit()
        self.file_data = {"filename": "my.png", "content_type": "image/png", "data": "asdf" * 1024 * 64}
        self.portal.fol.secur._save_file(self.make_file(**self.file_data), contributor="contributor")
        transaction.commit()
        self.the_file = self.portal.fol.secur
    def afterSetUp(self):

        from naaya.content.bfile.bfile_item import NyBFile

        def get_selected_language(self):
            form = getattr(self.REQUEST, "form", {"lang": "en"})
            return form.get("lang", "en")

        NyBFile.get_selected_language = get_selected_language

        self.portal.manage_install_pluggableitem("Naaya Blob File")
        addNyFolder(self.portal, "myfolder", contributor="contributor", submitted=1)
        addNyBFile(self.portal.myfolder, id="mybfile", title="My file", submitted=1, contributor="contributor")
        transaction.commit()
Esempio n. 9
0
    def afterSetUp(self):

        from naaya.content.bfile.bfile_item import NyBFile
        def get_selected_language(self):
            form = getattr(self.REQUEST, 'form', {'lang':'en'})
            return form.get('lang', 'en')
        NyBFile.get_selected_language = get_selected_language

        self.portal.manage_install_pluggableitem('Naaya Blob File')
        addNyFolder(self.portal, 'myfolder', contributor='contributor',
                    submitted=1)
        addNyBFile(self.portal.myfolder, id='mybfile', title='My file',
                   submitted=1, contributor='contributor')
        transaction.commit()
Esempio n. 10
0
    def test_view(self):
        """Same as download, but without the attachment header"""

        file_contents = 'simple contents'
        uploaded_file = StringIO(file_contents)
        uploaded_file.filename = 'test.txt'
        uploaded_file.headers = {'content-type': 'text/plain; charset=utf-8'}

        addNyBFile(self.portal.myfolder, submitted=1,
                   contributor='contributor', id='test', title="test",
                   uploaded_file=uploaded_file, approved=True)
        transaction.commit()
        #View the file
        self.browser.go('http://localhost/portal/myfolder/test/download/en/1/test.txt?action=view')
        self.assertEqual(file_contents, self.browser.get_html())
Esempio n. 11
0
    def test_view(self):
        """Same as download, but without the attachment header"""

        file_contents = 'simple contents'
        uploaded_file = StringIO(file_contents)
        uploaded_file.filename = 'test.txt'
        uploaded_file.headers = {'content-type': 'text/plain; charset=utf-8'}

        addNyBFile(self.portal.myfolder, submitted=1,
                   contributor='contributor', id='test', title="test",
                   uploaded_file=uploaded_file, approved=True)
        transaction.commit()
        #View the file
        self.browser.go('http://localhost/portal/myfolder/test/download/1/test.txt?action=view')
        self.assertEqual(file_contents, self.browser.get_html())
Esempio n. 12
0
 def add_blob_file(location_obj, name, data):
     f = StringIO(data)
     f.filename = name
     if '.' in name:
         name = name.rsplit('.', 1)[0]
     return addNyBFile(location_obj, uploaded_file=f,
                       _send_notifications=False)
Esempio n. 13
0
    def document_entry(self, parent_path, ob_id, filename, data_file,
                       title, description, date, userid):
        from StringIO import StringIO
        assert isinstance(data_file, StringIO)
        data_file.filename = filename
        bf = make_blobfile(data_file,
                           content_type=mimetype_from_filename(filename),
                           removed=False,
                           timestamp=datetime(date.year, date.month, date.day))

        parent = get_parent(self.context, parent_path)
        orig_path = parent_path + '/' + ob_id

        if orig_path in self.rename:
            ob_path = self.rename.get(orig_path)
            the_file = self.context.restrictedTraverse(ob_path)

        else:
            kwargs = {
                'id': ob_id,
                'contributor': userid,
                'releasedate': nydateformat(date),
                'title': title,
                'description': description,
                '_send_notifications': False,
            }
            assert ob_id not in parent.objectIds()
            the_file_id = addNyBFile(parent, **kwargs)
            self.rename[orig_path] = parent_path + '/' + the_file_id
            the_file = parent[the_file_id]

        the_file._versions.append(bf)
        #print>>self.report, "file: %r" % path_in_site(the_file)
        self.count['files'] += 1
Esempio n. 14
0
 def add_file(location_obj, name, data):
     f = StringIO(data)
     f.filename = name
     if '.' in name:
         name = name.rsplit('.', 1)[0]
     return addNyBFile(location_obj, id=name, uploaded_file=f,
                       _send_notifications=False)
Esempio n. 15
0
    def test_add_utf8_filename(self):
        name = u'A\xa7A\xb6A\xa9A\xae_\x86\x90a\x83\x91a\x86\x93a\x99\xaa1.txt'
        myfile = StringIO('hello data!')
        myfile.filename = name.encode('utf-8')

        myfolder = self.portal.myfolder
        file_id = addNyBFile(myfolder, uploaded_file=myfile,
                             submitted=1, contributor='contributor')
        self.assertEqual(file_id, 'assapa-c-r-_aaaa1') # as returned by unidecode
Esempio n. 16
0
 def afterSetUp(self):
     self.portal.manage_install_pluggableitem('Naaya Blob File')
     from Products.Naaya.NyFolder import addNyFolder
     from naaya.content.bfile.bfile_item import addNyBFile
     addNyFolder(self.portal, 'fol', contributor='contributor', submitted=1)
     addNyBFile(self.portal.fol, id='secur', title='Mulitple versions',
         submitted=1, contributor='contributor')
     self.ob_url = 'http://localhost/portal/fol/secur'
     transaction.commit()
     self.file_data = {
         'filename': 'my.png',
         'content_type': 'image/png',
         'data': 'asdf'*1024*64,
     }
     self.portal.fol.secur._save_file(self.make_file(**self.file_data),
                              contributor='contributor')
     transaction.commit()
     self.the_file = self.portal.fol.secur
Esempio n. 17
0
 def afterSetUp(self):
     self.portal.manage_install_pluggableitem('Naaya Blob File')
     from Products.Naaya.NyFolder import addNyFolder
     from naaya.content.bfile.bfile_item import addNyBFile
     addNyFolder(self.portal, 'fol', contributor='contributor', submitted=1)
     addNyBFile(self.portal.fol, id='secur', title='Mulitple versions',
         submitted=1, contributor='contributor')
     self.ob_url = 'http://localhost/portal/fol/secur'
     transaction.commit()
     self.file_data = {
         'filename': 'my.png',
         'content_type': 'image/png',
         'data': 'asdf'*1024*64,
     }
     self.portal.fol.secur._save_file(self.make_file(**self.file_data),
                              contributor='contributor')
     transaction.commit()
     self.the_file = self.portal.fol.secur
Esempio n. 18
0
    def test_direct_download(self):
        """ In folder listing we should have a download link that allows users
        to download the last version directly

        """
        file_contents = 'simple contents'
        uploaded_file = StringIO(file_contents)
        uploaded_file.filename = 'test.txt'
        uploaded_file.headers = {'content-type': 'text/plain; charset=utf-8'}

        addNyBFile(self.portal.myfolder, id='mybfile_download', title='My file',
                   uploaded_file=uploaded_file, submitted=1,
                   contributor='admin')
        transaction.commit()

        self.browser_do_login('admin', '')
        self.browser.go('http://localhost/portal/myfolder')
        self.assertTrue(
        self.portal.myfolder.mybfile_download.current_version_download_url() in
        self.browser.get_html())
Esempio n. 19
0
    def test_direct_download(self):
        """ In folder listing we should have a download link that allows users
        to download the last version directly

        """
        file_contents = 'simple contents'
        uploaded_file = StringIO(file_contents)
        uploaded_file.filename = 'test.txt'
        uploaded_file.headers = {'content-type': 'text/plain; charset=utf-8'}

        addNyBFile(self.portal.myfolder, id='mybfile_download', title='My file',
                   uploaded_file=uploaded_file, submitted=1,
                   contributor='admin')
        transaction.commit()

        self.browser_do_login('admin', '')
        self.browser.go('http://localhost/portal/myfolder')
        self.assertTrue(
        self.portal.myfolder.mybfile_download.current_version_download_url() in
        self.browser.get_html())
Esempio n. 20
0
    def test_add_utf8_filename(self):
        name = u'A\xa7A\xb6A\xa9A\xae_\x86\x90a\x83\x91a\x86\x93a\x99\xaa1.txt'
        myfile = StringIO('hello data!')
        myfile.filename = name.encode('utf-8')

        myfolder = self.portal.myfolder
        file_id = addNyBFile(myfolder,
                             uploaded_file=myfile,
                             submitted=1,
                             contributor='contributor')
        self.assertEqual(file_id,
                         'assapa-c-r-_aaaa1')  # as returned by unidecode
Esempio n. 21
0
    def test_add_no_title(self):
        myfile = StringIO('hello data!')
        myfile.filename = 'my_file_for_title.txt'

        myfolder = self.portal.myfolder
        file_id = addNyBFile(myfolder, uploaded_file=myfile,
                             submitted=1, contributor='contributor')

        self.assertEqual(file_id, 'my_file_for_title')
        self.assertTrue('my_file_for_title' in myfolder.objectIds())
        myfile = myfolder['my_file_for_title']
        self.assertEqual(myfile.title, 'my_file_for_title')
Esempio n. 22
0
    def test_add_no_title(self):
        myfile = StringIO('hello data!')
        myfile.filename = 'my_file_for_title.txt'

        myfolder = self.portal.myfolder
        file_id = addNyBFile(myfolder,
                             uploaded_file=myfile,
                             submitted=1,
                             contributor='contributor')

        self.assertEqual(file_id, 'my_file_for_title')
        self.assertTrue('my_file_for_title' in myfolder.objectIds())
        myfile = myfolder['my_file_for_title']
        self.assertEqual(myfile.title, 'my_file_for_title')
    def test_direct_download(self):
        """ In folder listing we should have a download link that allows users
        to download the last version directly

        """
        file_contents = "simple contents"
        uploaded_file = StringIO(file_contents)
        uploaded_file.filename = "test.txt"
        uploaded_file.headers = {"content-type": "text/plain; charset=utf-8"}

        addNyBFile(
            self.portal.myfolder,
            id="mybfile_download",
            title="My file",
            uploaded_file=uploaded_file,
            submitted=1,
            contributor="admin",
        )
        transaction.commit()

        self.browser_do_login("admin", "")
        self.browser.go("http://localhost/portal/myfolder")
        self.assertTrue(self.portal.myfolder.mybfile_download.current_version_download_url() in self.browser.get_html())
Esempio n. 24
0
    def document_entry(self, parent_path, ob_id, filename, data_file,
                       title, description, keywords, date, userid):
        from StringIO import StringIO
        assert isinstance(data_file, StringIO)
        data_file.filename = filename
        content_type, content_encoding = mimetypes.guess_type(filename)
        if content_type is None:
            content_type = 'application/octet-stream'
        bf = make_blobfile(data_file,
                           content_type=content_type,
                           removed=False,
                           timestamp=datetime(date.year, date.month, date.day))

        parent = get_parent(self.context, parent_path)
        orig_path = join_parent_path(parent_path, ob_id)

        if orig_path in self.rename:
            ob_path = self.rename.get(orig_path)
            the_file = self.context.restrictedTraverse(ob_path)
            logger.warn('new document version for %r' % orig_path)
            if keywords or description:
                logger.warn('ignoring keywords=%r, description=%r' %
                          (keywords, description))

        else:
            kwargs = {
                'id': ob_id,
                'contributor': userid or self.default_userid,
                'releasedate': nydateformat(date),
                'title': title,
                'description': description,
                'keywords': keywords,
                '_send_notifications': False,
            }
            assert ob_id not in parent.objectIds()
            the_file_id = addNyBFile(parent, **kwargs)
            if parent_path:
                self.rename[orig_path] = parent_path + '/' + the_file_id
            else:
                self.rename[orig_path] = the_file_id
            the_file = parent[the_file_id]

        the_file._versions.append(bf)
        logger.info("Added file: %r", path_in_site(the_file))
        self.count['files'] += 1
Esempio n. 25
0
    def document_entry(self, parent_path, ob_id, filename, data_file, title,
                       description, keywords, date, userid):
        from StringIO import StringIO
        assert isinstance(data_file, StringIO)
        data_file.filename = filename
        content_type, content_encoding = mimetypes.guess_type(filename)
        if content_type is None:
            content_type = 'application/octet-stream'
        bf = make_blobfile(data_file,
                           content_type=content_type,
                           removed=False,
                           timestamp=datetime(date.year, date.month, date.day))

        parent = get_parent(self.context, parent_path)
        orig_path = join_parent_path(parent_path, ob_id)

        if orig_path in self.rename:
            ob_path = self.rename.get(orig_path)
            the_file = self.context.restrictedTraverse(ob_path)
            logger.warn('new document version for %r' % orig_path)
            if keywords or description:
                logger.warn('ignoring keywords=%r, description=%r' %
                            (keywords, description))

        else:
            kwargs = {
                'id': ob_id,
                'contributor': userid or self.default_userid,
                'releasedate': nydateformat(date),
                'title': title,
                'description': description,
                'keywords': keywords,
                '_send_notifications': False,
            }
            assert ob_id not in parent.objectIds()
            the_file_id = addNyBFile(parent, **kwargs)
            if parent_path:
                self.rename[orig_path] = parent_path + '/' + the_file_id
            else:
                self.rename[orig_path] = the_file_id
            the_file = parent[the_file_id]

        the_file._versions.append(bf)
        logger.info("Added file: %r", path_in_site(the_file))
        self.count['files'] += 1
Esempio n. 26
0
 def add_bfile(self, **kwargs):
     addNyBFile(self.portal.myfolder, submitted=1, contributor='contributor', **kwargs)
Esempio n. 27
0
 def add_bfile(self, **kwargs):
     addNyBFile(self.portal.myfolder,
                submitted=1,
                contributor='contributor',
                **kwargs)
Esempio n. 28
0
 def afterSetUp(self):
     self.portal.manage_install_pluggableitem('Naaya Blob File')
     addNyFolder(self.portal, 'myfolder', contributor='contributor', submitted=1)
     addNyBFile(self.portal.myfolder, id='mybfile', title='My file', submitted=1, contributor='contributor')
     transaction.commit()
Esempio n. 29
0
 def add_object(self, parent, **kwargs):
     from naaya.content.bfile.bfile_item import addNyBFile
     return addNyBFile(parent, **kwargs)