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() addNyLocalizedBFile(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 afterSetUp(self): self.portal.gl_add_site_language('fr') self.portal.manage_install_pluggableitem('Naaya Localized Blob File') addNyFolder(self.portal, 'myfolder', contributor='contributor', submitted=1) addNyLocalizedBFile(self.portal.myfolder, id='mylocalizedbfile', title='My localized file', submitted=1, contributor='contributor') transaction.commit()
def test_exceptions(self): """Different Exceptions""" file_contents = 'simple contents' uploaded_file = StringIO(file_contents) uploaded_file.filename = 'test.txt' uploaded_file.headers = {'content-type': 'text/plain; charset=utf-8'} addNyLocalizedBFile(self.portal.myfolder, submitted=1, contributor='contributor', id='test', title="test", uploaded_file=uploaded_file, approved=True) transaction.commit() self.browser.go( 'http://localhost/portal/myfolder/test/download/0/test.txt?action=view' ) self.failUnless('An error was encountered' in self.browser.get_html()) self.failUnless('NotFound' in self.browser.get_html()) self.browser.go( 'http://localhost/portal/de/myfolder/test/download/1/test.txt?action=view' ) self.failUnless('An error was encountered' in self.browser.get_html()) self.failUnless('NotFound' in self.browser.get_html()) self.browser.go( 'http://localhost/portal/fr/myfolder/test/download/1/test.txt?action=view' ) self.failUnless('An error was encountered' in self.browser.get_html()) self.failUnless('NotFound' in self.browser.get_html())
def afterSetUp(self): self.portal.gl_add_site_language('fr') self.portal.manage_install_pluggableitem('Naaya Localized Blob File') from Products.Naaya.NyFolder import addNyFolder from naaya.content.localizedbfile.localizedbfile_item import addNyLocalizedBFile addNyFolder(self.portal, 'fol', contributor='contributor', submitted=1) addNyLocalizedBFile(self.portal.fol, id='multiver', title='Mulitple versions', submitted=1, contributor='contributor') self.ob_url_en = 'http://localhost/portal/fol/multiver' self.ob_url_fr = 'http://localhost/portal/fr/fol/multiver' self.lang_map = self.portal.gl_get_languages() transaction.commit() self.the_file = self.portal.fol.multiver
def afterSetUp(self): self.portal.gl_add_site_language('fr') self.portal.manage_install_pluggableitem('Naaya Localized Blob File') addNyFolder(self.portal, 'myfolder', contributor='contributor', submitted=1) addNyLocalizedBFile(self.portal.myfolder, id='mylocalizedbfile', title='My localized file', submitted=1, contributor='contributor') transaction.commit()
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'} addNyLocalizedBFile(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())
def test_random_action(self): """Radom action""" file_contents = 'simple contents' uploaded_file = StringIO(file_contents) uploaded_file.filename = 'test.txt' uploaded_file.headers = {'content-type': 'text/plain; charset=utf-8'} addNyLocalizedBFile(self.portal.myfolder, submitted=1, contributor='contributor', id='test', title="test", uploaded_file=uploaded_file, approved=True) transaction.commit() self.browser.go('http://localhost/portal/de/myfolder/test/download/1/test.txt?action=shop') self.failUnless('An error was encountered' in self.browser.get_html()) self.failUnless('NotFound' in self.browser.get_html())
def afterSetUp(self): self.portal.gl_add_site_language('fr') self.portal.manage_install_pluggableitem('Naaya Localized Blob File') from Products.Naaya.NyFolder import addNyFolder from naaya.content.localizedbfile.localizedbfile_item import addNyLocalizedBFile addNyFolder(self.portal, 'fol', contributor='contributor', submitted=1) addNyLocalizedBFile(self.portal.fol, id='multiver', title='Mulitple versions', submitted=1, contributor='contributor') self.ob_url_en = 'http://localhost/portal/fol/multiver' self.ob_url_fr = 'http://localhost/portal/fr/fol/multiver' self.lang_map = self.portal.gl_get_languages() transaction.commit() self.the_file = self.portal.fol.multiver
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 = addNyLocalizedBFile(myfolder, uploaded_file=myfile, submitted=1, contributor='contributor') self.assertEqual(file_id, 'assapa-c-r-_aaaa1') # as returned by unidecode
def afterSetUp(self): self.portal.manage_install_pluggableitem('Naaya Localized Blob File') from Products.Naaya.NyFolder import addNyFolder from naaya.content.localizedbfile.localizedbfile_item import addNyLocalizedBFile addNyFolder(self.portal, 'fol', contributor='contributor', submitted=1) addNyLocalizedBFile(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, } lang = 'en' self.portal.fol.secur._save_file(self.make_file(**self.file_data), lang, contributor='contributor') transaction.commit() self.the_file = self.portal.fol.secur
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'} addNyLocalizedBFile(self.portal.myfolder, id='mylocalizedbfile_download', title='My Localized 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.mylocalizedbfile_download.current_version_download_url() in self.browser.get_html())
def test_add_no_title(self): myfile = StringIO('hello data!') myfile.filename = 'my_file_for_title.txt' myfolder = self.portal.myfolder file_id = addNyLocalizedBFile(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_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'} addNyLocalizedBFile(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())
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'} addNyLocalizedBFile(self.portal.myfolder, id='mylocalizedbfile_download', title='My Localized 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.mylocalizedbfile_download. current_version_download_url() in self.browser.get_html())
def afterSetUp(self): self.portal.manage_install_pluggableitem('Naaya Localized Blob File') from Products.Naaya.NyFolder import addNyFolder from naaya.content.localizedbfile.localizedbfile_item import addNyLocalizedBFile addNyFolder(self.portal, 'fol', contributor='contributor', submitted=1) addNyLocalizedBFile(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, } lang = 'en' self.portal.fol.secur._save_file(self.make_file(**self.file_data), lang, contributor='contributor') transaction.commit() self.the_file = self.portal.fol.secur
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() addNyLocalizedBFile(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 add_localizedbfile(self, lang, **kwargs): addNyLocalizedBFile(self.portal.myfolder, submitted=1, contributor='contributor', _lang=lang, **kwargs )