Commit 39369332 authored by Jérome Perrin's avatar Jérome Perrin

testDms

parent cc8560b9
...@@ -31,11 +31,10 @@ ...@@ -31,11 +31,10 @@
import unittest import unittest
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from erp5.component.test.testDms import DocumentUploadTestCase
from erp5.component.test.testDms import makeFileUpload
class TestERP5Discussion(ERP5TypeTestCase): class TestERP5Discussion(DocumentUploadTestCase):
"""Test for erp5_discussion business template. """Test for erp5_discussion business template.
""" """
...@@ -143,7 +142,7 @@ class TestERP5Discussion(ERP5TypeTestCase): ...@@ -143,7 +142,7 @@ class TestERP5Discussion(ERP5TypeTestCase):
self.assertEqual(0, len(attachment_list)) self.assertEqual(0, len(attachment_list))
# check attachment creation # check attachment creation
file_ = makeFileUpload('TEST-en-002.doc') file_ = self.makeFileUpload('TEST-en-002.doc')
web_section1.WebSection_createNewDiscussionThread('test1-new-with-attachment', 'test1 body', file=file_) web_section1.WebSection_createNewDiscussionThread('test1-new-with-attachment', 'test1 body', file=file_)
discussion_thread, = [x for x in self.portal.discussion_thread_module.objectValues() \ discussion_thread, = [x for x in self.portal.discussion_thread_module.objectValues() \
if x.getId() not in discussion_thread_id_set] if x.getId() not in discussion_thread_id_set]
...@@ -240,7 +239,7 @@ class TestERP5Discussion(ERP5TypeTestCase): ...@@ -240,7 +239,7 @@ class TestERP5Discussion(ERP5TypeTestCase):
web_site_value = self.portal.web_site_module.newContent(portal_type='Web Site') web_site_value = self.portal.web_site_module.newContent(portal_type='Web Site')
web_section_value = web_site_value.newContent(portal_type='Web Section') web_section_value = web_site_value.newContent(portal_type='Web Section')
file_ = makeFileUpload('simple.csv') file_ = self.makeFileUpload('simple.csv')
web_section_value.WebSection_createNewDiscussionThread( web_section_value.WebSection_createNewDiscussionThread(
"Thread Title", "Thread Title",
"Post Content", "Post Content",
......
...@@ -45,13 +45,12 @@ ...@@ -45,13 +45,12 @@
These are subject to another suite "testIngestion". These are subject to another suite "testIngestion".
""" """
import io
import unittest import unittest
import time import time
from six.moves import cStringIO as StringIO
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from unittest import expectedFailure from unittest import expectedFailure
from Products.ERP5Type.Utils import bytes2str, str2bytes
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.utils import FileUpload from Products.ERP5Type.tests.utils import FileUpload
from Products.ERP5Type.tests.utils import DummyLocalizer from Products.ERP5Type.tests.utils import DummyLocalizer
...@@ -87,20 +86,25 @@ REFERENCE_REGULAR_EXPRESSION = "(?P<reference>[A-Z]{3,10})(-(?P<language>[a-z]{2 ...@@ -87,20 +86,25 @@ REFERENCE_REGULAR_EXPRESSION = "(?P<reference>[A-Z]{3,10})(-(?P<language>[a-z]{2
def makeFilePath(name): def makeFilePath(name):
return os.path.join(TEST_FILES_HOME, name) return os.path.join(TEST_FILES_HOME, name)
def makeFileUpload(name, as_name=None):
def getFileSize(name):
path = makeFilePath(name)
with open(path, "rb") as f:
return len(f.read())
class DocumentUploadTestCase(ERP5TypeTestCase):
def makeFileUpload(self, name, as_name=None):
if as_name is None: if as_name is None:
as_name = name as_name = name
path = makeFilePath(name) path = makeFilePath(name)
return FileUpload(path, as_name) fu = FileUpload(path, as_name)
self.addCleanup(fu.close)
return fu
def getFileSize(name):
path = makeFilePath(name)
f = open(path, "r")
file_size = len(f.read())
f.close()
return file_size
class TestDocumentMixin(ERP5TypeTestCase): class TestDocumentMixin(DocumentUploadTestCase):
business_template_list = ['erp5_core_proxy_field_legacy', business_template_list = ['erp5_core_proxy_field_legacy',
'erp5_jquery', 'erp5_jquery',
...@@ -184,6 +188,7 @@ class TestDocumentMixin(ERP5TypeTestCase): ...@@ -184,6 +188,7 @@ class TestDocumentMixin(ERP5TypeTestCase):
doc_module.manage_delObjects(list(doc_module.objectIds())) doc_module.manage_delObjects(list(doc_module.objectIds()))
self.tic() self.tic()
class TestDocument(TestDocumentMixin): class TestDocument(TestDocumentMixin):
""" """
Test basic document - related operations Test basic document - related operations
...@@ -230,14 +235,18 @@ class TestDocument(TestDocumentMixin): ...@@ -230,14 +235,18 @@ class TestDocument(TestDocumentMixin):
def getURLSizeList(self, uri, **kw): def getURLSizeList(self, uri, **kw):
# __ac=RVJQNVR5cGVUZXN0Q2FzZTo%3D is encoded ERP5TypeTestCase with empty password # __ac=RVJQNVR5cGVUZXN0Q2FzZTo%3D is encoded ERP5TypeTestCase with empty password
url = '%s?%s&__ac=%s' %(uri, make_query(kw), 'RVJQNVR5cGVUZXN0Q2FzZTo%3D') url = '%s?%s' % (uri, make_query(dict(kw, __ac='RVJQNVR5cGVUZXN0Q2FzZTo%3D')))
format_=kw.get('format', 'jpeg') format_ = kw.get('format', 'jpeg')
infile = urlopen(url) infile = urlopen(url)
try:
image_data = infile.read()
finally:
infile.close()
# save as file with proper incl. format filename (for some reasons PIL uses this info) # save as file with proper incl. format filename (for some reasons PIL uses this info)
filename = "%s%stest-image-format-resize.%s" %(os.getcwd(), os.sep, format_) filename = "%s%stest-image-format-resize.%s" % (os.getcwd(), os.sep, format_)
with open(filename, "wb") as f: with open(filename, "wb") as f:
f.write(infile.read()) f.write(image_data)
infile.close()
file_size = len(image_data) file_size = len(image_data)
try: try:
from PIL import Image from PIL import Image
...@@ -278,7 +287,7 @@ class TestDocument(TestDocumentMixin): ...@@ -278,7 +287,7 @@ class TestDocument(TestDocumentMixin):
# the same document should now have revision 4 (because it should have done mergeRevision) # the same document should now have revision 4 (because it should have done mergeRevision)
# getRevisionList should return (1, 2, 3, 4) # getRevisionList should return (1, 2, 3, 4)
filename = 'TEST-en-002.doc' filename = 'TEST-en-002.doc'
file_ = makeFileUpload(filename) file_ = self.makeFileUpload(filename)
document = self.portal.portal_contributions.newContent(file=file_) document = self.portal.portal_contributions.newContent(file=file_)
self.tic() self.tic()
document_url = document.getRelativeUrl() document_url = document.getRelativeUrl()
...@@ -490,38 +499,38 @@ class TestDocument(TestDocumentMixin): ...@@ -490,38 +499,38 @@ class TestDocument(TestDocumentMixin):
# create docs to be referenced: # create docs to be referenced:
# (1) TEST, 002, en # (1) TEST, 002, en
filename = 'TEST-en-002.odt' filename = 'TEST-en-002.odt'
file_ = makeFileUpload(filename) file_ = self.makeFileUpload(filename)
document1 = self.portal.portal_contributions.newContent(file=file_) document1 = self.portal.portal_contributions.newContent(file=file_)
# (2) TEST, 002, fr # (2) TEST, 002, fr
as_name = 'TEST-fr-002.odt' as_name = 'TEST-fr-002.odt'
file_ = makeFileUpload(filename, as_name) file_ = self.makeFileUpload(filename, as_name)
document2 = self.portal.portal_contributions.newContent(file=file_) document2 = self.portal.portal_contributions.newContent(file=file_)
# (3) TEST, 003, en # (3) TEST, 003, en
as_name = 'TEST-en-003.odt' as_name = 'TEST-en-003.odt'
file_ = makeFileUpload(filename, as_name) file_ = self.makeFileUpload(filename, as_name)
document3 = self.portal.portal_contributions.newContent(file=file_) document3 = self.portal.portal_contributions.newContent(file=file_)
# create docs to contain references in text_content: # create docs to contain references in text_content:
# REF, 002, en; "I use reference to look up TEST" # REF, 002, en; "I use reference to look up TEST"
filename = 'REF-en-002.odt' filename = 'REF-en-002.odt'
file_ = makeFileUpload(filename) file_ = self.makeFileUpload(filename)
document5 = self.portal.portal_contributions.newContent(file=file_) document5 = self.portal.portal_contributions.newContent(file=file_)
# REFLANG, 001, en: "I use reference and language to look up TEST-fr" # REFLANG, 001, en: "I use reference and language to look up TEST-fr"
filename = 'REFLANG-en-001.odt' filename = 'REFLANG-en-001.odt'
file_ = makeFileUpload(filename) file_ = self.makeFileUpload(filename)
document6 = self.portal.portal_contributions.newContent(file=file_) document6 = self.portal.portal_contributions.newContent(file=file_)
# REFVER, 001, en: "I use reference and version to look up TEST-002" # REFVER, 001, en: "I use reference and version to look up TEST-002"
filename = 'REFVER-en-001.odt' filename = 'REFVER-en-001.odt'
file_ = makeFileUpload(filename) file_ = self.makeFileUpload(filename)
document7 = self.portal.portal_contributions.newContent(file=file_) document7 = self.portal.portal_contributions.newContent(file=file_)
# REFVERLANG, 001, en: "I use reference, version and language to look up TEST-002-en" # REFVERLANG, 001, en: "I use reference, version and language to look up TEST-002-en"
filename = 'REFVERLANG-en-001.odt' filename = 'REFVERLANG-en-001.odt'
file_ = makeFileUpload(filename) file_ = self.makeFileUpload(filename)
document8 = self.portal.portal_contributions.newContent(file=file_) document8 = self.portal.portal_contributions.newContent(file=file_)
self.tic() self.tic()
...@@ -577,7 +586,7 @@ class TestDocument(TestDocumentMixin): ...@@ -577,7 +586,7 @@ class TestDocument(TestDocumentMixin):
def test_catalog_search_by_size(self): def test_catalog_search_by_size(self):
doc = self.portal.document_module.newContent( doc = self.portal.document_module.newContent(
portal_type='Spreadsheet', portal_type='Spreadsheet',
file=makeFileUpload('import_data_list.ods')) file=self.makeFileUpload('import_data_list.ods'))
self.tic() self.tic()
self.assertEqual( self.assertEqual(
[x.getObject() for x in self.portal.portal_catalog(size=doc.getSize())], [doc]) [x.getObject() for x in self.portal.portal_catalog(size=doc.getSize())], [doc])
...@@ -585,8 +594,8 @@ class TestDocument(TestDocumentMixin): ...@@ -585,8 +594,8 @@ class TestDocument(TestDocumentMixin):
def testOOoDocument_get_size(self): def testOOoDocument_get_size(self):
# test get_size on OOoDocument # test get_size on OOoDocument
doc = self.portal.document_module.newContent(portal_type='Spreadsheet') doc = self.portal.document_module.newContent(portal_type='Spreadsheet')
doc.edit(file=makeFileUpload('import_data_list.ods')) doc.edit(file=self.makeFileUpload('import_data_list.ods'))
self.assertEqual(len(makeFileUpload('import_data_list.ods').read()), self.assertEqual(len(self.makeFileUpload('import_data_list.ods').read()),
doc.get_size()) doc.get_size())
def testTempOOoDocument_get_size(self): def testTempOOoDocument_get_size(self):
...@@ -599,14 +608,14 @@ class TestDocument(TestDocumentMixin): ...@@ -599,14 +608,14 @@ class TestDocument(TestDocumentMixin):
# test hasData on OOoDocument # test hasData on OOoDocument
doc = self.portal.document_module.newContent(portal_type='Spreadsheet') doc = self.portal.document_module.newContent(portal_type='Spreadsheet')
self.assertFalse(doc.hasData()) self.assertFalse(doc.hasData())
doc.edit(file=makeFileUpload('import_data_list.ods')) doc.edit(file=self.makeFileUpload('import_data_list.ods'))
self.assertTrue(doc.hasData()) self.assertTrue(doc.hasData())
def testTempOOoDocument_hasData(self): def testTempOOoDocument_hasData(self):
# test hasData on TempOOoDocument # test hasData on TempOOoDocument
doc = self.portal.newContent(temp_object=True, portal_type='OOo Document', id='tmp') doc = self.portal.newContent(temp_object=True, portal_type='OOo Document', id='tmp')
self.assertFalse(doc.hasData()) self.assertFalse(doc.hasData())
doc.edit(file=makeFileUpload('import_data_list.ods')) doc.edit(file=self.makeFileUpload('import_data_list.ods'))
self.assertTrue(doc.hasData()) self.assertTrue(doc.hasData())
def test_Owner_Base_download(self): def test_Owner_Base_download(self):
...@@ -616,7 +625,7 @@ class TestDocument(TestDocumentMixin): ...@@ -616,7 +625,7 @@ class TestDocument(TestDocumentMixin):
doc = self.portal.document_module.newContent( doc = self.portal.document_module.newContent(
filename='test.ods', filename='test.ods',
portal_type='Spreadsheet') portal_type='Spreadsheet')
doc.edit(file=makeFileUpload('TEST-en-002.doc')) doc.edit(file=self.makeFileUpload('TEST-en-002.doc'))
self.tic() self.tic()
uf = self.portal.acl_users uf = self.portal.acl_users
...@@ -626,7 +635,7 @@ class TestDocument(TestDocumentMixin): ...@@ -626,7 +635,7 @@ class TestDocument(TestDocumentMixin):
response = self.publish('%s/Base_download' % doc.getPath(), response = self.publish('%s/Base_download' % doc.getPath(),
basic='member_user1:secret') basic='member_user1:secret')
self.assertEqual(makeFileUpload('TEST-en-002.doc').read(), self.assertEqual(self.makeFileUpload('TEST-en-002.doc').read(),
response.getBody()) response.getBody())
self.assertEqual('application/msword', self.assertEqual('application/msword',
response.headers['content-type']) response.headers['content-type'])
...@@ -655,7 +664,7 @@ class TestDocument(TestDocumentMixin): ...@@ -655,7 +664,7 @@ class TestDocument(TestDocumentMixin):
doc = self.portal.document_module.newContent( doc = self.portal.document_module.newContent(
filename='test.ods', filename='test.ods',
portal_type='Spreadsheet') portal_type='Spreadsheet')
doc.edit(file=makeFileUpload('import.file.with.dot.in.filename.ods')) doc.edit(file=self.makeFileUpload('import.file.with.dot.in.filename.ods'))
doc.publish() doc.publish()
self.tic() self.tic()
...@@ -670,12 +679,8 @@ class TestDocument(TestDocumentMixin): ...@@ -670,12 +679,8 @@ class TestDocument(TestDocumentMixin):
self.assertEqual('attachment; filename="import.file.with.dot.in.filename.pdf"', self.assertEqual('attachment; filename="import.file.with.dot.in.filename.pdf"',
response.getHeader('content-disposition')) response.getHeader('content-disposition'))
response_body = response.getBody() response_body = response.getBody()
conversion = str(doc.convert('pdf')[1]) conversion = doc.convert('pdf')[1]
diff = '\n'+'\n'.join(difflib.unified_diff(response_body.splitlines(), self.assertEqual(response_body, conversion)
conversion.splitlines(),
fromfile='first_call.pdf',
tofile='second_call.pdf'))
self.assertEqual(response_body, conversion, diff)
# test Print icon works on OOoDocument # test Print icon works on OOoDocument
response = self.publish('%s/OOoDocument_print' % doc.getPath()) response = self.publish('%s/OOoDocument_print' % doc.getPath())
...@@ -733,13 +738,13 @@ class TestDocument(TestDocumentMixin): ...@@ -733,13 +738,13 @@ class TestDocument(TestDocumentMixin):
def test_csv(self): def test_csv(self):
doc = self.portal.document_module.newContent( doc = self.portal.document_module.newContent(
portal_type='Spreadsheet', portal_type='Spreadsheet',
file=makeFileUpload('simple.csv'), file=self.makeFileUpload('simple.csv'),
) )
self.assertEqual(doc.getContentType(), 'text/csv') self.assertEqual(doc.getContentType(), 'text/csv')
doc.publish() doc.publish()
self.tic() self.tic()
response = self.publish('%s?format=' % doc.getPath()) response = self.publish('%s?format=' % doc.getPath())
self.assertEqual(response.getBody(), makeFileUpload('simple.csv').read()) self.assertEqual(response.getBody(), self.makeFileUpload('simple.csv').read())
self.assertEqual(response.getHeader('Content-Type'), 'text/csv; charset=utf-8') self.assertEqual(response.getHeader('Content-Type'), 'text/csv; charset=utf-8')
self.assertEqual(response.getHeader('Content-Disposition'), 'attachment; filename="simple.csv"') self.assertEqual(response.getHeader('Content-Disposition'), 'attachment; filename="simple.csv"')
...@@ -761,7 +766,7 @@ class TestDocument(TestDocumentMixin): ...@@ -761,7 +766,7 @@ class TestDocument(TestDocumentMixin):
is not draft is not draft
""" """
filename = 'TEST-en-002.doc' filename = 'TEST-en-002.doc'
file_ = makeFileUpload(filename) file_ = self.makeFileUpload(filename)
document = self.portal.portal_contributions.newContent(file=file_) document = self.portal.portal_contributions.newContent(file=file_)
self.assertEqual('converting', document.getExternalProcessingState()) self.assertEqual('converting', document.getExternalProcessingState())
...@@ -826,7 +831,7 @@ class TestDocument(TestDocumentMixin): ...@@ -826,7 +831,7 @@ class TestDocument(TestDocumentMixin):
document. document.
""" """
filename = 'EmbeddedImage-en-002.odt' filename = 'EmbeddedImage-en-002.odt'
file_ = makeFileUpload(filename) file_ = self.makeFileUpload(filename)
document = self.portal.portal_contributions.newContent(file=file_) document = self.portal.portal_contributions.newContent(file=file_)
self.tic() self.tic()
...@@ -1310,7 +1315,7 @@ class TestDocument(TestDocumentMixin): ...@@ -1310,7 +1315,7 @@ class TestDocument(TestDocumentMixin):
re_html_nbsp = re.compile('&(nbsp|#160);') re_html_nbsp = re.compile('&(nbsp|#160);')
def test_PDFTextContent(self): def test_PDFTextContent(self):
upload_file = makeFileUpload('REF-en-001.pdf') upload_file = self.makeFileUpload('REF-en-001.pdf')
document = self.portal.portal_contributions.newContent(file=upload_file) document = self.portal.portal_contributions.newContent(file=upload_file)
self.assertEqual('PDF', document.getPortalType()) self.assertEqual('PDF', document.getPortalType())
self.assertEqual('I use reference to look up TEST\n', self.assertEqual('I use reference to look up TEST\n',
...@@ -1321,7 +1326,7 @@ class TestDocument(TestDocumentMixin): ...@@ -1321,7 +1326,7 @@ class TestDocument(TestDocumentMixin):
document.SearchableText()) document.SearchableText())
def test_PDFToPng(self): def test_PDFToPng(self):
upload_file = makeFileUpload('REF-en-001.pdf') upload_file = self.makeFileUpload('REF-en-001.pdf')
document = self.portal.portal_contributions.newContent(file=upload_file) document = self.portal.portal_contributions.newContent(file=upload_file)
self.assertEqual('PDF', document.getPortalType()) self.assertEqual('PDF', document.getPortalType())
...@@ -1333,7 +1338,7 @@ class TestDocument(TestDocumentMixin): ...@@ -1333,7 +1338,7 @@ class TestDocument(TestDocumentMixin):
self.assertEqual(image_data[1:4], b'PNG') self.assertEqual(image_data[1:4], b'PNG')
def test_PDFToJpg(self): def test_PDFToJpg(self):
upload_file = makeFileUpload('REF-en-001.pdf') upload_file = self.makeFileUpload('REF-en-001.pdf')
document = self.portal.portal_contributions.newContent(file=upload_file) document = self.portal.portal_contributions.newContent(file=upload_file)
self.assertEqual('PDF', document.getPortalType()) self.assertEqual('PDF', document.getPortalType())
...@@ -1344,7 +1349,7 @@ class TestDocument(TestDocumentMixin): ...@@ -1344,7 +1349,7 @@ class TestDocument(TestDocumentMixin):
self.assertEqual(image_data[6:10], b'JFIF') self.assertEqual(image_data[6:10], b'JFIF')
def test_PDFToGif(self): def test_PDFToGif(self):
upload_file = makeFileUpload('REF-en-001.pdf') upload_file = self.makeFileUpload('REF-en-001.pdf')
document = self.portal.portal_contributions.newContent(file=upload_file) document = self.portal.portal_contributions.newContent(file=upload_file)
self.assertEqual('PDF', document.getPortalType()) self.assertEqual('PDF', document.getPortalType())
...@@ -1355,7 +1360,7 @@ class TestDocument(TestDocumentMixin): ...@@ -1355,7 +1360,7 @@ class TestDocument(TestDocumentMixin):
self.assertEqual(image_data[0:4], b'GIF8') self.assertEqual(image_data[0:4], b'GIF8')
def test_PDFToTiff(self): def test_PDFToTiff(self):
upload_file = makeFileUpload('REF-en-001.pdf') upload_file = self.makeFileUpload('REF-en-001.pdf')
document = self.portal.portal_contributions.newContent(file=upload_file) document = self.portal.portal_contributions.newContent(file=upload_file)
self.assertEqual('PDF', document.getPortalType()) self.assertEqual('PDF', document.getPortalType())
...@@ -1367,7 +1372,7 @@ class TestDocument(TestDocumentMixin): ...@@ -1367,7 +1372,7 @@ class TestDocument(TestDocumentMixin):
def test_PDF_content_information(self): def test_PDF_content_information(self):
upload_file = makeFileUpload('REF-en-001.pdf') upload_file = self.makeFileUpload('REF-en-001.pdf')
document = self.portal.portal_contributions.newContent(file=upload_file) document = self.portal.portal_contributions.newContent(file=upload_file)
self.assertEqual('PDF', document.getPortalType()) self.assertEqual('PDF', document.getPortalType())
content_information = document.getContentInformation() content_information = document.getContentInformation()
...@@ -1379,7 +1384,7 @@ class TestDocument(TestDocumentMixin): ...@@ -1379,7 +1384,7 @@ class TestDocument(TestDocumentMixin):
def test_PDF_content_information_extra_metadata(self): def test_PDF_content_information_extra_metadata(self):
# Extra metadata, such as those stored by pdftk update_info are also # Extra metadata, such as those stored by pdftk update_info are also
# available in document.getContentInformation() # available in document.getContentInformation()
upload_file = makeFileUpload('metadata.pdf', as_name='REF-en-001.pdf') upload_file = self.makeFileUpload('metadata.pdf', as_name='REF-en-001.pdf')
document = self.portal.portal_contributions.newContent(file=upload_file) document = self.portal.portal_contributions.newContent(file=upload_file)
self.tic() self.tic()
self.assertEqual('PDF', document.getPortalType()) self.assertEqual('PDF', document.getPortalType())
...@@ -1390,7 +1395,7 @@ class TestDocument(TestDocumentMixin): ...@@ -1390,7 +1395,7 @@ class TestDocument(TestDocumentMixin):
# contribute file which will be merged to current document in synchronous mode # contribute file which will be merged to current document in synchronous mode
# and check content_type recalculated # and check content_type recalculated
upload_file = makeFileUpload('Forty-Two.Pages-en-001.pdf', as_name='REF-en-001.pdf') upload_file = self.makeFileUpload('Forty-Two.Pages-en-001.pdf', as_name='REF-en-001.pdf')
contributed_document = self.portal.Base_contribute(file=upload_file, \ contributed_document = self.portal.Base_contribute(file=upload_file, \
synchronous_metadata_discovery=True) synchronous_metadata_discovery=True)
self.tic() self.tic()
...@@ -1404,7 +1409,7 @@ class TestDocument(TestDocumentMixin): ...@@ -1404,7 +1409,7 @@ class TestDocument(TestDocumentMixin):
document.getContentInformation()['Pages']) document.getContentInformation()['Pages'])
# upload with another file and check content_type recalculated # upload with another file and check content_type recalculated
upload_file = makeFileUpload('REF-en-001.pdf') upload_file = self.makeFileUpload('REF-en-001.pdf')
document.setFile(upload_file) document.setFile(upload_file)
self.tic() self.tic()
content_information = document.getContentInformation() content_information = document.getContentInformation()
...@@ -1422,7 +1427,7 @@ class TestDocument(TestDocumentMixin): ...@@ -1422,7 +1427,7 @@ class TestDocument(TestDocumentMixin):
# IndirectObject instance which is not picklable # IndirectObject instance which is not picklable
document = self.portal.document_module.newContent( document = self.portal.document_module.newContent(
portal_type='PDF', portal_type='PDF',
file=makeFileUpload('apple_metadata.pdf')) file=self.makeFileUpload('apple_metadata.pdf'))
# content_information is picklable # content_information is picklable
content_information = document.getContentInformation() content_information = document.getContentInformation()
from pickle import dumps from pickle import dumps
...@@ -1435,7 +1440,7 @@ class TestDocument(TestDocumentMixin): ...@@ -1435,7 +1440,7 @@ class TestDocument(TestDocumentMixin):
""" Test that pypdf2 handle wrong formatted PDF """ """ Test that pypdf2 handle wrong formatted PDF """
pdf = self.portal.document_module.newContent( pdf = self.portal.document_module.newContent(
portal_type='PDF', portal_type='PDF',
file=makeFileUpload('FEUILLE BLANCHE.pdf'), file=self.makeFileUpload('FEUILLE BLANCHE.pdf'),
title='Bad PDF') title='Bad PDF')
self.tic() self.tic()
pdf.share() pdf.share()
...@@ -1445,7 +1450,7 @@ class TestDocument(TestDocumentMixin): ...@@ -1445,7 +1450,7 @@ class TestDocument(TestDocumentMixin):
self.assertNotEqual(result, None) self.assertNotEqual(result, None)
def test_PDF_content_content_type(self): def test_PDF_content_content_type(self):
upload_file = makeFileUpload('REF-en-001.pdf') upload_file = self.makeFileUpload('REF-en-001.pdf')
document = self.portal.document_module.newContent(portal_type='PDF') document = self.portal.document_module.newContent(portal_type='PDF')
# Here we use edit instead of setFile, # Here we use edit instead of setFile,
# because only edit method set filename as filename. # because only edit method set filename as filename.
...@@ -1454,17 +1459,17 @@ class TestDocument(TestDocumentMixin): ...@@ -1454,17 +1459,17 @@ class TestDocument(TestDocumentMixin):
def test_PDF_watermark(self): def test_PDF_watermark(self):
original_document = self.portal.portal_contributions.newContent( original_document = self.portal.portal_contributions.newContent(
file=makeFileUpload('REF-en-001.pdf')) file=self.makeFileUpload('REF-en-001.pdf'))
# This watermark.pdf document is a pdf with a transparent background. Such # This watermark.pdf document is a pdf with a transparent background. Such
# document can be created using GIMP # document can be created using GIMP
watermark_document = self.portal.portal_contributions.newContent( watermark_document = self.portal.portal_contributions.newContent(
file=makeFileUpload('watermark.pdf')) file=self.makeFileUpload('watermark.pdf'))
watermarked_data = original_document.getWatermarkedData( watermarked_data = original_document.getWatermarkedData(
watermark_data=watermark_document.getData(), watermark_data=watermark_document.getData(),
repeat_watermark=False) repeat_watermark=False)
# this looks like a pdf # this looks like a pdf
self.assertTrue(watermarked_data.startswith('%PDF-1.3')) self.assertTrue(watermarked_data.startswith(b'%PDF-1.3'))
# and ERP5 can make a PDF Document out of it # and ERP5 can make a PDF Document out of it
watermarked_document = self.portal.document_module.newContent( watermarked_document = self.portal.document_module.newContent(
...@@ -1477,14 +1482,14 @@ class TestDocument(TestDocumentMixin): ...@@ -1477,14 +1482,14 @@ class TestDocument(TestDocumentMixin):
def test_PDF_watermark_repeat(self): def test_PDF_watermark_repeat(self):
# watermark a pdf, repeating the watermark # watermark a pdf, repeating the watermark
original_document = self.portal.portal_contributions.newContent( original_document = self.portal.portal_contributions.newContent(
file=makeFileUpload('Forty-Two.Pages-en-001.pdf')) file=self.makeFileUpload('Forty-Two.Pages-en-001.pdf'))
watermark_document = self.portal.portal_contributions.newContent( watermark_document = self.portal.portal_contributions.newContent(
file=makeFileUpload('watermark.pdf')) file=self.makeFileUpload('watermark.pdf'))
watermarked_data = original_document.getWatermarkedData( watermarked_data = original_document.getWatermarkedData(
watermark_data=watermark_document.getData(), watermark_data=watermark_document.getData(),
repeat_watermark=True) repeat_watermark=True)
self.assertTrue(watermarked_data.startswith('%PDF-1.3')) self.assertTrue(watermarked_data.startswith(b'%PDF-1.3'))
watermarked_document = self.portal.document_module.newContent( watermarked_document = self.portal.document_module.newContent(
portal_type='PDF', portal_type='PDF',
data=watermarked_data) data=watermarked_data)
...@@ -1495,15 +1500,15 @@ class TestDocument(TestDocumentMixin): ...@@ -1495,15 +1500,15 @@ class TestDocument(TestDocumentMixin):
def test_PDF_watermark_start_page(self): def test_PDF_watermark_start_page(self):
# watermark a pdf, starting on the second page # watermark a pdf, starting on the second page
original_document = self.portal.portal_contributions.newContent( original_document = self.portal.portal_contributions.newContent(
file=makeFileUpload('Forty-Two.Pages-en-001.pdf')) file=self.makeFileUpload('Forty-Two.Pages-en-001.pdf'))
watermark_document = self.portal.portal_contributions.newContent( watermark_document = self.portal.portal_contributions.newContent(
file=makeFileUpload('watermark.pdf')) file=self.makeFileUpload('watermark.pdf'))
watermarked_data = original_document.getWatermarkedData( watermarked_data = original_document.getWatermarkedData(
watermark_data=watermark_document.getData(), watermark_data=watermark_document.getData(),
repeat_watermark=False, repeat_watermark=False,
watermark_start_page=1) # This is 0 based. watermark_start_page=1) # This is 0 based.
self.assertTrue(watermarked_data.startswith('%PDF-1.3')) self.assertTrue(watermarked_data.startswith(b'%PDF-1.3'))
watermarked_document = self.portal.document_module.newContent( watermarked_document = self.portal.document_module.newContent(
portal_type='PDF', portal_type='PDF',
data=watermarked_data) data=watermarked_data)
...@@ -1512,7 +1517,7 @@ class TestDocument(TestDocumentMixin): ...@@ -1512,7 +1517,7 @@ class TestDocument(TestDocumentMixin):
watermarked_document.getData()) watermarked_document.getData())
def test_checkVisibleTextInPresentationToImageConversion(self): def test_checkVisibleTextInPresentationToImageConversion(self):
odp = makeFileUpload("TEST-en-003.odp") odp = self.makeFileUpload("TEST-en-003.odp")
presentation = self.portal.document_module.newContent( presentation = self.portal.document_module.newContent(
portal_type="Presentation", portal_type="Presentation",
data=odp, data=odp,
...@@ -1532,7 +1537,7 @@ class TestDocument(TestDocumentMixin): ...@@ -1532,7 +1537,7 @@ class TestDocument(TestDocumentMixin):
self.assertIn("ERP5 DMS page 1", txt) self.assertIn("ERP5 DMS page 1", txt)
def test_Document_getStandardFilename(self): def test_Document_getStandardFilename(self):
upload_file = makeFileUpload('metadata.pdf') upload_file = self.makeFileUpload('metadata.pdf')
document = self.portal.document_module.newContent(portal_type='PDF') document = self.portal.document_module.newContent(portal_type='PDF')
document.edit(file=upload_file) document.edit(file=upload_file)
self.assertEqual(document.getStandardFilename(), 'metadata.pdf') self.assertEqual(document.getStandardFilename(), 'metadata.pdf')
...@@ -1544,7 +1549,7 @@ class TestDocument(TestDocumentMixin): ...@@ -1544,7 +1549,7 @@ class TestDocument(TestDocumentMixin):
self.assertEqual(document.getStandardFilename(format='png'), self.assertEqual(document.getStandardFilename(format='png'),
'metadata-001-en.png') 'metadata-001-en.png')
# check when format contains multiple '.' # check when format contains multiple '.'
upload_file = makeFileUpload('TEST-en-003.odp') upload_file = self.makeFileUpload('TEST-en-003.odp')
document = self.portal.document_module.newContent(portal_type='Presentation') document = self.portal.document_module.newContent(portal_type='Presentation')
document.edit(file=upload_file) document.edit(file=upload_file)
self.assertEqual(document.getStandardFilename(), 'TEST-en-003.odp') self.assertEqual(document.getStandardFilename(), 'TEST-en-003.odp')
...@@ -1552,18 +1557,18 @@ class TestDocument(TestDocumentMixin): ...@@ -1552,18 +1557,18 @@ class TestDocument(TestDocumentMixin):
def test_CMYKImageTextContent(self): def test_CMYKImageTextContent(self):
upload_file = makeFileUpload('cmyk_sample.jpg') upload_file = self.makeFileUpload('cmyk_sample.jpg')
document = self.portal.portal_contributions.newContent(file=upload_file) document = self.portal.portal_contributions.newContent(file=upload_file)
self.assertEqual('Image', document.getPortalType()) self.assertEqual('Image', document.getPortalType())
self.assertEqual('ERP5 is a free software.', document.asText()) self.assertEqual('ERP5 is a free software.', document.asText())
def test_MonochromeImageResize(self): def test_MonochromeImageResize(self):
upload_file = makeFileUpload('monochrome_sample.tiff') upload_file = self.makeFileUpload('monochrome_sample.tiff')
document = self.portal.portal_contributions.newContent(file=upload_file) document = self.portal.portal_contributions.newContent(file=upload_file)
self.assertEqual('Image', document.getPortalType()) self.assertEqual('Image', document.getPortalType())
resized_image = document.convert(format='png', display='small')[1] resized_image = document.convert(format='png', display='small')[1]
identify_output = Popen(['identify', '-verbose', '-'], stdin=PIPE, stdout=PIPE).communicate(resized_image)[0] identify_output = Popen(['identify', '-verbose', '-'], stdin=PIPE, stdout=PIPE).communicate(resized_image)[0]
self.assertNotIn('1-bit', identify_output) self.assertNotIn(b'1-bit', identify_output)
self.assertEqual('ERP5 is a free software.', document.asText()) self.assertEqual('ERP5 is a free software.', document.asText())
def test_Base_showFoundText(self): def test_Base_showFoundText(self):
...@@ -1571,7 +1576,7 @@ class TestDocument(TestDocumentMixin): ...@@ -1571,7 +1576,7 @@ class TestDocument(TestDocumentMixin):
document = self.portal.document_module.newContent(portal_type='Drawing') document = self.portal.document_module.newContent(portal_type='Drawing')
self.assertEqual('empty', document.getExternalProcessingState()) self.assertEqual('empty', document.getExternalProcessingState())
upload_file = makeFileUpload('TEST-en-002.odt') upload_file = self.makeFileUpload('TEST-en-002.odt')
document.edit(file=upload_file) document.edit(file=upload_file)
self.tic() self.tic()
self.assertEqual('converted', document.getExternalProcessingState()) self.assertEqual('converted', document.getExternalProcessingState())
...@@ -1586,7 +1591,7 @@ class TestDocument(TestDocumentMixin): ...@@ -1586,7 +1591,7 @@ class TestDocument(TestDocumentMixin):
document.Base_showFoundText()) document.Base_showFoundText())
# upload again good content # upload again good content
upload_file = makeFileUpload('TEST-en-002.odt') upload_file = self.makeFileUpload('TEST-en-002.odt')
document.edit(file=upload_file) document.edit(file=upload_file)
self.tic() self.tic()
self.assertEqual('converted', document.getExternalProcessingState()) self.assertEqual('converted', document.getExternalProcessingState())
...@@ -1597,18 +1602,18 @@ class TestDocument(TestDocumentMixin): ...@@ -1597,18 +1602,18 @@ class TestDocument(TestDocumentMixin):
Check that encoding remains. Check that encoding remains.
""" """
web_page_portal_type = 'Web Page' web_page_portal_type = 'Web Page'
string_to_test = 'éààéôù' string_to_test = u'éààéôù'
web_page = self.portal.getDefaultModule(web_page_portal_type)\ web_page = self.portal.getDefaultModule(web_page_portal_type)\
.newContent(portal_type=web_page_portal_type) .newContent(portal_type=web_page_portal_type)
html_content = '<p>%s</p>' % string_to_test html_content = u'<p>%s</p>' % string_to_test
web_page.edit(text_content=html_content) web_page.edit(text_content=html_content)
_, pdf_data = web_page.convert('pdf') _, pdf_data = web_page.convert('pdf')
text_content = self.portal.portal_transforms.\ text_content = self.portal.portal_transforms.\
convertToData('text/plain', convertToData('text/plain',
str(pdf_data), bytes(pdf_data),
object=web_page, context=web_page, object=web_page, context=web_page,
filename='test.pdf') filename='test.pdf')
self.assertIn(string_to_test, text_content) self.assertIn(string_to_test, text_content.decode('utf-8'))
def test_HTML_to_ODT_conversion_keep_related_image_list(self): def test_HTML_to_ODT_conversion_keep_related_image_list(self):
"""This test create a Web Page and an Image. """This test create a Web Page and an Image.
...@@ -1630,7 +1635,7 @@ class TestDocument(TestDocumentMixin): ...@@ -1630,7 +1635,7 @@ class TestDocument(TestDocumentMixin):
.newContent(portal_type=image_portal_type) .newContent(portal_type=image_portal_type)
# edit content and publish it # edit content and publish it
upload_file = makeFileUpload('cmyk_sample.jpg') upload_file = self.makeFileUpload('cmyk_sample.jpg')
image.edit(reference=image_reference, image.edit(reference=image_reference,
version='001', version='001',
language='en', language='en',
...@@ -1666,7 +1671,7 @@ class TestDocument(TestDocumentMixin): ...@@ -1666,7 +1671,7 @@ class TestDocument(TestDocumentMixin):
# Let's continue with Presentation Document as embbeded image # Let's continue with Presentation Document as embbeded image
document = self.portal.document_module.newContent(portal_type='Presentation') document = self.portal.document_module.newContent(portal_type='Presentation')
upload_file = makeFileUpload('TEST-en-003.odp') upload_file = self.makeFileUpload('TEST-en-003.odp')
image_reference = 'IMAGE-odp' image_reference = 'IMAGE-odp'
document.edit(file=upload_file, reference=image_reference) document.edit(file=upload_file, reference=image_reference)
document.publish() document.publish()
...@@ -1737,7 +1742,7 @@ class TestDocument(TestDocumentMixin): ...@@ -1737,7 +1742,7 @@ class TestDocument(TestDocumentMixin):
module = self.portal.getDefaultModule(web_page_portal_type) module = self.portal.getDefaultModule(web_page_portal_type)
web_page = module.newContent(portal_type=web_page_portal_type) web_page = module.newContent(portal_type=web_page_portal_type)
html_content = """<html> html_content = u"""<html>
<head> <head>
<meta http-equiv="refresh" content="5;url=http://example.com/"/> <meta http-equiv="refresh" content="5;url=http://example.com/"/>
<meta http-equiv="Set-Cookie" content=""/> <meta http-equiv="Set-Cookie" content=""/>
...@@ -1763,9 +1768,7 @@ class TestDocument(TestDocumentMixin): ...@@ -1763,9 +1768,7 @@ class TestDocument(TestDocumentMixin):
</body> </body>
</html> </html>
""" """
if six.PY2: html_content = html_content.encode('iso-8859-1')
html_content = html_content.decode('utf-8').encode('iso-8859-1')
# content encoded into another codec # content encoded into another codec
# than utf-8 comes from necessarily an external file # than utf-8 comes from necessarily an external file
# (Ingestion, or FileField), not from user interface # (Ingestion, or FileField), not from user interface
...@@ -1774,12 +1777,8 @@ class TestDocument(TestDocumentMixin): ...@@ -1774,12 +1777,8 @@ class TestDocument(TestDocumentMixin):
# as it is done in reality # as it is done in reality
# Mimic the behaviour of a FileUpload from WebPage_view # Mimic the behaviour of a FileUpload from WebPage_view
file_like = StringIO() file_like = io.BytesIO(html_content)
file_like.write(html_content) file_like.filename = 'something.htm'
setattr(file_like, 'filename', 'something.htm')
if six.PY3:
from io import BytesIO
file_like = BytesIO(file_like.getvalue().encode())
web_page.edit(file=file_like) web_page.edit(file=file_like)
# run conversion to base format # run conversion to base format
self.tic() self.tic()
...@@ -1886,7 +1885,7 @@ document.write('<sc'+'ript type="text/javascript" src="http://somosite.bg/utb.ph ...@@ -1886,7 +1885,7 @@ document.write('<sc'+'ript type="text/javascript" src="http://somosite.bg/utb.ph
self.assertNotIn('#FFAA44', safe_html) self.assertNotIn('#FFAA44', safe_html)
filename = 'broken_html.html' filename = 'broken_html.html'
file_object = makeFileUpload(filename) file_object = self.makeFileUpload(filename)
web_page.edit(file=file_object) web_page.edit(file=file_object)
assert web_page.convert('html')[1] assert web_page.convert('html')[1]
...@@ -1946,7 +1945,7 @@ document.write('<sc'+'ript type="text/javascript" src="http://somosite.bg/utb.ph ...@@ -1946,7 +1945,7 @@ document.write('<sc'+'ript type="text/javascript" src="http://somosite.bg/utb.ph
document_module = self.portal.getDefaultModule(portal_type) document_module = self.portal.getDefaultModule(portal_type)
document = document_module.newContent(portal_type=portal_type) document = document_module.newContent(portal_type=portal_type)
upload_file = makeFileUpload('Forty-Two.Pages-en-001.pdf') upload_file = self.makeFileUpload('Forty-Two.Pages-en-001.pdf')
document.edit(file=upload_file) document.edit(file=upload_file)
pages_number = int(document.getContentInformation()['Pages']) pages_number = int(document.getContentInformation()['Pages'])
self.tic() self.tic()
...@@ -2050,16 +2049,24 @@ document.write('<sc'+'ript type="text/javascript" src="http://somosite.bg/utb.ph ...@@ -2050,16 +2049,24 @@ document.write('<sc'+'ript type="text/javascript" src="http://somosite.bg/utb.ph
""" """
web_page_portal_type = 'Web Page' web_page_portal_type = 'Web Page'
module = self.portal.getDefaultModule(web_page_portal_type) module = self.portal.getDefaultModule(web_page_portal_type)
upload_file = makeFileUpload('TEST-text-iso8859-1.txt') upload_file = self.makeFileUpload('TEST-text-iso8859-1.txt')
web_page = module.newContent(portal_type=web_page_portal_type, web_page = module.newContent(
portal_type=web_page_portal_type,
file=upload_file) file=upload_file)
self.tic() self.tic()
self.assertEqual(web_page.getContentType(), 'text/plain')
text_content = web_page.getTextContent() text_content = web_page.getTextContent()
my_utf_eight_token = 'ùééàçèîà' self.assertIn('éèàùôâïî', text_content)
text_content = text_content.replace('\n', '\n%s\n' % my_utf_eight_token) self.assertIn('éèàùôâïî', web_page.asStrippedHTML())
self.assertIn('éèàùôâïî', web_page.asEntireHTML())
added_utf_eight_token = 'ùééàçèîà'
text_content = text_content.replace('\n', '\n%s\n' % added_utf_eight_token)
web_page.edit(text_content=text_content) web_page.edit(text_content=text_content)
self.assertIn(my_utf_eight_token, web_page.asStrippedHTML()) self.assertIn('éèàùôâïî', web_page.asStrippedHTML())
self.assertTrue(isinstance(web_page.asEntireHTML().decode('utf-8'), unicode)) self.assertIn('éèàùôâïî', web_page.asEntireHTML())
self.assertIn(added_utf_eight_token, web_page.asStrippedHTML())
self.assertIn(added_utf_eight_token, web_page.asEntireHTML())
def test_PDFDocument_asTextConversion(self): def test_PDFDocument_asTextConversion(self):
"""Test a PDF document with embedded images """Test a PDF document with embedded images
...@@ -2067,24 +2074,24 @@ document.write('<sc'+'ript type="text/javascript" src="http://somosite.bg/utb.ph ...@@ -2067,24 +2074,24 @@ document.write('<sc'+'ript type="text/javascript" src="http://somosite.bg/utb.ph
""" """
document = self.portal.document_module.newContent( document = self.portal.document_module.newContent(
portal_type='PDF', portal_type='PDF',
file=makeFileUpload('TEST.Embedded.Image.pdf')) file=self.makeFileUpload('TEST.Embedded.Image.pdf'))
self.assertEqual(document.asText(), 'ERP5 is a free software.') self.assertEqual(document.asText(), 'ERP5 is a free software.')
def test_broken_pdf_asText(self): def test_broken_pdf_asText(self):
class StringIOWithFilename(StringIO): class BytesIOWithFilename(io.BytesIO):
filename = 'broken.pdf' filename = 'broken.pdf'
document = self.portal.document_module.newContent( document = self.portal.document_module.newContent(
portal_type='PDF', portal_type='PDF',
file=StringIOWithFilename('broken')) file=BytesIOWithFilename(b'broken'))
self.assertEqual(document.asText(), '') self.assertEqual(document.asText(), '')
self.tic() # no activity failure self.tic() # no activity failure
def test_password_protected_pdf_asText(self): def test_password_protected_pdf_asText(self):
pdf_reader = PyPDF2.PdfFileReader(makeFileUpload('TEST.Embedded.Image.pdf')) pdf_reader = PyPDF2.PdfFileReader(self.makeFileUpload('TEST.Embedded.Image.pdf'))
pdf_writer = PyPDF2.PdfFileWriter() pdf_writer = PyPDF2.PdfFileWriter()
pdf_writer.addPage(pdf_reader.getPage(0)) pdf_writer.addPage(pdf_reader.getPage(0))
pdf_writer.encrypt('secret') pdf_writer.encrypt('secret')
encrypted_pdf_stream = StringIO() encrypted_pdf_stream = io.BytesIO()
pdf_writer.write(encrypted_pdf_stream) pdf_writer.write(encrypted_pdf_stream)
document = self.portal.document_module.newContent( document = self.portal.document_module.newContent(
portal_type='PDF', portal_type='PDF',
...@@ -2106,7 +2113,7 @@ return 1 ...@@ -2106,7 +2113,7 @@ return 1
def _test_document_conversion_to_base_format_no_original_format_access(self, def _test_document_conversion_to_base_format_no_original_format_access(self,
portal_type, filename): portal_type, filename):
module = self.portal.getDefaultModule(portal_type) module = self.portal.getDefaultModule(portal_type)
upload_file = makeFileUpload(filename) upload_file = self.makeFileUpload(filename)
document = module.newContent(portal_type=portal_type, document = module.newContent(portal_type=portal_type,
file=upload_file) file=upload_file)
...@@ -2158,7 +2165,7 @@ return 1 ...@@ -2158,7 +2165,7 @@ return 1
self.commit() self.commit()
# Create document with good content # Create document with good content
document = self.portal.document_module.newContent(portal_type='Presentation') document = self.portal.document_module.newContent(portal_type='Presentation')
upload_file = makeFileUpload('TEST-en-003.odp') upload_file = self.makeFileUpload('TEST-en-003.odp')
document.edit(file=upload_file) document.edit(file=upload_file)
self.tic() self.tic()
self.assertEqual('converted', document.getExternalProcessingState()) self.assertEqual('converted', document.getExternalProcessingState())
...@@ -2166,12 +2173,12 @@ return 1 ...@@ -2166,12 +2173,12 @@ return 1
for credential in ['ERP5TypeTestCase:', 'zope_user:']: for credential in ['ERP5TypeTestCase:', 'zope_user:']:
response = self.publish('%s/%s' %(document.getPath(), object_url), response = self.publish('%s/%s' %(document.getPath(), object_url),
basic=credential) basic=credential)
self.assertIn('200 OK', response.getOutput()) self.assertIn(b'200 OK', response.getOutput())
# OOod produced HTML navigation, test it # cloudooo produced HTML navigation, test it
self.assertIn('First page', response.getBody()) self.assertIn(b'First page', response.getBody())
self.assertIn('Back', response.getBody()) self.assertIn(b'Back', response.getBody())
self.assertIn('Continue', response.getBody()) self.assertIn(b'Continue', response.getBody())
self.assertIn('Last page', response.getBody()) self.assertIn(b'Last page', response.getBody())
def test_getTargetFormatItemList(self): def test_getTargetFormatItemList(self):
""" """
...@@ -2183,7 +2190,7 @@ return 1 ...@@ -2183,7 +2190,7 @@ return 1
portal_type = 'PDF' portal_type = 'PDF'
module = self.portal.getDefaultModule(portal_type) module = self.portal.getDefaultModule(portal_type)
upload_file = makeFileUpload('TEST.Large.Document.pdf') upload_file = self.makeFileUpload('TEST.Large.Document.pdf')
pdf = module.newContent(portal_type=portal_type, file=upload_file) pdf = module.newContent(portal_type=portal_type, file=upload_file)
self.assertIn('html', pdf.getTargetFormatList()) self.assertIn('html', pdf.getTargetFormatList())
...@@ -2204,7 +2211,7 @@ return 1 ...@@ -2204,7 +2211,7 @@ return 1
self.assertSameSet([], presentation.getTargetFormatList()) self.assertSameSet([], presentation.getTargetFormatList())
# test uploading some data # test uploading some data
upload_file = makeFileUpload('Foo_001.odg') upload_file = self.makeFileUpload('Foo_001.odg')
presentation.edit(file=upload_file) presentation.edit(file=upload_file)
self.tic() self.tic()
self.assertIn('odg', presentation.getTargetFormatList()) self.assertIn('odg', presentation.getTargetFormatList())
...@@ -2232,7 +2239,7 @@ return 1 ...@@ -2232,7 +2239,7 @@ return 1
# images from same instance accessed by reference and wrong conversion arguments (dispay NOT display) # images from same instance accessed by reference and wrong conversion arguments (dispay NOT display)
# code should be more resilient # code should be more resilient
upload_file = makeFileUpload('cmyk_sample.jpg') upload_file = self.makeFileUpload('cmyk_sample.jpg')
image = self.portal.image_module.newContent(portal_type='Image', image = self.portal.image_module.newContent(portal_type='Image',
reference='Embedded-XXX', reference='Embedded-XXX',
version='001', version='001',
...@@ -2275,15 +2282,15 @@ return 1 ...@@ -2275,15 +2282,15 @@ return 1
""" """
# Create OOo document # Create OOo document
ooo_document = self.portal.document_module.newContent(portal_type='Presentation') ooo_document = self.portal.document_module.newContent(portal_type='Presentation')
upload_file = makeFileUpload('TEST-en-003.odp') upload_file = self.makeFileUpload('TEST-en-003.odp')
ooo_document.edit(file=upload_file) ooo_document.edit(file=upload_file)
pdf_document = self.portal.document_module.newContent(portal_type='PDF') pdf_document = self.portal.document_module.newContent(portal_type='PDF')
upload_file = makeFileUpload('TEST-en-002.pdf') upload_file = self.makeFileUpload('TEST-en-002.pdf')
pdf_document.edit(file=upload_file) pdf_document.edit(file=upload_file)
image_document = self.portal.image_module.newContent(portal_type='Image') image_document = self.portal.image_module.newContent(portal_type='Image')
upload_file = makeFileUpload('TEST-en-002.png') upload_file = self.makeFileUpload('TEST-en-002.png')
image_document.edit(file=upload_file) image_document.edit(file=upload_file)
web_page_document = self.portal.web_page_module.newContent(portal_type="Web Page") web_page_document = self.portal.web_page_module.newContent(portal_type="Web Page")
...@@ -2367,19 +2374,19 @@ return 1 ...@@ -2367,19 +2374,19 @@ return 1
""" """
def getURL(uri, **kw): def getURL(uri, **kw):
# __ac=RVJQNVR5cGVUZXN0Q2FzZTo%3D is encoded ERP5TypeTestCase with empty password # __ac=RVJQNVR5cGVUZXN0Q2FzZTo%3D is encoded ERP5TypeTestCase with empty password
url = '%s?%s&__ac=%s' %(uri, urlencode(kw), 'RVJQNVR5cGVUZXN0Q2FzZTo%3D') url = '%s?%s' % (uri, urlencode(dict(kw, __ac='RVJQNVR5cGVUZXN0Q2FzZTo%3D')))
return urlopen(url) return urlopen(url)
ooo_document = self.portal.document_module.newContent(portal_type='Presentation') ooo_document = self.portal.document_module.newContent(portal_type='Presentation')
upload_file = makeFileUpload('TEST-en-003.odp') upload_file = self.makeFileUpload('TEST-en-003.odp')
ooo_document.edit(file=upload_file) ooo_document.edit(file=upload_file)
pdf_document = self.portal.document_module.newContent(portal_type='PDF') pdf_document = self.portal.document_module.newContent(portal_type='PDF')
upload_file = makeFileUpload('TEST-en-002.pdf') upload_file = self.makeFileUpload('TEST-en-002.pdf')
pdf_document.edit(file=upload_file) pdf_document.edit(file=upload_file)
image_document = self.portal.image_module.newContent(portal_type='Image') image_document = self.portal.image_module.newContent(portal_type='Image')
upload_file = makeFileUpload('TEST-en-002.png') upload_file = self.makeFileUpload('TEST-en-002.png')
image_document.edit(file=upload_file) image_document.edit(file=upload_file)
web_page_document = self.portal.web_page_module.newContent(portal_type="Web Page") web_page_document = self.portal.web_page_module.newContent(portal_type="Web Page")
...@@ -2388,25 +2395,25 @@ return 1 ...@@ -2388,25 +2395,25 @@ return 1
web_page_document.setTextContentSubstitutionMappingMethodId('WebPage_getStandardSubstitutionMappingDict') web_page_document.setTextContentSubstitutionMappingMethodId('WebPage_getStandardSubstitutionMappingDict')
self.tic() self.tic()
response = getURL(image_document.absolute_url(), **{'format':''}) response = getURL(image_document.absolute_url(), **{'format': ''})
self.assertIn('Content-Type: image/png\r\n', response.info().headers) self.assertEqual(response.info().get('Content-Type'), 'image/png')
self.assertIn('Content-Length: %s\r\n' %getFileSize('TEST-en-002.png'), response.info().headers) self.assertEqual(response.info().get('Content-Length'), str(getFileSize('TEST-en-002.png')))
response = getURL(ooo_document.absolute_url(), **{'format':''}) response = getURL(ooo_document.absolute_url(), **{'format': ''})
self.assertIn('Content-Type: application/vnd.oasis.opendocument.presentation\r\n', response.info().headers) self.assertEqual(response.info().get('Content-Type'), 'application/vnd.oasis.opendocument.presentation')
self.assertIn('Content-Disposition: attachment; filename="TEST-en-003.odp"\r\n', response.info().headers) self.assertEqual(response.info().get('Content-Disposition'), 'attachment; filename="TEST-en-003.odp"')
self.assertIn('Content-Length: %s\r\n' %getFileSize('TEST-en-003.odp'), response.info().headers) self.assertEqual(response.info().get('Content-Length'), str(getFileSize('TEST-en-003.odp')))
response = getURL(pdf_document.absolute_url(), **{'format':''}) response = getURL(pdf_document.absolute_url(), **{'format': ''})
self.assertIn('Content-Type: application/pdf\r\n', response.info().headers) self.assertEqual(response.info().get('Content-Type'), 'application/pdf')
self.assertIn('Content-Disposition: attachment; filename="TEST-en-002.pdf"\r\n', response.info().headers) self.assertEqual(response.info().get('Content-Disposition'), 'attachment; filename="TEST-en-002.pdf"')
response = getURL(pdf_document.absolute_url(), **{'format':'pdf'}) response = getURL(pdf_document.absolute_url(), **{'format': 'pdf'})
self.assertIn('Content-Type: application/pdf\r\n', response.info().headers) self.assertEqual(response.info().get('Content-Type'), 'application/pdf')
self.assertIn('Content-Disposition: attachment; filename="TEST-en-002.pdf"\r\n', response.info().headers) self.assertEqual(response.info().get('Content-Disposition'), 'attachment; filename="TEST-en-002.pdf"')
response = getURL(web_page_document.absolute_url(), **{'format':''}) response = getURL(web_page_document.absolute_url(), **{'format': ''})
self.assertIn('Content-Type: text/html; charset=utf-8\r\n', response.info().headers) self.assertEqual(response.info().get('Content-Type'), 'text/html; charset=utf-8')
def test_checkConversionFormatPermission(self): def test_checkConversionFormatPermission(self):
""" """
...@@ -2414,7 +2421,7 @@ return 1 ...@@ -2414,7 +2421,7 @@ return 1
""" """
portal_type = 'PDF' portal_type = 'PDF'
module = self.portal.getDefaultModule(portal_type) module = self.portal.getDefaultModule(portal_type)
upload_file = makeFileUpload('TEST.Large.Document.pdf') upload_file = self.makeFileUpload('TEST.Large.Document.pdf')
pdf = module.newContent(portal_type=portal_type, file=upload_file) pdf = module.newContent(portal_type=portal_type, file=upload_file)
# if PDF size is larger than A4 format system should deny conversion # if PDF size is larger than A4 format system should deny conversion
...@@ -2423,7 +2430,7 @@ return 1 ...@@ -2423,7 +2430,7 @@ return 1
# raster -> svg image should deny conversion if image width or height > 128 px # raster -> svg image should deny conversion if image width or height > 128 px
portal_type = 'Image' portal_type = 'Image'
module = self.portal.getDefaultModule(portal_type) module = self.portal.getDefaultModule(portal_type)
upload_file = makeFileUpload('TEST-en-002.jpg') upload_file = self.makeFileUpload('TEST-en-002.jpg')
image = module.newContent(portal_type=portal_type, file=upload_file) image = module.newContent(portal_type=portal_type, file=upload_file)
self.assertRaises(Unauthorized, image.convert, format='svg') self.assertRaises(Unauthorized, image.convert, format='svg')
...@@ -2433,7 +2440,7 @@ return 1 ...@@ -2433,7 +2440,7 @@ return 1
return a default (i.e. indicating a conversion failures) return a default (i.e. indicating a conversion failures)
""" """
doc = self.portal.document_module.newContent(portal_type='Presentation') doc = self.portal.document_module.newContent(portal_type='Presentation')
upload_file = makeFileUpload('TEST-en-003.odp') upload_file = self.makeFileUpload('TEST-en-003.odp')
doc.edit(file=upload_file) doc.edit(file=upload_file)
doc.publish() doc.publish()
self.tic() self.tic()
...@@ -2561,7 +2568,7 @@ return 1 ...@@ -2561,7 +2568,7 @@ return 1
Test various cases of contributing to an existing document Test various cases of contributing to an existing document
""" """
# contribute a document, then make it not editable and check we can not contribute to it # contribute a document, then make it not editable and check we can not contribute to it
upload_file = makeFileUpload('TEST-en-002.doc') upload_file = self.makeFileUpload('TEST-en-002.doc')
kw = dict(file=upload_file, synchronous_metadata_discovery=True) kw = dict(file=upload_file, synchronous_metadata_discovery=True)
document = self.portal.Base_contribute(**kw) document = self.portal.Base_contribute(**kw)
self.tic() self.tic()
...@@ -2586,12 +2593,12 @@ return 1 ...@@ -2586,12 +2593,12 @@ return 1
""" """
# contribute a document, then make it not editable and check we can not contribute to it # contribute a document, then make it not editable and check we can not contribute to it
kw=dict(synchronous_metadata_discovery=True) kw=dict(synchronous_metadata_discovery=True)
upload_file = makeFileUpload('TEST-en-002.doc') upload_file = self.makeFileUpload('TEST-en-002.doc')
kw = dict(file=upload_file, synchronous_metadata_discovery=True) kw = dict(file=upload_file, synchronous_metadata_discovery=True)
document = self.portal.Base_contribute(**kw) document = self.portal.Base_contribute(**kw)
self.tic() self.tic()
upload_file = makeFileUpload('TEST-en-003.odp', 'TEST-en-002.doc') upload_file = self.makeFileUpload('TEST-en-003.odp', 'TEST-en-002.doc')
kw = dict(file=upload_file, synchronous_metadata_discovery=True) kw = dict(file=upload_file, synchronous_metadata_discovery=True)
document = self.portal.Base_contribute(**kw) document = self.portal.Base_contribute(**kw)
self.tic() self.tic()
...@@ -2625,7 +2632,7 @@ return 1 ...@@ -2625,7 +2632,7 @@ return 1
def test_base_convertable_uses_pdata_for_base_data(self): def test_base_convertable_uses_pdata_for_base_data(self):
document = self.portal.document_module.newContent( document = self.portal.document_module.newContent(
portal_type='Spreadsheet', portal_type='Spreadsheet',
file=makeFileUpload('import_big_spreadsheet.ods')) file=self.makeFileUpload('import_big_spreadsheet.ods'))
self.tic() self.tic()
# for large documents base_data is stored as Pdata # for large documents base_data is stored as Pdata
self.assertIsInstance(document.base_data, Pdata) self.assertIsInstance(document.base_data, Pdata)
...@@ -2635,7 +2642,7 @@ return 1 ...@@ -2635,7 +2642,7 @@ return 1
# for small documents, it's bytes directly # for small documents, it's bytes directly
document = self.portal.document_module.newContent( document = self.portal.document_module.newContent(
portal_type='Text', portal_type='Text',
file=makeFileUpload('TEST-en-002.odt')) file=self.makeFileUpload('TEST-en-002.odt'))
self.tic() self.tic()
self.assertIsInstance(document.base_data, bytes) self.assertIsInstance(document.base_data, bytes)
self.assertIsInstance(document.getBaseData(), bytes) self.assertIsInstance(document.getBaseData(), bytes)
...@@ -2647,7 +2654,7 @@ return 1 ...@@ -2647,7 +2654,7 @@ return 1
When cloning a document base_data must not be computed once again. When cloning a document base_data must not be computed once again.
""" """
# create a document # create a document
upload_file = makeFileUpload('TEST-en-002.doc') upload_file = self.makeFileUpload('TEST-en-002.doc')
kw = dict(file=upload_file, synchronous_metadata_discovery=True) kw = dict(file=upload_file, synchronous_metadata_discovery=True)
document = self.portal.Base_contribute(**kw) document = self.portal.Base_contribute(**kw)
self.tic() self.tic()
...@@ -2665,7 +2672,7 @@ return 1 ...@@ -2665,7 +2672,7 @@ return 1
# Update document with another content by using setData: # Update document with another content by using setData:
# base_data must be recomputed # base_data must be recomputed
document.edit(data=makeFileUpload('TEST-en-002.odt').read()) document.edit(data=self.makeFileUpload('TEST-en-002.odt').read())
self.tic() self.tic()
self.assertTrue(document.hasBaseData()) self.assertTrue(document.hasBaseData())
self.assertNotEqual(previous_base_data, document.getBaseData(), self.assertNotEqual(previous_base_data, document.getBaseData(),
...@@ -2677,7 +2684,7 @@ return 1 ...@@ -2677,7 +2684,7 @@ return 1
# Update document with another content by using setFile: # Update document with another content by using setFile:
# base_data must be recomputed # base_data must be recomputed
document.edit(file=makeFileUpload('TEST-en-002.doc')) document.edit(file=self.makeFileUpload('TEST-en-002.doc'))
self.tic() self.tic()
self.assertTrue(document.hasBaseData()) self.assertTrue(document.hasBaseData())
self.assertNotEqual(previous_base_data, document.getBaseData(), self.assertNotEqual(previous_base_data, document.getBaseData(),
...@@ -2698,7 +2705,7 @@ return 1 ...@@ -2698,7 +2705,7 @@ return 1
back to empty state back to empty state
""" """
# create a document # create a document
upload_file = makeFileUpload('TEST-en-002.doc') upload_file = self.makeFileUpload('TEST-en-002.doc')
kw = dict(file=upload_file, synchronous_metadata_discovery=True) kw = dict(file=upload_file, synchronous_metadata_discovery=True)
document = self.portal.Base_contribute(**kw) document = self.portal.Base_contribute(**kw)
self.tic() self.tic()
...@@ -2846,7 +2853,7 @@ return 1 ...@@ -2846,7 +2853,7 @@ return 1
""" Test "visible" instances of a doc are auto archived when a new """ Test "visible" instances of a doc are auto archived when a new
instance is made "visible" except when they have a future effective date. instance is made "visible" except when they have a future effective date.
""" """
upload_file = makeFileUpload('TEST-en-002.doc') upload_file = self.makeFileUpload('TEST-en-002.doc')
kw = dict(file=upload_file, synchronous_metadata_discovery=True) kw = dict(file=upload_file, synchronous_metadata_discovery=True)
document_002 = self.portal.Base_contribute(**kw) document_002 = self.portal.Base_contribute(**kw)
document_002.publish() document_002.publish()
...@@ -2905,7 +2912,7 @@ return 1 ...@@ -2905,7 +2912,7 @@ return 1
self.tic() self.tic()
def testFileWithNotDefinedMimeType(self): def testFileWithNotDefinedMimeType(self):
upload_file = makeFileUpload('TEST-001-en.dummy') upload_file = self.makeFileUpload('TEST-001-en.dummy')
kw = dict(file=upload_file, synchronous_metadata_discovery=True, kw = dict(file=upload_file, synchronous_metadata_discovery=True,
portal_type='File') portal_type='File')
document = self.portal.Base_contribute(**kw) document = self.portal.Base_contribute(**kw)
...@@ -2922,7 +2929,7 @@ return 1 ...@@ -2922,7 +2929,7 @@ return 1
Checks Base_getRelatedDocumentList works correctly with both Checks Base_getRelatedDocumentList works correctly with both
related (follow_up) Documents and with sub-object Embedded Files related (follow_up) Documents and with sub-object Embedded Files
""" """
uploaded_file = makeFileUpload('TEST-001-en.dummy') uploaded_file = self.makeFileUpload('TEST-001-en.dummy')
document_value = self.portal.Base_contribute( document_value = self.portal.Base_contribute(
file=uploaded_file, file=uploaded_file,
synchronous_metadata_discovery=True, synchronous_metadata_discovery=True,
...@@ -2973,7 +2980,7 @@ class TestDocumentWithSecurity(TestDocumentMixin): ...@@ -2973,7 +2980,7 @@ class TestDocumentWithSecurity(TestDocumentMixin):
Make sure that uploader can preview document after submitted. Make sure that uploader can preview document after submitted.
""" """
filename = 'REF-en-001.odt' filename = 'REF-en-001.odt'
upload_file = makeFileUpload(filename) upload_file = self.makeFileUpload(filename)
document = self.portal.portal_contributions.newContent(file=upload_file) document = self.portal.portal_contributions.newContent(file=upload_file)
self.tic() self.tic()
...@@ -2996,9 +3003,8 @@ class TestDocumentWithSecurity(TestDocumentMixin): ...@@ -2996,9 +3003,8 @@ class TestDocumentWithSecurity(TestDocumentMixin):
text_document = document_module.newContent(portal_type=portal_type, text_document = document_module.newContent(portal_type=portal_type,
reference='Foo_001', reference='Foo_001',
title='Foo_OO1') title='Foo_OO1')
f = makeFileUpload('Foo_001.odt') f = self.makeFileUpload('Foo_001.odt')
text_document.edit(file=f) text_document.edit(file=f)
f.close()
self.tic() self.tic()
# the document should be automatically converted to html # the document should be automatically converted to html
...@@ -3068,14 +3074,14 @@ class TestDocumentWithSecurity(TestDocumentMixin): ...@@ -3068,14 +3074,14 @@ class TestDocumentWithSecurity(TestDocumentMixin):
def test_mergeRevision(self): def test_mergeRevision(self):
document1 = self.portal.portal_contributions.newContent( document1 = self.portal.portal_contributions.newContent(
file=makeFileUpload('TEST-en-002.doc')) file=self.makeFileUpload('TEST-en-002.doc'))
self.tic() self.tic()
self.assertEqual( self.assertEqual(
(document1.getReference(), document1.getLanguage(), document1.getVersion()), (document1.getReference(), document1.getLanguage(), document1.getVersion()),
('TEST', 'en', '002')) ('TEST', 'en', '002'))
self.assertNotIn('This document is modified', document1.asText()) self.assertNotIn('This document is modified', document1.asText())
document2 = self.portal.portal_contributions.newContent( document2 = self.portal.portal_contributions.newContent(
file=makeFileUpload('TEST-en-002-modified.doc')) file=self.makeFileUpload('TEST-en-002-modified.doc'))
self.tic() self.tic()
self.assertIn('This document is modified', document2.asText()) self.assertIn('This document is modified', document2.asText())
self.assertEqual( self.assertEqual(
...@@ -3094,7 +3100,7 @@ class TestDocumentWithSecurity(TestDocumentMixin): ...@@ -3094,7 +3100,7 @@ class TestDocumentWithSecurity(TestDocumentMixin):
with self.assertRaisesRegex( with self.assertRaisesRegex(
Unauthorized, Unauthorized,
"You are not allowed to update the existing document"): "You are not allowed to update the existing document"):
self.portal.portal_contributions.newContent(file=makeFileUpload('TEST-en-002.doc')) self.portal.portal_contributions.newContent(file=self.makeFileUpload('TEST-en-002.doc'))
# this also works with another user which can not see the document # this also works with another user which can not see the document
another_user_id = self.id() another_user_id = self.id()
...@@ -3104,7 +3110,7 @@ class TestDocumentWithSecurity(TestDocumentMixin): ...@@ -3104,7 +3110,7 @@ class TestDocumentWithSecurity(TestDocumentMixin):
with self.assertRaisesRegex( with self.assertRaisesRegex(
Unauthorized, Unauthorized,
"You are not allowed to update the existing document"): "You are not allowed to update the existing document"):
self.portal.portal_contributions.newContent(file=makeFileUpload('TEST-en-002.doc')) self.portal.portal_contributions.newContent(file=self.makeFileUpload('TEST-en-002.doc'))
def test_mergeRevision_with_node_reference_local_reference_filename_regular_expression(self): def test_mergeRevision_with_node_reference_local_reference_filename_regular_expression(self):
# this filename regular expression comes from configurator # this filename regular expression comes from configurator
...@@ -3113,14 +3119,14 @@ class TestDocumentWithSecurity(TestDocumentMixin): ...@@ -3113,14 +3119,14 @@ class TestDocumentWithSecurity(TestDocumentMixin):
) )
self.tic() self.tic()
document1 = self.portal.portal_contributions.newContent( document1 = self.portal.portal_contributions.newContent(
file=makeFileUpload('TEST-en-002.doc', as_name='P-PROJ-TEST-002-en.doc')) file=self.makeFileUpload('TEST-en-002.doc', as_name='P-PROJ-TEST-002-en.doc'))
self.tic() self.tic()
self.assertEqual( self.assertEqual(
(document1.getReference(), document1.getLanguage(), document1.getVersion()), (document1.getReference(), document1.getLanguage(), document1.getVersion()),
('P-PROJ-TEST', 'en', '002')) ('P-PROJ-TEST', 'en', '002'))
self.assertNotIn('This document is modified', document1.asText()) self.assertNotIn('This document is modified', document1.asText())
document2 = self.portal.portal_contributions.newContent( document2 = self.portal.portal_contributions.newContent(
file=makeFileUpload('TEST-en-002-modified.doc', as_name='P-PROJ-TEST-002-en.doc')) file=self.makeFileUpload('TEST-en-002-modified.doc', as_name='P-PROJ-TEST-002-en.doc'))
self.tic() self.tic()
self.assertIn('This document is modified', document2.asText()) self.assertIn('This document is modified', document2.asText())
self.assertEqual( self.assertEqual(
...@@ -3140,7 +3146,7 @@ class TestDocumentWithSecurity(TestDocumentMixin): ...@@ -3140,7 +3146,7 @@ class TestDocumentWithSecurity(TestDocumentMixin):
Unauthorized, Unauthorized,
"You are not allowed to update the existing document"): "You are not allowed to update the existing document"):
self.portal.portal_contributions.newContent( self.portal.portal_contributions.newContent(
file=makeFileUpload('TEST-en-002.doc', as_name='P-PROJ-TEST-002-en.doc')) file=self.makeFileUpload('TEST-en-002.doc', as_name='P-PROJ-TEST-002-en.doc'))
# this also works with another user which can not see the document # this also works with another user which can not see the document
another_user_id = self.id() another_user_id = self.id()
...@@ -3151,7 +3157,7 @@ class TestDocumentWithSecurity(TestDocumentMixin): ...@@ -3151,7 +3157,7 @@ class TestDocumentWithSecurity(TestDocumentMixin):
Unauthorized, Unauthorized,
"You are not allowed to update the existing document"): "You are not allowed to update the existing document"):
self.portal.portal_contributions.newContent( self.portal.portal_contributions.newContent(
file=makeFileUpload('TEST-en-002.doc', as_name='P-PROJ-TEST-002-en.doc')) file=self.makeFileUpload('TEST-en-002.doc', as_name='P-PROJ-TEST-002-en.doc'))
class TestDocumentPerformance(TestDocumentMixin): class TestDocumentPerformance(TestDocumentMixin):
...@@ -3161,7 +3167,7 @@ class TestDocumentPerformance(TestDocumentMixin): ...@@ -3161,7 +3167,7 @@ class TestDocumentPerformance(TestDocumentMixin):
Test large OOoDocument to image conversion Test large OOoDocument to image conversion
""" """
ooo_document = self.portal.document_module.newContent(portal_type='Spreadsheet') ooo_document = self.portal.document_module.newContent(portal_type='Spreadsheet')
upload_file = makeFileUpload('import_big_spreadsheet.ods') upload_file = self.makeFileUpload('import_big_spreadsheet.ods')
ooo_document.edit(file=upload_file) ooo_document.edit(file=upload_file)
self.tic() self.tic()
before = time.time() before = time.time()
...@@ -3180,7 +3186,7 @@ class TestDocumentPerformance(TestDocumentMixin): ...@@ -3180,7 +3186,7 @@ class TestDocumentPerformance(TestDocumentMixin):
req_time) req_time)
class DocumentConsistencyTestCase(ERP5TypeTestCase): class DocumentConsistencyTestCase(DocumentUploadTestCase):
portal_type = NotImplemented portal_type = NotImplemented
content_type = NotImplemented content_type = NotImplemented
filename = NotImplemented filename = NotImplemented
...@@ -3190,7 +3196,7 @@ class DocumentConsistencyTestCase(ERP5TypeTestCase): ...@@ -3190,7 +3196,7 @@ class DocumentConsistencyTestCase(ERP5TypeTestCase):
def afterSetUp(self): def afterSetUp(self):
self.document = self._getDocumentModule().newContent(portal_type=self.portal_type) self.document = self._getDocumentModule().newContent(portal_type=self.portal_type)
self.file_upload = makeFileUpload(self.filename) self.file_upload = self.makeFileUpload(self.filename)
with open(makeFilePath(self.filename), 'rb') as f: with open(makeFilePath(self.filename), 'rb') as f:
self.file_data = f.read() self.file_data = f.read()
self.file_size = len(self.file_data) self.file_size = len(self.file_data)
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
import unittest import unittest
from DateTime import DateTime from DateTime import DateTime
from erp5.component.test.testDms import TestDocumentMixin, makeFileUpload from erp5.component.test.testDms import TestDocumentMixin
try: try:
import magic import magic
...@@ -59,7 +59,7 @@ class TestDocumentConversionCache(TestDocumentMixin): ...@@ -59,7 +59,7 @@ class TestDocumentConversionCache(TestDocumentMixin):
def test_image_conversion(self): def test_image_conversion(self):
filename = 'TEST-en-002.doc' filename = 'TEST-en-002.doc'
file_ = makeFileUpload(filename) file_ = self.makeFileUpload(filename)
document = self.portal.portal_contributions.newContent(file=file_) document = self.portal.portal_contributions.newContent(file=file_)
self.tic() self.tic()
format_ = 'png' format_ = 'png'
...@@ -96,7 +96,7 @@ class TestDocumentConversionCache(TestDocumentMixin): ...@@ -96,7 +96,7 @@ class TestDocumentConversionCache(TestDocumentMixin):
Test Conversion Cache mechanism Test Conversion Cache mechanism
""" """
filename = 'TEST-en-002.doc' filename = 'TEST-en-002.doc'
file_ = makeFileUpload(filename) file_ = self.makeFileUpload(filename)
document = self.portal.portal_contributions.newContent(file=file_) document = self.portal.portal_contributions.newContent(file=file_)
self.tic() self.tic()
document_url = document.getRelativeUrl() document_url = document.getRelativeUrl()
...@@ -129,7 +129,7 @@ class TestDocumentConversionCache(TestDocumentMixin): ...@@ -129,7 +129,7 @@ class TestDocumentConversionCache(TestDocumentMixin):
def test_02_VolatileCacheConversionOfTempObject(self): def test_02_VolatileCacheConversionOfTempObject(self):
filename = 'TEST-en-002.doc' filename = 'TEST-en-002.doc'
file_ = makeFileUpload(filename) file_ = self.makeFileUpload(filename)
document = self.portal.portal_contributions.newContent(file=file_, temp_object=1) document = self.portal.portal_contributions.newContent(file=file_, temp_object=1)
document.uploadFile() document.uploadFile()
document.processFile() document.processFile()
...@@ -163,8 +163,8 @@ class TestDocumentConversionCache(TestDocumentMixin): ...@@ -163,8 +163,8 @@ class TestDocumentConversionCache(TestDocumentMixin):
def test_03_CacheConversionOfTempObjectIsNotMixed(self): def test_03_CacheConversionOfTempObjectIsNotMixed(self):
filename1 = 'TEST-en-002.doc' filename1 = 'TEST-en-002.doc'
filename2 = 'TEST-en-002.odt' filename2 = 'TEST-en-002.odt'
file1 = makeFileUpload(filename1) file1 = self.makeFileUpload(filename1)
file2 = makeFileUpload(filename2) file2 = self.makeFileUpload(filename2)
document1 = self.portal.portal_contributions.newContent(file=file1, temp_object=1) document1 = self.portal.portal_contributions.newContent(file=file1, temp_object=1)
document1.uploadFile() document1.uploadFile()
document1.processFile() document1.processFile()
...@@ -187,7 +187,7 @@ class TestDocumentConversionCache(TestDocumentMixin): ...@@ -187,7 +187,7 @@ class TestDocumentConversionCache(TestDocumentMixin):
self.portal.portal_caches.clearAllCache() self.portal.portal_caches.clearAllCache()
self.tic() self.tic()
filename = 'TEST-en-002.doc' filename = 'TEST-en-002.doc'
file_ = makeFileUpload(filename) file_ = self.makeFileUpload(filename)
document = self.portal.portal_contributions.newContent(file=file_) document = self.portal.portal_contributions.newContent(file=file_)
self.tic() self.tic()
document_url = document.getRelativeUrl() document_url = document.getRelativeUrl()
...@@ -223,7 +223,7 @@ class TestDocumentConversionCache(TestDocumentMixin): ...@@ -223,7 +223,7 @@ class TestDocumentConversionCache(TestDocumentMixin):
Test Conversion Cache return expected value with checksum Test Conversion Cache return expected value with checksum
""" """
filename = 'TEST-en-002.doc' filename = 'TEST-en-002.doc'
file_ = makeFileUpload(filename) file_ = self.makeFileUpload(filename)
document = self.portal.portal_contributions.newContent(file=file_) document = self.portal.portal_contributions.newContent(file=file_)
self.tic() self.tic()
document_url = document.getRelativeUrl() document_url = document.getRelativeUrl()
...@@ -252,7 +252,7 @@ class TestDocumentConversionCache(TestDocumentMixin): ...@@ -252,7 +252,7 @@ class TestDocumentConversionCache(TestDocumentMixin):
Check that md5 checksum is well updated when upload a file Check that md5 checksum is well updated when upload a file
""" """
filename = 'TEST-en-002.doc' filename = 'TEST-en-002.doc'
file_ = makeFileUpload(filename) file_ = self.makeFileUpload(filename)
document = self.portal.portal_contributions.newContent(file=file_) document = self.portal.portal_contributions.newContent(file=file_)
self.tic() self.tic()
document_url = document.getRelativeUrl() document_url = document.getRelativeUrl()
...@@ -260,7 +260,7 @@ class TestDocumentConversionCache(TestDocumentMixin): ...@@ -260,7 +260,7 @@ class TestDocumentConversionCache(TestDocumentMixin):
md5sum = document.getContentMd5() md5sum = document.getContentMd5()
self.assertTrue(md5sum) self.assertTrue(md5sum)
filename2 = 'TEST-en-002.odt' filename2 = 'TEST-en-002.odt'
file2 = makeFileUpload(filename2) file2 = self.makeFileUpload(filename2)
document.edit(file=file2) document.edit(file=file2)
self.assertNotEqual(md5sum, document.getContentMd5()) self.assertNotEqual(md5sum, document.getContentMd5())
self.tic() self.tic()
...@@ -275,7 +275,7 @@ class TestDocumentConversionCache(TestDocumentMixin): ...@@ -275,7 +275,7 @@ class TestDocumentConversionCache(TestDocumentMixin):
self.portal.portal_caches.clearAllCache() self.portal.portal_caches.clearAllCache()
self.tic() self.tic()
filename = 'TEST-en-002.doc' filename = 'TEST-en-002.doc'
file_ = makeFileUpload(filename) file_ = self.makeFileUpload(filename)
document_id = 'an id with spaces' document_id = 'an id with spaces'
portal_type = 'Text' portal_type = 'Text'
module = self.portal.getDefaultModule(portal_type) module = self.portal.getDefaultModule(portal_type)
...@@ -314,7 +314,7 @@ class TestDocumentConversionCache(TestDocumentMixin): ...@@ -314,7 +314,7 @@ class TestDocumentConversionCache(TestDocumentMixin):
self.assertEqual(len(portal_type_list), len([pt for pt in portal_type_list if pt in data_mapping])) self.assertEqual(len(portal_type_list), len([pt for pt in portal_type_list if pt in data_mapping]))
for portal_type in portal_type_list: for portal_type in portal_type_list:
module = self.portal.getDefaultModule(portal_type=portal_type) module = self.portal.getDefaultModule(portal_type=portal_type)
upload_file = makeFileUpload(data_mapping[portal_type]) upload_file = self.makeFileUpload(data_mapping[portal_type])
document = module.newContent(portal_type=portal_type) document = module.newContent(portal_type=portal_type)
document.edit(file=upload_file) document.edit(file=upload_file)
self.tic() self.tic()
......
...@@ -25,12 +25,11 @@ ...@@ -25,12 +25,11 @@
# #
############################################################################## ##############################################################################
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from erp5.component.test.testDms import DocumentUploadTestCase
from erp5.component.test.testDms import makeFileUpload
from Products.ERP5Form.PreferenceTool import Priority from Products.ERP5Form.PreferenceTool import Priority
class TestOOoConversionServerRetry(ERP5TypeTestCase): class TestOOoConversionServerRetry(DocumentUploadTestCase):
def getBusinessTemplateList(self): def getBusinessTemplateList(self):
business_template_list = ['erp5_core_proxy_field_legacy', business_template_list = ['erp5_core_proxy_field_legacy',
'erp5_jquery', 'erp5_jquery',
...@@ -80,7 +79,7 @@ class TestOOoConversionServerRetry(ERP5TypeTestCase): ...@@ -80,7 +79,7 @@ class TestOOoConversionServerRetry(ERP5TypeTestCase):
self.tic() self.tic()
filename = 'monochrome_sample.tiff' filename = 'monochrome_sample.tiff'
file_ = makeFileUpload(filename) file_ = self.makeFileUpload(filename)
document = self.portal.document_module.newContent(portal_type='Text') document = self.portal.document_module.newContent(portal_type='Text')
document.edit(file = file_) document.edit(file = file_)
message = document.Document_tryToConvertToBaseFormat() message = document.Document_tryToConvertToBaseFormat()
...@@ -95,7 +94,7 @@ class TestOOoConversionServerRetry(ERP5TypeTestCase): ...@@ -95,7 +94,7 @@ class TestOOoConversionServerRetry(ERP5TypeTestCase):
system_pref.setPreferredDocumentConversionServerUrlList(['https://broken.url']) system_pref.setPreferredDocumentConversionServerUrlList(['https://broken.url'])
self.tic() self.tic()
filename = 'TEST-en-002.doc' filename = 'TEST-en-002.doc'
file_ = makeFileUpload(filename) file_ = self.makeFileUpload(filename)
document = self.portal.portal_contributions.newContent(file=file_) document = self.portal.portal_contributions.newContent(file=file_)
message = document.Document_tryToConvertToBaseFormat() message = document.Document_tryToConvertToBaseFormat()
...@@ -110,7 +109,7 @@ class TestOOoConversionServerRetry(ERP5TypeTestCase): ...@@ -110,7 +109,7 @@ class TestOOoConversionServerRetry(ERP5TypeTestCase):
system_pref.setPreferredOoodocServerTimeout(1) system_pref.setPreferredOoodocServerTimeout(1)
self.tic() self.tic()
filename = 'TEST-en-002.doc' filename = 'TEST-en-002.doc'
file_ = makeFileUpload(filename) file_ = self.makeFileUpload(filename)
document = self.portal.portal_contributions.newContent(file=file_) document = self.portal.portal_contributions.newContent(file=file_)
message = document.Document_tryToConvertToBaseFormat() message = document.Document_tryToConvertToBaseFormat()
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
############################################################################## ##############################################################################
import unittest import unittest
from erp5.component.test.testDms import TestDocument, makeFileUpload from erp5.component.test.testDms import TestDocument
class TestDocumentWithPreConversion(TestDocument): class TestDocumentWithPreConversion(TestDocument):
""" """
...@@ -40,7 +40,7 @@ class TestDocumentWithPreConversion(TestDocument): ...@@ -40,7 +40,7 @@ class TestDocumentWithPreConversion(TestDocument):
def test_preConvertedReferencedImageInWebPageContent(self): def test_preConvertedReferencedImageInWebPageContent(self):
# create an image # create an image
upload_file = makeFileUpload('cmyk_sample.jpg') upload_file = self.makeFileUpload('cmyk_sample.jpg')
image = self.portal.image_module.newContent(portal_type='Image', image = self.portal.image_module.newContent(portal_type='Image',
reference='Embedded-XXX', reference='Embedded-XXX',
version='001', version='001',
...@@ -75,7 +75,7 @@ class TestDocumentWithPreConversion(TestDocument): ...@@ -75,7 +75,7 @@ class TestDocumentWithPreConversion(TestDocument):
language='en') language='en')
# draft image is not convertible # draft image is not convertible
upload_file = makeFileUpload('cmyk_sample.jpg') upload_file = self.makeFileUpload('cmyk_sample.jpg')
image.edit(file=upload_file) image.edit(file=upload_file)
self.tic() self.tic()
self.assertEqual(False, image.Base_isConvertible()) self.assertEqual(False, image.Base_isConvertible())
......
...@@ -31,7 +31,7 @@ import unittest ...@@ -31,7 +31,7 @@ import unittest
from unittest import expectedFailure from unittest import expectedFailure
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from Products.ERP5Type.Base import TempBase from Products.ERP5Type.Base import TempBase
from erp5.component.test.testDms import makeFileUpload, TestDocumentMixin from erp5.component.test.testDms import TestDocumentMixin
def _getGadgetInstanceUrlFromKnowledgePad(knowledge_pad, gadget): def _getGadgetInstanceUrlFromKnowledgePad(knowledge_pad, gadget):
""" Get Knowledge Box's relative URL specialising a gadget in a Knowledge Pad.""" """ Get Knowledge Box's relative URL specialising a gadget in a Knowledge Pad."""
...@@ -39,6 +39,7 @@ def _getGadgetInstanceUrlFromKnowledgePad(knowledge_pad, gadget): ...@@ -39,6 +39,7 @@ def _getGadgetInstanceUrlFromKnowledgePad(knowledge_pad, gadget):
portal_type = 'Knowledge Box', portal_type = 'Knowledge Box',
specialise_uid = gadget.getUid())[0].getObject().getRelativeUrl() specialise_uid = gadget.getUid())[0].getObject().getRelativeUrl()
class TestKMMixIn(TestDocumentMixin): class TestKMMixIn(TestDocumentMixin):
""" """
Mix in class for Knowledge Management system. Mix in class for Knowledge Management system.
...@@ -1008,38 +1009,38 @@ class TestKMSearch(TestKMMixIn): ...@@ -1008,38 +1009,38 @@ class TestKMSearch(TestKMMixIn):
# create docs to be referenced: # create docs to be referenced:
# (1) TEST, 002, en # (1) TEST, 002, en
filename = 'TEST-en-002.odt' filename = 'TEST-en-002.odt'
file_ = makeFileUpload(filename) file_ = self.makeFileUpload(filename)
self.portal.portal_contributions.newContent(file=file_) self.portal.portal_contributions.newContent(file=file_)
# (2) TEST, 002, fr # (2) TEST, 002, fr
as_name = 'TEST-fr-002.odt' as_name = 'TEST-fr-002.odt'
file_ = makeFileUpload(filename, as_name) file_ = self.makeFileUpload(filename, as_name)
document2 = self.portal.portal_contributions.newContent(file=file_) document2 = self.portal.portal_contributions.newContent(file=file_)
# (3) TEST, 003, en # (3) TEST, 003, en
as_name = 'TEST-en-003.odt' as_name = 'TEST-en-003.odt'
file_ = makeFileUpload(filename, as_name) file_ = self.makeFileUpload(filename, as_name)
document3 = self.portal.portal_contributions.newContent(file=file_) document3 = self.portal.portal_contributions.newContent(file=file_)
# create docs to contain references in text_content: # create docs to contain references in text_content:
# REF, 002, en; "I use reference to look up TEST" # REF, 002, en; "I use reference to look up TEST"
filename = 'REF-en-002.odt' filename = 'REF-en-002.odt'
file_ = makeFileUpload(filename) file_ = self.makeFileUpload(filename)
document5 = self.portal.portal_contributions.newContent(file=file_) document5 = self.portal.portal_contributions.newContent(file=file_)
# REFLANG, 001, en: "I use reference and language to look up TEST-fr" # REFLANG, 001, en: "I use reference and language to look up TEST-fr"
#filename = 'REFLANG-en-001.odt' #filename = 'REFLANG-en-001.odt'
#file = makeFileUpload(filename) #file = self.makeFileUpload(filename)
#document6 = self.portal.portal_contributions.newContent(file=file) #document6 = self.portal.portal_contributions.newContent(file=file)
# REFVER, 001, en: "I use reference and version to look up TEST-002" # REFVER, 001, en: "I use reference and version to look up TEST-002"
#filename = 'REFVER-en-001.odt' #filename = 'REFVER-en-001.odt'
#file = makeFileUpload(filename) #file = self.makeFileUpload(filename)
#document7 = self.portal.portal_contributions.newContent(file=file) #document7 = self.portal.portal_contributions.newContent(file=file)
# REFVERLANG, 001, en: "I use reference, version and language to look up TEST-002-en" # REFVERLANG, 001, en: "I use reference, version and language to look up TEST-002-en"
#filename = 'REFVERLANG-en-001.odt' #filename = 'REFVERLANG-en-001.odt'
#file = makeFileUpload(filename) #file = self.makeFileUpload(filename)
#document8 = self.portal.portal_contributions.newContent(file=file) #document8 = self.portal.portal_contributions.newContent(file=file)
self.tic() self.tic()
......
...@@ -26,14 +26,13 @@ ...@@ -26,14 +26,13 @@
############################################################################## ##############################################################################
import warnings import warnings
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from erp5.component.test.testDms import DocumentUploadTestCase
from erp5.component.test.testDms import makeFileUpload
original_warnings_showwarnings = warnings.showwarning original_warnings_showwarnings = warnings.showwarning
class TestERP5PDFMerge(ERP5TypeTestCase): class TestERP5PDFMerge(DocumentUploadTestCase):
def test_showwarning_issue(self): def test_showwarning_issue(self):
""" """
...@@ -42,7 +41,7 @@ class TestERP5PDFMerge(ERP5TypeTestCase): ...@@ -42,7 +41,7 @@ class TestERP5PDFMerge(ERP5TypeTestCase):
""" """
self.assertEqual(warnings.showwarning, original_warnings_showwarnings) self.assertEqual(warnings.showwarning, original_warnings_showwarnings)
document = self.portal.portal_contributions.newContent( document = self.portal.portal_contributions.newContent(
file=makeFileUpload('REF-en-001.pdf')) file=self.makeFileUpload('REF-en-001.pdf'))
merged_pdf_data = self.portal.ERP5Site_mergePDFList( merged_pdf_data = self.portal.ERP5Site_mergePDFList(
[document.getData(), document.getData()]) [document.getData(), document.getData()])
self.portal.document_module.newContent( self.portal.document_module.newContent(
...@@ -53,7 +52,7 @@ class TestERP5PDFMerge(ERP5TypeTestCase): ...@@ -53,7 +52,7 @@ class TestERP5PDFMerge(ERP5TypeTestCase):
def test_erp5_merge_pdf(self): def test_erp5_merge_pdf(self):
document = self.portal.portal_contributions.newContent( document = self.portal.portal_contributions.newContent(
file=makeFileUpload('REF-en-001.pdf')) file=self.makeFileUpload('REF-en-001.pdf'))
merged_pdf_data = self.portal.ERP5Site_mergePDFList( merged_pdf_data = self.portal.ERP5Site_mergePDFList(
[document.getData(), document.getData()]) [document.getData(), document.getData()])
merged_document = self.portal.document_module.newContent( merged_document = self.portal.document_module.newContent(
...@@ -63,7 +62,7 @@ class TestERP5PDFMerge(ERP5TypeTestCase): ...@@ -63,7 +62,7 @@ class TestERP5PDFMerge(ERP5TypeTestCase):
def test_erp5_merge_pdf_start_on_recto(self): def test_erp5_merge_pdf_start_on_recto(self):
document = self.portal.portal_contributions.newContent( document = self.portal.portal_contributions.newContent(
file=makeFileUpload('REF-en-001.pdf')) file=self.makeFileUpload('REF-en-001.pdf'))
merged_pdf_data = self.portal.ERP5Site_mergePDFList( merged_pdf_data = self.portal.ERP5Site_mergePDFList(
[document.getData(), document.getData()], start_on_recto=True) [document.getData(), document.getData()], start_on_recto=True)
merged_document = self.portal.document_module.newContent( merged_document = self.portal.document_module.newContent(
......
...@@ -26,12 +26,12 @@ ...@@ -26,12 +26,12 @@
# #
############################################################################## ##############################################################################
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from erp5.component.test.testDms import DocumentUploadTestCase
from erp5.component.test.testDms import makeFileUpload
from time import time from time import time
import base64 import base64
class TestRunMyDoc(ERP5TypeTestCase):
class TestRunMyDoc(DocumentUploadTestCase):
""" """
Basic Test for internal implementation of RunMyDocs Basic Test for internal implementation of RunMyDocs
""" """
...@@ -96,7 +96,7 @@ class TestRunMyDoc(ERP5TypeTestCase): ...@@ -96,7 +96,7 @@ class TestRunMyDoc(ERP5TypeTestCase):
Test Screeshot upload script used by Zelenium to Test Screeshot upload script used by Zelenium to
update screenshots of the documents. update screenshots of the documents.
""" """
image_upload = makeFileUpload('TEST-en-002.png') image_upload = self.makeFileUpload('TEST-en-002.png')
self.assertNotEqual(None, image_upload) self.assertNotEqual(None, image_upload)
# Create a web page, and check if the content is not overwriten # Create a web page, and check if the content is not overwriten
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment