Commit 227402e3 authored by Arnaud Fontaine's avatar Arnaud Fontaine

ZODB Components: erp5_dms: Migrate ExternalSource and erp5_dms-related Unit Tests from filesystem.

parent 431f8484
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
import unittest import unittest
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5OOo.tests.testDms import makeFileUpload from erp5.component.test.testDms import makeFileUpload
class TestERP5Discussion(ERP5TypeTestCase): class TestERP5Discussion(ERP5TypeTestCase):
...@@ -59,7 +59,7 @@ class TestERP5Discussion(ERP5TypeTestCase): ...@@ -59,7 +59,7 @@ class TestERP5Discussion(ERP5TypeTestCase):
'erp5_jquery', 'erp5_jquery',
'erp5_discussion', ) 'erp5_discussion', )
def login(self): def login(self, *args, **kw):
uf = self.getPortal().acl_users uf = self.getPortal().acl_users
uf._doAddUser(self.manager_username, self.manager_password, ['Manager'], []) uf._doAddUser(self.manager_username, self.manager_password, ['Manager'], [])
user = uf.getUserById(self.manager_username).__of__(uf) user = uf.getUserById(self.manager_username).__of__(uf)
...@@ -87,7 +87,7 @@ class TestERP5Discussion(ERP5TypeTestCase): ...@@ -87,7 +87,7 @@ class TestERP5Discussion(ERP5TypeTestCase):
def test_01_createDiscussionThread(self): def test_01_createDiscussionThread(self):
"""Create a new discussion thread""" """Create a new discussion thread"""
self.stepCreateThread(); self.stepCreateThread()
self.tic() self.tic()
def test_02_createDiscussionPost(self): def test_02_createDiscussionPost(self):
...@@ -143,8 +143,8 @@ class TestERP5Discussion(ERP5TypeTestCase): ...@@ -143,8 +143,8 @@ 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_ = 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]
discussion_thread_id_set.add(discussion_thread.getId()) discussion_thread_id_set.add(discussion_thread.getId())
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Test Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testERP5Discussion</string> </value>
</item>
<item>
<key> <string>default_source_reference</string> </key>
<value> <string>Products.ERP5.tests.testERP5Discussion</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testERP5Discussion</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Test Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
test.erp5.testERP5Discussion
\ No newline at end of file
erp5_full_text_mroonga_catalog
erp5_ingestion_mysql_innodb_catalog
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Document Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>default_reference</string> </key>
<value> <string>ExternalSource</string> </value>
</item>
<item>
<key> <string>default_source_reference</string> </key>
<value> <string>Products.ERP5.Document.ExternalSource</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>document.erp5.ExternalSource</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Document Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -57,7 +57,6 @@ from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase ...@@ -57,7 +57,6 @@ 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
from Products.ERP5OOo.OOoUtils import OOoBuilder from Products.ERP5OOo.OOoUtils import OOoBuilder
from Products.CMFCore.utils import getToolByName
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from AccessControl import getSecurityManager from AccessControl import getSecurityManager
from Products.ERP5.Document.Document import NotConvertedError from Products.ERP5.Document.Document import NotConvertedError
...@@ -77,12 +76,13 @@ from ZTUtils import make_query ...@@ -77,12 +76,13 @@ from ZTUtils import make_query
QUIET = 0 QUIET = 0
TEST_FILES_HOME = os.path.join(os.path.dirname(__file__), 'test_document') from Products.ERP5OOo import tests
TEST_FILES_HOME = os.path.join(tests.__path__[0], 'test_document')
FILENAME_REGULAR_EXPRESSION = "(?P<reference>[A-Z]{3,10})-(?P<language>[a-z]{2})-(?P<version>[0-9]{3})" FILENAME_REGULAR_EXPRESSION = "(?P<reference>[A-Z]{3,10})-(?P<language>[a-z]{2})-(?P<version>[0-9]{3})"
REFERENCE_REGULAR_EXPRESSION = "(?P<reference>[A-Z]{3,10})(-(?P<language>[a-z]{2}))?(-(?P<version>[0-9]{3}))?" REFERENCE_REGULAR_EXPRESSION = "(?P<reference>[A-Z]{3,10})(-(?P<language>[a-z]{2}))?(-(?P<version>[0-9]{3}))?"
def makeFilePath(name): def makeFilePath(name):
return os.path.join(os.path.dirname(__file__), 'test_document', name) return os.path.join(TEST_FILES_HOME, name)
def makeFileUpload(name, as_name=None): def makeFileUpload(name, as_name=None):
if as_name is None: if as_name is None:
...@@ -120,14 +120,14 @@ class TestDocumentMixin(ERP5TypeTestCase): ...@@ -120,14 +120,14 @@ class TestDocumentMixin(ERP5TypeTestCase):
def setSystemPreference(self): def setSystemPreference(self):
pref = self.getDefaultSystemPreference() pref = self.getDefaultSystemPreference()
id = self.__class__.__name__ id_ = self.__class__.__name__
if pref.getPreferredConversionCacheFactory() != id: if pref.getPreferredConversionCacheFactory() != id_:
try: try:
self.portal.portal_caches[id] self.portal.portal_caches[id_]
except KeyError: except KeyError:
self.setCacheFactory( self.setCacheFactory(
self.portal.portal_caches.newContent(id, 'Cache Factory')) self.portal.portal_caches.newContent(id_, 'Cache Factory'))
pref.setPreferredConversionCacheFactory(id) pref.setPreferredConversionCacheFactory(id_)
pref.setPreferredDocumentFilenameRegularExpression(FILENAME_REGULAR_EXPRESSION) pref.setPreferredDocumentFilenameRegularExpression(FILENAME_REGULAR_EXPRESSION)
pref.setPreferredDocumentReferenceRegularExpression(REFERENCE_REGULAR_EXPRESSION) pref.setPreferredDocumentReferenceRegularExpression(REFERENCE_REGULAR_EXPRESSION)
...@@ -209,13 +209,13 @@ class TestDocument(TestDocumentMixin): ...@@ -209,13 +209,13 @@ class TestDocument(TestDocumentMixin):
doctext.setLanguage(language) doctext.setLanguage(language)
return doctext return doctext
def getDocument(self, id): def getDocument(self, id_):
""" """
Returns a document with given ID in the Returns a document with given ID in the
document module. document module.
""" """
document_module = self.portal.document_module document_module = self.portal.document_module
return getattr(document_module, id) return getattr(document_module, id_)
def getPreferences(self, image_display): def getPreferences(self, image_display):
preference_tool = self.portal.portal_preferences preference_tool = self.portal.portal_preferences
...@@ -228,10 +228,10 @@ class TestDocument(TestDocumentMixin): ...@@ -228,10 +228,10 @@ 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&__ac=%s' %(uri, make_query(kw), 'RVJQNVR5cGVUZXN0Q2FzZTo%3D')
format=kw.get('format', 'jpeg') format_=kw.get('format', 'jpeg')
infile = urllib.urlopen(url) infile = urllib.urlopen(url)
# 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_)
f = open(filename, "w") f = open(filename, "w")
image_data = infile.read() image_data = infile.read()
f.write(image_data) f.write(image_data)
...@@ -245,8 +245,7 @@ class TestDocument(TestDocumentMixin): ...@@ -245,8 +245,7 @@ class TestDocument(TestDocumentMixin):
except ImportError: except ImportError:
identify_output = Popen(['identify', filename], identify_output = Popen(['identify', filename],
stdout=PIPE).communicate()[0] stdout=PIPE).communicate()[0]
image_size = tuple(map(lambda x:int(x), image_size = tuple([int(x) for x in identify_output.split()[2].split('x')])
identify_output.split()[2].split('x')))
os.remove(filename) os.remove(filename)
return image_size, file_size return image_size, file_size
...@@ -277,20 +276,20 @@ class TestDocument(TestDocumentMixin): ...@@ -277,20 +276,20 @@ 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_ = 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()
def getTestDocument(): def getTestDocument():
return self.portal.restrictedTraverse(document_url) return self.portal.restrictedTraverse(document_url)
self.assertEqual(getTestDocument().getRevision(), '1') self.assertEqual(getTestDocument().getRevision(), '1')
getTestDocument().edit(file=file) getTestDocument().edit(file=file_)
self.tic() self.tic()
self.assertEqual(getTestDocument().getRevision(), '2') self.assertEqual(getTestDocument().getRevision(), '2')
getTestDocument().edit(title='Hey Joe') getTestDocument().edit(title='Hey Joe')
self.tic() self.tic()
self.assertEqual(getTestDocument().getRevision(), '3') self.assertEqual(getTestDocument().getRevision(), '3')
another_document = self.portal.portal_contributions.newContent(file=file) self.portal.portal_contributions.newContent(file=file_)
self.tic() self.tic()
self.assertEqual(getTestDocument().getRevision(), '4') self.assertEqual(getTestDocument().getRevision(), '4')
self.assertEqual(getTestDocument().getRevisionList(), ['1', '2', '3', '4']) self.assertEqual(getTestDocument().getRevisionList(), ['1', '2', '3', '4'])
...@@ -307,7 +306,6 @@ class TestDocument(TestDocumentMixin): ...@@ -307,7 +306,6 @@ class TestDocument(TestDocumentMixin):
# run isVersionUnique on 1, 2, 3 (should return True) # run isVersionUnique on 1, 2, 3 (should return True)
# run getLatestVersionValue on all (should return 3) # run getLatestVersionValue on all (should return 3)
# run getVersionValueList on 2 (should return [3, 2, 1]) # run getVersionValueList on 2 (should return [3, 2, 1])
document_module = self.getDocumentModule()
docs = {} docs = {}
docs[1] = self.createTestDocument(reference='TEST', version='002', language='en') docs[1] = self.createTestDocument(reference='TEST', version='002', language='en')
docs[2] = self.createTestDocument(reference='TEST', version='002', language='en') docs[2] = self.createTestDocument(reference='TEST', version='002', language='en')
...@@ -401,7 +399,6 @@ class TestDocument(TestDocumentMixin): ...@@ -401,7 +399,6 @@ class TestDocument(TestDocumentMixin):
# reference, version, language # reference, version, language
kw = {'portal_type': 'Drawing'} kw = {'portal_type': 'Drawing'}
document1 = self.portal.document_module.newContent(**kw) document1 = self.portal.document_module.newContent(**kw)
document2 = self.portal.document_module.newContent(**kw)
document3 = self.portal.document_module.newContent(**kw) document3 = self.portal.document_module.newContent(**kw)
document4 = self.portal.document_module.newContent(**kw) document4 = self.portal.document_module.newContent(**kw)
document5 = self.portal.document_module.newContent(**kw) document5 = self.portal.document_module.newContent(**kw)
...@@ -491,44 +488,39 @@ class TestDocument(TestDocumentMixin): ...@@ -491,44 +488,39 @@ 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_ = 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_ = 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_ = 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, 001, en; "I use reference to look up TEST"
filename = 'REF-en-001.odt'
file = makeFileUpload(filename)
document4 = self.portal.portal_contributions.newContent(file=file)
# 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_ = 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_ = 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_ = 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_ = makeFileUpload(filename)
document8 = self.portal.portal_contributions.newContent(file=file) document8 = self.portal.portal_contributions.newContent(file=file_)
self.tic() self.tic()
# the implicit predecessor will find documents by reference. # the implicit predecessor will find documents by reference.
...@@ -691,8 +683,8 @@ class TestDocument(TestDocumentMixin): ...@@ -691,8 +683,8 @@ class TestDocument(TestDocumentMixin):
is not draft is not draft
""" """
filename = 'TEST-en-002.doc' filename = 'TEST-en-002.doc'
file = makeFileUpload(filename) file_ = 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())
self.commit() self.commit()
...@@ -756,8 +748,8 @@ class TestDocument(TestDocumentMixin): ...@@ -756,8 +748,8 @@ class TestDocument(TestDocumentMixin):
document. document.
""" """
filename = 'EmbeddedImage-en-002.odt' filename = 'EmbeddedImage-en-002.odt'
file = makeFileUpload(filename) file_ = makeFileUpload(filename)
document = self.portal.portal_contributions.newContent(file=file) document = self.portal.portal_contributions.newContent(file=file_)
self.tic() self.tic()
...@@ -1255,9 +1247,9 @@ class TestDocument(TestDocumentMixin): ...@@ -1255,9 +1247,9 @@ class TestDocument(TestDocumentMixin):
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_type, image_data = document.convert(format='png', _, image_data = document.convert(format='png',
frame=0, frame=0,
display='thumbnail') display='thumbnail')
# it's a valid PNG # it's a valid PNG
self.assertEqual('PNG', image_data[1:4]) self.assertEqual('PNG', image_data[1:4])
...@@ -1328,12 +1320,9 @@ class TestDocument(TestDocumentMixin): ...@@ -1328,12 +1320,9 @@ class TestDocument(TestDocumentMixin):
def test_upload_bad_pdf_file(self): def test_upload_bad_pdf_file(self):
""" Test that pypdf2 handle wrong formatted PDF """ """ Test that pypdf2 handle wrong formatted PDF """
path = os.path.join(os.path.dirname(__file__), 'test_document',
'FEUILLE BLANCHE.pdf')
file_upload = FileUpload(path, 'FEUILLE BLANCHE.pdf')
pdf = self.portal.document_module.newContent( pdf = self.portal.document_module.newContent(
portal_type='PDF', portal_type='PDF',
file=file_upload, file=makeFileUpload('FEUILLE BLANCHE.pdf'),
title='Bad PDF') title='Bad PDF')
self.tic() self.tic()
pdf.share() pdf.share()
...@@ -1572,7 +1561,7 @@ class TestDocument(TestDocumentMixin): ...@@ -1572,7 +1561,7 @@ class TestDocument(TestDocumentMixin):
.newContent(portal_type=web_page_portal_type) .newContent(portal_type=web_page_portal_type)
html_content = '<p>%s</p>' % string_to_test html_content = '<p>%s</p>' % string_to_test
web_page.edit(text_content=html_content) web_page.edit(text_content=html_content)
mime_type, 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), str(pdf_data),
...@@ -1610,7 +1599,7 @@ class TestDocument(TestDocumentMixin): ...@@ -1610,7 +1599,7 @@ class TestDocument(TestDocumentMixin):
self.tic() self.tic()
# convert web_page into odt # convert web_page into odt
mime_type, odt_archive = web_page.convert('odt') _, odt_archive = web_page.convert('odt')
builder = OOoBuilder(odt_archive) builder = OOoBuilder(odt_archive)
image_count = builder._image_count image_count = builder._image_count
failure_message = 'Expected image not found in ODF zipped archive' failure_message = 'Expected image not found in ODF zipped archive'
...@@ -1624,11 +1613,11 @@ class TestDocument(TestDocumentMixin): ...@@ -1624,11 +1613,11 @@ class TestDocument(TestDocumentMixin):
html_content = '<p><img src="%s?format=jpeg&amp;display=%s&amp;quality=75"/></p>' % \ html_content = '<p><img src="%s?format=jpeg&amp;display=%s&amp;quality=75"/></p>' % \
(image_reference, image_display) (image_reference, image_display)
web_page.edit(text_content=html_content) web_page.edit(text_content=html_content)
mime_type, odt_archive = web_page.convert('odt') _, odt_archive = web_page.convert('odt')
builder = OOoBuilder(odt_archive) builder = OOoBuilder(odt_archive)
image_count = builder._image_count image_count = builder._image_count
# compute resized image for comparison # compute resized image for comparison
mime, converted_image = image.convert(format='jpeg', display=image_display) _, converted_image = image.convert(format='jpeg', display=image_display)
# fetch image from zipped archive content # fetch image from zipped archive content
# then compare with resized ERP5 Image # then compare with resized ERP5 Image
self.assertEqual(builder.extract('Pictures/%s.jpeg' % image_count), self.assertEqual(builder.extract('Pictures/%s.jpeg' % image_count),
...@@ -1644,11 +1633,11 @@ class TestDocument(TestDocumentMixin): ...@@ -1644,11 +1633,11 @@ class TestDocument(TestDocumentMixin):
html_content = '<p><img src="%s?format=png&amp;display=%s&amp;quality=75"/></p>' % \ html_content = '<p><img src="%s?format=png&amp;display=%s&amp;quality=75"/></p>' % \
(image_reference, image_display) (image_reference, image_display)
web_page.edit(text_content=html_content) web_page.edit(text_content=html_content)
mime_type, odt_archive = web_page.convert('odt') _, odt_archive = web_page.convert('odt')
builder = OOoBuilder(odt_archive) builder = OOoBuilder(odt_archive)
image_count = builder._image_count image_count = builder._image_count
# compute resized image for comparison # compute resized image for comparison
mime, converted_image = document.convert(format='png', _, converted_image = document.convert(format='png',
display=image_display, display=image_display,
quality=75) quality=75)
# fetch image from zipped archive content # fetch image from zipped archive content
...@@ -1784,10 +1773,10 @@ class TestDocument(TestDocumentMixin): ...@@ -1784,10 +1773,10 @@ class TestDocument(TestDocumentMixin):
self.assertTrue('7CcvP/PS8U90/wv0LRSL/rwEwgAAAABJRU5ErkJggg=="' in safe_html) self.assertTrue('7CcvP/PS8U90/wv0LRSL/rwEwgAAAABJRU5ErkJggg=="' in safe_html)
# now check converted value is stored in cache # now check converted value is stored in cache
format = 'html' format_ = 'html'
self.assertTrue(web_page.hasConversion(format=format)) self.assertTrue(web_page.hasConversion(format=format_))
web_page.edit(text_content=None) web_page.edit(text_content=None)
self.assertFalse(web_page.hasConversion(format=format)) self.assertFalse(web_page.hasConversion(format=format_))
# test with not well-formed html document # test with not well-formed html document
html_content = r""" html_content = r"""
...@@ -1851,7 +1840,7 @@ document.write('<sc'+'ript type="text/javascript" src="http://somosite.bg/utb.ph ...@@ -1851,7 +1840,7 @@ document.write('<sc'+'ript type="text/javascript" src="http://somosite.bg/utb.ph
filename = 'broken_html.html' filename = 'broken_html.html'
file_object = makeFileUpload(filename) file_object = makeFileUpload(filename)
web_page.edit(file=file_object) web_page.edit(file=file_object)
converted = web_page.convert('html')[1] assert web_page.convert('html')[1]
def test_safeHTML_impossible_conversion(self): def test_safeHTML_impossible_conversion(self):
"""Some html are not parsable. """Some html are not parsable.
...@@ -1908,10 +1897,6 @@ document.write('<sc'+'ript type="text/javascript" src="http://somosite.bg/utb.ph ...@@ -1908,10 +1897,6 @@ document.write('<sc'+'ript type="text/javascript" src="http://somosite.bg/utb.ph
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()
preference_tool = getToolByName(self.portal, 'portal_preferences')
image_size = preference_tool.getPreferredThumbnailImageHeight(),\
preference_tool.getPreferredThumbnailImageWidth()
convert_kw = {'format': 'png', convert_kw = {'format': 'png',
'quality': 75, 'quality': 75,
'display': 'thumbnail', 'display': 'thumbnail',
...@@ -1957,7 +1942,8 @@ document.write('<sc'+'ript type="text/javascript" src="http://somosite.bg/utb.ph ...@@ -1957,7 +1942,8 @@ document.write('<sc'+'ript type="text/javascript" src="http://somosite.bg/utb.ph
instance.start() instance.start()
# Wait until threads finishing # Wait until threads finishing
[tested.join() for tested in tested_list] for tested in tested_list:
tested.join()
self.tic() self.tic()
...@@ -2054,7 +2040,6 @@ return 1 ...@@ -2054,7 +2040,6 @@ return 1
self.createRestrictedSecurityHelperScript() self.createRestrictedSecurityHelperScript()
from AccessControl import Unauthorized
# check that it is not possible to access document in original format # check that it is not possible to access document in original format
self.assertRaises(Unauthorized, document.convert, format=None) self.assertRaises(Unauthorized, document.convert, format=None)
# check that it is possible to convert document to text format # check that it is possible to convert document to text format
...@@ -2168,7 +2153,7 @@ return 1 ...@@ -2168,7 +2153,7 @@ return 1
self.tic() self.tic()
web_page_document_url = '%s/%s' %(self.portal.absolute_url(), web_page_document.getRelativeUrl()) web_page_document_url = '%s/%s' %(self.portal.absolute_url(), web_page_document.getRelativeUrl())
web_page_image_size, web_page_file_size = self.getURLSizeList(web_page_document_url, **convert_kw) web_page_image_size, _ = self.getURLSizeList(web_page_document_url, **convert_kw)
self.assertTrue(max(preffered_size_for_display) - max(web_page_image_size) <= 1) self.assertTrue(max(preffered_size_for_display) - max(web_page_image_size) <= 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)
...@@ -2185,7 +2170,7 @@ return 1 ...@@ -2185,7 +2170,7 @@ return 1
web_page_document.setTextContent('''<b> test </b><img src="Embedded-XXX?format=jpeg&amp;dispay=medium&amp;quality=50"/>''') web_page_document.setTextContent('''<b> test </b><img src="Embedded-XXX?format=jpeg&amp;dispay=medium&amp;quality=50"/>''')
self.tic() self.tic()
web_page_document_url = '%s/%s' %(self.portal.absolute_url(), web_page_document.getRelativeUrl()) web_page_document_url = '%s/%s' %(self.portal.absolute_url(), web_page_document.getRelativeUrl())
web_page_image_size, web_page_file_size = self.getURLSizeList(web_page_document_url, **convert_kw) web_page_image_size, _ = self.getURLSizeList(web_page_document_url, **convert_kw)
self.assertTrue(max(preffered_size_for_display) - max(web_page_image_size) <= 1) self.assertTrue(max(preffered_size_for_display) - max(web_page_image_size) <= 1)
# external images # external images
...@@ -2198,7 +2183,7 @@ return 1 ...@@ -2198,7 +2183,7 @@ return 1
''') ''')
self.tic() self.tic()
web_page_document_url = '%s/%s' %(self.portal.absolute_url(), web_page_document.getRelativeUrl()) web_page_document_url = '%s/%s' %(self.portal.absolute_url(), web_page_document.getRelativeUrl())
web_page_image_size, web_page_file_size = self.getURLSizeList(web_page_document_url, **convert_kw) web_page_image_size, _ = self.getURLSizeList(web_page_document_url, **convert_kw)
self.assertTrue(max(preffered_size_for_display) - max(web_page_image_size) <= 1) self.assertTrue(max(preffered_size_for_display) - max(web_page_image_size) <= 1)
# XXX: how to simulate the case when web page contains (through reference) link to document for which based conversion failed? # XXX: how to simulate the case when web page contains (through reference) link to document for which based conversion failed?
...@@ -2241,33 +2226,33 @@ return 1 ...@@ -2241,33 +2226,33 @@ return 1
for display in ('nano', 'micro', 'thumbnail', 'xsmall', 'small', 'medium', 'large', 'xlarge',): for display in ('nano', 'micro', 'thumbnail', 'xsmall', 'small', 'medium', 'large', 'xlarge',):
max_tollerance_px = 1 max_tollerance_px = 1
preffered_size_for_display = self.getPreferences(display) preffered_size_for_display = self.getPreferences(display)
for format in ('png', 'jpeg', 'gif',): for format_ in ('png', 'jpeg', 'gif',):
convert_kw = {'display':display, \ convert_kw = {'display':display, \
'format':format, \ 'format':format_, \
'quality':100} 'quality':100}
# Note: due to some image interpolations it's possssible that we have a difference of max_tollerance_px # Note: due to some image interpolations it's possssible that we have a difference of max_tollerance_px
# so allow some tollerance which is produced by respective portal_transform command # so allow some tollerance which is produced by respective portal_transform command
# any OOo based portal type # any OOo based portal type
ooo_document_image_size, ooo_document_file_size = self.getURLSizeList(ooo_document_url, **convert_kw) ooo_document_image_size, _ = self.getURLSizeList(ooo_document_url, **convert_kw)
self.assertTrue(max(preffered_size_for_display) - max(ooo_document_image_size) <= max_tollerance_px) self.assertTrue(max(preffered_size_for_display) - max(ooo_document_image_size) <= max_tollerance_px)
# PDF # PDF
pdf_document_image_size, pdf_document_file_size = self.getURLSizeList(pdf_document_url, **convert_kw) pdf_document_image_size, _ = self.getURLSizeList(pdf_document_url, **convert_kw)
self.assertTrue(max(preffered_size_for_display) - max(pdf_document_image_size) <= max_tollerance_px) self.assertTrue(max(preffered_size_for_display) - max(pdf_document_image_size) <= max_tollerance_px)
# Image # Image
image_document_image_size, image_document_file_size = self.getURLSizeList(image_document_url, **convert_kw) image_document_image_size, _ = self.getURLSizeList(image_document_url, **convert_kw)
self.assertTrue(max(preffered_size_for_display) - max(image_document_image_size) <= max_tollerance_px) self.assertTrue(max(preffered_size_for_display) - max(image_document_image_size) <= max_tollerance_px)
self.assertTrue(abs(min(preffered_size_for_display) - min(image_document_image_size)) >= max_tollerance_px) self.assertTrue(abs(min(preffered_size_for_display) - min(image_document_image_size)) >= max_tollerance_px)
cropped_image_document_image_size, cropped_image_document_file_size = \ cropped_image_document_image_size, _ = \
self.getURLSizeList(image_document_url, crop = 1, **convert_kw) self.getURLSizeList(image_document_url, crop = 1, **convert_kw)
self.assertEqual(max(preffered_size_for_display), max(cropped_image_document_image_size)) self.assertEqual(max(preffered_size_for_display), max(cropped_image_document_image_size))
self.assertEqual(min(preffered_size_for_display), min(cropped_image_document_image_size)) self.assertEqual(min(preffered_size_for_display), min(cropped_image_document_image_size))
# Web Page # Web Page
web_page_image_size, web_page_file_size = self.getURLSizeList(web_page_document_url, **convert_kw) web_page_image_size, _ = self.getURLSizeList(web_page_document_url, **convert_kw)
self.assertTrue(max(preffered_size_for_display) - max(web_page_image_size) <= max_tollerance_px) self.assertTrue(max(preffered_size_for_display) - max(web_page_image_size) <= max_tollerance_px)
...@@ -2379,28 +2364,28 @@ return 1 ...@@ -2379,28 +2364,28 @@ return 1
doc.publish() doc.publish()
self.tic() self.tic()
default_conversion_failure_image_size, default_conversion_failure_image_file_size = \ default_conversion_failure_image_size, _ = \
self.getURLSizeList('%s/default_conversion_failure_image' %self.portal.absolute_url()) self.getURLSizeList('%s/default_conversion_failure_image' %self.portal.absolute_url())
doc_url = '%s/%s' %(self.portal.absolute_url(), doc.getPath()) doc_url = '%s/%s' %(self.portal.absolute_url(), doc.getPath())
converted_image_size_70, converted_file_size_70 = self.getURLSizeList(doc_url, \ converted_image_size_70, _ = self.getURLSizeList(doc_url, \
**{'format':'png', 'quality':70.0}) **{'format':'png', 'quality':70.0})
self.assertTrue(doc.hasConversion(**{'format': 'png', 'quality': 70.0})) self.assertTrue(doc.hasConversion(**{'format': 'png', 'quality': 70.0}))
# try with new quality and pre_converted_only now a default image # try with new quality and pre_converted_only now a default image
# with content "No image available" should be returned # with content "No image available" should be returned
failure_image_size, failure_file_size = self.getURLSizeList(doc_url, \ failure_image_size, _ = self.getURLSizeList(doc_url, \
**{'format':'png', 'quality':80.0, 'pre_converted_only':1}) **{'format':'png', 'quality':80.0, 'pre_converted_only':1})
self.assertSameSet(failure_image_size, default_conversion_failure_image_size) self.assertSameSet(failure_image_size, default_conversion_failure_image_size)
converted_image_size_80, converted_file_size_80 = self.getURLSizeList(doc_url, \ converted_image_size_80, _ = self.getURLSizeList(doc_url, \
**{'format':'png', 'quality':80.0}) **{'format':'png', 'quality':80.0})
self.assertSameSet(converted_image_size_80, converted_image_size_70) self.assertSameSet(converted_image_size_80, converted_image_size_70)
self.assertTrue(doc.hasConversion(**{'format': 'png', 'quality': 80.0})) self.assertTrue(doc.hasConversion(**{'format': 'png', 'quality': 80.0}))
# as conversion is cached we should get it # as conversion is cached we should get it
converted_image_size_80n, converted_file_size_80n = self.getURLSizeList(doc_url, converted_image_size_80n, _ = self.getURLSizeList(doc_url,
**{'format':'png', 'quality':80.0, 'pre_converted_only':1}) **{'format':'png', 'quality':80.0, 'pre_converted_only':1})
self.assertSameSet(converted_image_size_80n, converted_image_size_70) self.assertSameSet(converted_image_size_80n, converted_image_size_70)
...@@ -2442,7 +2427,7 @@ return 1 ...@@ -2442,7 +2427,7 @@ return 1
self.tic() self.tic()
self.assertEqual(0, len(document1.Document_getOtherVersionDocumentList())) self.assertEqual(0, len(document1.Document_getOtherVersionDocumentList()))
kw['version'] == '002' kw['version'] = '002'
document2 = portal.document_module.newContent(portal_type="Spreadsheet", **kw) document2 = portal.document_module.newContent(portal_type="Spreadsheet", **kw)
self.tic() self.tic()
...@@ -2497,8 +2482,6 @@ return 1 ...@@ -2497,8 +2482,6 @@ return 1
""" """
Test various cases of contributing to an existing document Test various cases of contributing to an existing document
""" """
request = get_request()
portal = self.portal
# 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 = makeFileUpload('TEST-en-002.doc')
kw = dict(file=upload_file, synchronous_metadata_discovery=True) kw = dict(file=upload_file, synchronous_metadata_discovery=True)
...@@ -2523,8 +2506,6 @@ return 1 ...@@ -2523,8 +2506,6 @@ return 1
""" """
Test various cases of merging to an existing document Test various cases of merging to an existing document
""" """
request = get_request()
portal = self.portal
# 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 = makeFileUpload('TEST-en-002.doc')
...@@ -2769,8 +2750,6 @@ return 1 ...@@ -2769,8 +2750,6 @@ 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.
""" """
portal = self.portal
upload_file = makeFileUpload('TEST-en-002.doc') upload_file = 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)
...@@ -2849,7 +2828,7 @@ class TestDocumentWithSecurity(TestDocumentMixin): ...@@ -2849,7 +2828,7 @@ class TestDocumentWithSecurity(TestDocumentMixin):
def getTitle(self): def getTitle(self):
return "DMS with security" return "DMS with security"
def login(self): def login(self, *args, **kw):
uf = self.getPortal().acl_users uf = self.getPortal().acl_users
uf._doAddUser(self.username, '', ['Auditor', 'Author'], []) uf._doAddUser(self.username, '', ['Auditor', 'Author'], [])
user = uf.getUserById(self.username).__of__(uf) user = uf.getUserById(self.username).__of__(uf)
...@@ -2895,7 +2874,7 @@ class TestDocumentWithSecurity(TestDocumentMixin): ...@@ -2895,7 +2874,7 @@ class TestDocumentWithSecurity(TestDocumentMixin):
self.assertFalse(text_document.hasConversion(format='pdf')) self.assertFalse(text_document.hasConversion(format='pdf'))
# call pdf conversion, in this way, the result should be cached # call pdf conversion, in this way, the result should be cached
mime_type, pdf_data = text_document.convert(format='pdf') _, pdf_data = text_document.convert(format='pdf')
pdf_size = len(pdf_data) pdf_size = len(pdf_data)
...@@ -2986,4 +2965,4 @@ def test_suite(): ...@@ -2986,4 +2965,4 @@ def test_suite():
return suite return suite
# vim: syntax=python shiftwidth=2 # vim: syntax=python shiftwidth=2
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Test Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testDms</string> </value>
</item>
<item>
<key> <string>default_source_reference</string> </key>
<value> <string>Products.ERP5OOo.tests.testDms</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testDms</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Test Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
############################################################################## ##############################################################################
import unittest import unittest
from testDms import TestDocument from erp5.component.test.testDms import TestDocument
from Products.ERP5Type.tests.ERP5TypeTestCase import _getPersistentMemcachedServerDict from Products.ERP5Type.tests.ERP5TypeTestCase import _getPersistentMemcachedServerDict
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Test Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testDmsWithFlare</string> </value>
</item>
<item>
<key> <string>default_source_reference</string> </key>
<value> <string>Products.ERP5OOo.tests.testDmsWithFlare</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testDmsWithFlare</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Test Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -68,7 +68,8 @@ gg==''') ...@@ -68,7 +68,8 @@ gg==''')
def makeFilePath(name): def makeFilePath(name):
return os.path.join(os.path.dirname(__file__), 'test_data', name) from Products.ERP5 import tests
return os.path.join(tests.__path__[0], 'test_data', name)
def makeFileUpload(name, as_name=None): def makeFileUpload(name, as_name=None):
if as_name is None: if as_name is None:
...@@ -1319,7 +1320,7 @@ return True ...@@ -1319,7 +1320,7 @@ return True
("image/png", "", pngmessage, png, XSMALL_PNG_IMAGE_ICON_DATA), ("image/png", "", pngmessage, png, XSMALL_PNG_IMAGE_ICON_DATA),
("image/png", "png", svgtopngmessage, svg, None), ("image/png", "png", svgtopngmessage, svg, None),
]: ]:
__traceback_info__ = (content_type, "?format=" + ext) __traceback_info__ = (content_type, "?format=" + ext) # pylint: disable=unused-variable
self.assertEqual( self.assertEqual(
message.get("Content-Location"), message.get("Content-Location"),
obj.absolute_url() + "?format=" + ext, obj.absolute_url() + "?format=" + ext,
...@@ -1479,7 +1480,7 @@ return True ...@@ -1479,7 +1480,7 @@ return True
image_module = self.portal.getDefaultModule(portal_type="Image") image_module = self.portal.getDefaultModule(portal_type="Image")
page = web_page_module.newContent(portal_type="Web Page") page = web_page_module.newContent(portal_type="Web Page")
text_content_list = ["<p>Hello</p>"] text_content_list = ["<p>Hello</p>"]
for i in range(0, 1000, 5): for _ in range(0, 1000, 5):
svg = image_module.newContent(portal_type="Image") svg = image_module.newContent(portal_type="Image")
svg.edit(content_type="image/svg+xml", data=XSMALL_SVG_IMAGE_ICON_DATA) svg.edit(content_type="image/svg+xml", data=XSMALL_SVG_IMAGE_ICON_DATA)
svg.publish() svg.publish()
...@@ -1505,7 +1506,7 @@ return True ...@@ -1505,7 +1506,7 @@ return True
image_module = self.portal.getDefaultModule(portal_type="Image") image_module = self.portal.getDefaultModule(portal_type="Image")
page = web_page_module.newContent(portal_type="Web Page") page = web_page_module.newContent(portal_type="Web Page")
text_content_list = ["<p>Hello</p>"] text_content_list = ["<p>Hello</p>"]
for i in range(0, 1000, 5): for _ in range(0, 1000, 5):
svg = image_module.newContent(portal_type="Image") svg = image_module.newContent(portal_type="Image")
svg.edit(content_type="image/svg+xml", data=XSMALL_SVG_IMAGE_ICON_DATA) svg.edit(content_type="image/svg+xml", data=XSMALL_SVG_IMAGE_ICON_DATA)
svg.publish() svg.publish()
...@@ -1603,7 +1604,7 @@ return True ...@@ -1603,7 +1604,7 @@ return True
def test_WebPageImplicitSuccessorValueList(self): def test_WebPageImplicitSuccessorValueList(self):
# Test init part # Test init part
# XXX use web site domain properties instead of @customScript # XXX use web site domain properties instead of @customScript
web_site = self.setupWebSite() self.setupWebSite()
web_page_module = self.portal.getDefaultModule(portal_type="Web Page") web_page_module = self.portal.getDefaultModule(portal_type="Web Page")
image_module = self.portal.getDefaultModule(portal_type="Image") image_module = self.portal.getDefaultModule(portal_type="Image")
img_list = [] img_list = []
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Test Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testERP5WebWithDms</string> </value>
</item>
<item>
<key> <string>default_source_reference</string> </key>
<value> <string>Products.ERP5.tests.testERP5WebWithDms</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testERP5WebWithDms</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Test Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -31,25 +31,13 @@ ...@@ -31,25 +31,13 @@
import unittest import unittest
from DateTime import DateTime from DateTime import DateTime
from testDms import TestDocumentMixin from erp5.component.test.testDms import TestDocumentMixin, makeFileUpload
from Products.ERP5Type.tests.utils import FileUpload
import os
try: try:
import magic import magic
except ImportError: except ImportError:
magic = None magic = None
def makeFilePath(name):
return os.path.join(os.path.dirname(__file__), 'test_document', name)
def makeFileUpload(name, as_name=None):
if as_name is None:
as_name = name
path = makeFilePath(name)
return FileUpload(path, as_name)
class TestDocumentConversionCache(TestDocumentMixin): class TestDocumentConversionCache(TestDocumentMixin):
""" """
Test basic document - related operations Test basic document - related operations
...@@ -71,34 +59,34 @@ class TestDocumentConversionCache(TestDocumentMixin): ...@@ -71,34 +59,34 @@ 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_ = 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'
self.assertFalse(document.hasConversion(format=format)) self.assertFalse(document.hasConversion(format=format_))
document.convert(format) document.convert(format_)
self.assertTrue(document.hasConversion(format=format)) self.assertTrue(document.hasConversion(format=format_))
self.assertFalse(document.hasConversion(format=format, display='large')) self.assertFalse(document.hasConversion(format=format_, display='large'))
document.convert(format, display='large') document.convert(format_, display='large')
self.assertTrue(document.hasConversion(format=format, display='large')) self.assertTrue(document.hasConversion(format=format_, display='large'))
self.assertFalse(document.hasConversion(format=format, self.assertFalse(document.hasConversion(format=format_,
display='large', display='large',
quality=40)) quality=40))
document.convert(format, display='large', quality=40) document.convert(format_, display='large', quality=40)
self.assertTrue(document.hasConversion(format=format, self.assertTrue(document.hasConversion(format=format_,
display='large', display='large',
quality=40)) quality=40))
if magic is not None: if magic is not None:
mime_detector = magic.Magic(mime=True) mime_detector = magic.Magic(mime=True)
self.assertEqual(mime_detector.from_buffer(document.getConversion(format=format)[1]), self.assertEqual(mime_detector.from_buffer(document.getConversion(format=format_)[1]),
'image/png') 'image/png')
self.assertEqual(mime_detector.from_buffer(document.getConversion(format=format, self.assertEqual(mime_detector.from_buffer(document.getConversion(format=format_,
display='large')[1]), display='large')[1]),
'image/png') 'image/png')
self.assertEqual(mime_detector.from_buffer(document.getConversion(format=format, self.assertEqual(mime_detector.from_buffer(document.getConversion(format=format_,
display='large', display='large',
quality=40)[1]), quality=40)[1]),
'image/png') 'image/png')
...@@ -108,69 +96,69 @@ class TestDocumentConversionCache(TestDocumentMixin): ...@@ -108,69 +96,69 @@ 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_ = 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()
document = self.portal.restrictedTraverse(document_url) document = self.portal.restrictedTraverse(document_url)
format_list = [format for format in document.getTargetFormatList() if format not in self.failed_format_list] format_list = [format_ for format_ in document.getTargetFormatList() if format_ not in self.failed_format_list]
if not format_list: if not format_list:
self.fail('Target format list is empty') self.fail('Target format list is empty')
#Test Conversion Cache #Test Conversion Cache
for format in format_list: for format_ in format_list:
document.convert(format=format) document.convert(format=format_)
self.commit() self.commit()
self.assertTrue(document.hasConversion(format=format), 'Cache Storage failed for %s' % (format)) self.assertTrue(document.hasConversion(format=format_), 'Cache Storage failed for %s' % (format_))
self.assertEqual(DateTime().Date(), document.getConversionDate(format=format).Date()) self.assertEqual(DateTime().Date(), document.getConversionDate(format=format_).Date())
self.assertTrue(document.getConversionMd5(format=format)) self.assertTrue(document.getConversionMd5(format=format_))
self.assertTrue(document.getConversionSize(format=format)) self.assertTrue(document.getConversionSize(format=format_))
document.edit(title='Foo') document.edit(title='Foo')
self.commit() self.commit()
#Test Cache is cleared #Test Cache is cleared
for format in format_list: for format_ in format_list:
self.assertFalse(document.hasConversion(format=format), 'Cache Storage failed for %s' % (format)) self.assertFalse(document.hasConversion(format=format_), 'Cache Storage failed for %s' % (format_))
self.assertRaises(KeyError, document.getConversionSize, format=format) self.assertRaises(KeyError, document.getConversionSize, format=format_)
document.edit(title='Bar') document.edit(title='Bar')
self.tic() self.tic()
#Test Conversion Cache after editing #Test Conversion Cache after editing
for format in format_list: for format_ in format_list:
document.convert(format=format) document.convert(format=format_)
self.commit() self.commit()
self.assertTrue(document.hasConversion(format=format), 'Cache Storage failed for %s' % (format)) self.assertTrue(document.hasConversion(format=format_), 'Cache Storage failed for %s' % (format_))
self.assertTrue(document.getConversionSize(format=format)) self.assertTrue(document.getConversionSize(format=format_))
def test_02_VolatileCacheConversionOfTempObject(self): def test_02_VolatileCacheConversionOfTempObject(self):
filename = 'TEST-en-002.doc' filename = 'TEST-en-002.doc'
file = makeFileUpload(filename) file_ = 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()
document.convertToBaseFormat() document.convertToBaseFormat()
format_list = [format for format in document.getTargetFormatList() if format not in self.failed_format_list] format_list = [format_ for format_ in document.getTargetFormatList() if format_ not in self.failed_format_list]
if not format_list: if not format_list:
self.fail('Target format list is empty') self.fail('Target format list is empty')
#Test Conversion Cache #Test Conversion Cache
for format in format_list: for format_ in format_list:
document.convert(format=format) document.convert(format=format_)
self.commit() self.commit()
self.assertTrue(document.hasConversion(format=format), 'Cache Storage failed for %s' % (format)) self.assertTrue(document.hasConversion(format=format_), 'Cache Storage failed for %s' % (format_))
self.assertEqual(DateTime().Date(), document.getConversionDate(format=format).Date()) self.assertEqual(DateTime().Date(), document.getConversionDate(format=format_).Date())
self.assertTrue(document.getConversionMd5(format=format)) self.assertTrue(document.getConversionMd5(format=format_))
self.assertTrue(document.getConversionSize(format=format)) self.assertTrue(document.getConversionSize(format=format_))
document.edit(title='Foo') document.edit(title='Foo')
self.commit() self.commit()
#Test Cache is cleared #Test Cache is cleared
for format in format_list: for format_ in format_list:
self.assertFalse(document.hasConversion(format=format), 'Cache Storage failed for %s' % (format)) self.assertFalse(document.hasConversion(format=format_), 'Cache Storage failed for %s' % (format_))
self.assertRaises(KeyError, document.getConversionSize, format=format) self.assertRaises(KeyError, document.getConversionSize, format=format_)
document.edit(title='Bar') document.edit(title='Bar')
self.tic() self.tic()
#Test Conversion Cache after editing #Test Conversion Cache after editing
for format in format_list: for format_ in format_list:
document.convert(format=format) document.convert(format=format_)
self.commit() self.commit()
self.assertTrue(document.hasConversion(format=format), 'Cache Storage failed for %s' % (format)) self.assertTrue(document.hasConversion(format=format_), 'Cache Storage failed for %s' % (format_))
self.assertTrue(document.getConversionSize(format=format)) self.assertTrue(document.getConversionSize(format=format_))
def test_03_CacheConversionOfTempObjectIsNotMixed(self): def test_03_CacheConversionOfTempObjectIsNotMixed(self):
filename1 = 'TEST-en-002.doc' filename1 = 'TEST-en-002.doc'
...@@ -185,11 +173,11 @@ class TestDocumentConversionCache(TestDocumentMixin): ...@@ -185,11 +173,11 @@ class TestDocumentConversionCache(TestDocumentMixin):
document2.uploadFile() document2.uploadFile()
document2.processFile() document2.processFile()
document2.convertToBaseFormat() document2.convertToBaseFormat()
format = 'pdf' format_ = 'pdf'
document1.convert(format=format) document1.convert(format=format_)
document2.convert(format=format) document2.convert(format=format_)
self.assertNotEqual(document1.getConversion(format=format), self.assertNotEqual(document1.getConversion(format=format_),
document2.getConversion(format=format)) document2.getConversion(format=format_))
self.tic() self.tic()
def test_04_PersistentCacheConversionWithFlare(self): def test_04_PersistentCacheConversionWithFlare(self):
...@@ -199,44 +187,44 @@ class TestDocumentConversionCache(TestDocumentMixin): ...@@ -199,44 +187,44 @@ 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_ = 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()
document = self.portal.restrictedTraverse(document_url) document = self.portal.restrictedTraverse(document_url)
format_list = [format for format in document.getTargetFormatList()\ format_list = [format_ for format_ in document.getTargetFormatList()\
if format not in self.failed_format_list] if format_ not in self.failed_format_list]
if not format_list: if not format_list:
self.fail('Target format list is empty') self.fail('Target format list is empty')
#Test Conversion Cache #Test Conversion Cache
for format in format_list: for format_ in format_list:
document.convert(format=format) document.convert(format=format_)
self.assertTrue(document.hasConversion(format=format), self.assertTrue(document.hasConversion(format=format_),
'Cache Storage failed for %s' % (format)) 'Cache Storage failed for %s' % (format_))
self.assertTrue(document.getConversionSize(format=format)) self.assertTrue(document.getConversionSize(format=format_))
document.edit(title='Foo') document.edit(title='Foo')
self.commit() self.commit()
#Test Cache is cleared #Test Cache is cleared
for format in format_list: for format_ in format_list:
self.assertFalse(document.hasConversion(format=format), self.assertFalse(document.hasConversion(format=format_),
'Cache Storage failed for %s' % (format)) 'Cache Storage failed for %s' % (format_))
self.assertRaises(KeyError, document.getConversionSize, format=format) self.assertRaises(KeyError, document.getConversionSize, format=format_)
document.edit(title='Bar') document.edit(title='Bar')
self.tic() self.tic()
#Test Conversion Cache after editing #Test Conversion Cache after editing
for format in format_list: for format_ in format_list:
document.convert(format=format) document.convert(format=format_)
self.assertTrue(document.hasConversion(format=format), self.assertTrue(document.hasConversion(format=format_),
'Cache Storage failed for %s' % (format)) 'Cache Storage failed for %s' % (format_))
self.assertTrue(document.getConversionSize(format=format)) self.assertTrue(document.getConversionSize(format=format_))
def test_05_checksum_conversion(self): def test_05_checksum_conversion(self):
""" """
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_ = 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()
document = self.portal.restrictedTraverse(document_url) document = self.portal.restrictedTraverse(document_url)
...@@ -264,8 +252,8 @@ class TestDocumentConversionCache(TestDocumentMixin): ...@@ -264,8 +252,8 @@ 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_ = 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()
document = self.portal.restrictedTraverse(document_url) document = self.portal.restrictedTraverse(document_url)
...@@ -287,11 +275,11 @@ class TestDocumentConversionCache(TestDocumentMixin): ...@@ -287,11 +275,11 @@ 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_ = 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)
document = module.newContent(id=document_id, file=file, document = module.newContent(id=document_id, file=file_,
portal_type=portal_type) portal_type=portal_type)
self.tic() self.tic()
document_url = document.getRelativeUrl() document_url = document.getRelativeUrl()
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Test Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testOOoConversionCache</string> </value>
</item>
<item>
<key> <string>default_source_reference</string> </key>
<value> <string>Products.ERP5OOo.tests.testOOoConversionCache</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testOOoConversionCache</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Test Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
############################################################################## ##############################################################################
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5OOo.tests.testDms import makeFileUpload from erp5.component.test.testDms import makeFileUpload
from Products.ERP5Form.PreferenceTool import Priority from Products.ERP5Form.PreferenceTool import Priority
...@@ -63,12 +63,12 @@ class TestOOoConversionServerRetry(ERP5TypeTestCase): ...@@ -63,12 +63,12 @@ class TestOOoConversionServerRetry(ERP5TypeTestCase):
self.retry_count = 2 self.retry_count = 2
def getDefaultSystemPreference(self): def getDefaultSystemPreference(self):
id = 'default_system_preference' id_ = 'default_system_preference'
tool = self.getPreferenceTool() tool = self.getPreferenceTool()
try: try:
pref = tool[id] pref = tool[id_]
except KeyError: except KeyError:
pref = tool.newContent(id, 'System Preference') pref = tool.newContent(id_, 'System Preference')
pref.setPriority(Priority.SITE) pref.setPriority(Priority.SITE)
pref.enable() pref.enable()
return pref return pref
...@@ -80,9 +80,9 @@ class TestOOoConversionServerRetry(ERP5TypeTestCase): ...@@ -80,9 +80,9 @@ class TestOOoConversionServerRetry(ERP5TypeTestCase):
self.tic() self.tic()
filename = 'monochrome_sample.tiff' filename = 'monochrome_sample.tiff'
file = makeFileUpload(filename) file_ = 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()
self.assertEqual(message.count('Error converting document to base format'), 1) self.assertEqual(message.count('Error converting document to base format'), 1)
...@@ -95,8 +95,8 @@ class TestOOoConversionServerRetry(ERP5TypeTestCase): ...@@ -95,8 +95,8 @@ 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_ = 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()
self.assertEqual(message.count('broken.url: Connection refused'), self.retry_count + 1) self.assertEqual(message.count('broken.url: Connection refused'), self.retry_count + 1)
...@@ -110,8 +110,8 @@ class TestOOoConversionServerRetry(ERP5TypeTestCase): ...@@ -110,8 +110,8 @@ 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_ = 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()
if 'Socket Error: SSLError' in message: if 'Socket Error: SSLError' in message:
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Test Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testOOoConversionServerRetry</string> </value>
</item>
<item>
<key> <string>default_source_reference</string> </key>
<value> <string>Products.ERP5OOo.tests.testOOoConversionServerRetry</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testOOoConversionServerRetry</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Test Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
document.erp5.ExternalSource
document.erp5.PDFDocument document.erp5.PDFDocument
\ No newline at end of file
test.erp5.testDms
test.erp5.testDmsWithFlare
test.erp5.testERP5WebWithDms
test.erp5.testOOoConversionCache
test.erp5.testOOoConversionServerRetry
\ No newline at end of file
erp5_full_text_mroonga_catalog
erp5_ingestion_mysql_innodb_catalog
\ No newline at end of file
...@@ -28,15 +28,13 @@ ...@@ -28,15 +28,13 @@
############################################################################## ##############################################################################
import unittest import unittest
from testDms import TestDocument, makeFileUpload from erp5.component.test.testDms import TestDocument, makeFileUpload
class TestDocumentWithPreConversion(TestDocument): class TestDocumentWithPreConversion(TestDocument):
""" """
Test basic document - related operations Test basic document - related operations
with Flare with Flare
""" """
business_template_list = TestDocument.business_template_list + ["erp5_dms_conversion_catalog"]
def getTitle(self): def getTitle(self):
return "DMS with Preconversion" return "DMS with Preconversion"
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Test Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testDmsWithPreConversion</string> </value>
</item>
<item>
<key> <string>default_source_reference</string> </key>
<value> <string>Products.ERP5OOo.tests.testDmsWithPreConversion</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testDmsWithPreConversion</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Test Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
test.erp5.testDmsWithPreConversion
\ No newline at end of file
erp5_full_text_mroonga_catalog
erp5_dms
\ No newline at end of file
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5.Document.ExternalSource import ExternalSource from erp5.component.document.ExternalSource import ExternalSource
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Type.Cache import transactional_cached from Products.ERP5Type.Cache import transactional_cached
......
...@@ -31,8 +31,7 @@ import unittest ...@@ -31,8 +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 Products.ERP5OOo.tests.testDms import makeFileUpload from erp5.component.test.testDms import makeFileUpload, TestDocumentMixin
from Products.ERP5OOo.tests.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."""
...@@ -65,7 +64,6 @@ class TestKMMixIn(TestDocumentMixin): ...@@ -65,7 +64,6 @@ class TestKMMixIn(TestDocumentMixin):
def afterSetUp(self): def afterSetUp(self):
self.login() self.login()
portal = self.getPortal()
self.website = self.setupWebSite(skin_selection_name='KM', self.website = self.setupWebSite(skin_selection_name='KM',
container_layout='erp5_km_minimal_layout', container_layout='erp5_km_minimal_layout',
content_layout='erp5_km_minimal_content_layout', content_layout='erp5_km_minimal_content_layout',
...@@ -87,7 +85,7 @@ class TestKMMixIn(TestDocumentMixin): ...@@ -87,7 +85,7 @@ class TestKMMixIn(TestDocumentMixin):
self.tic() self.tic()
return website return website
def login(self): def login(self, *args, **kw):
uf = self.getPortal().acl_users uf = self.getPortal().acl_users
uf._doAddUser('ivan', '', ['Manager'], []) uf._doAddUser('ivan', '', ['Manager'], [])
uf._doAddUser('ERP5TypeTestCase', '', ['Manager'], []) uf._doAddUser('ERP5TypeTestCase', '', ['Manager'], [])
...@@ -230,14 +228,14 @@ class TestKM(TestKMMixIn): ...@@ -230,14 +228,14 @@ class TestKM(TestKMMixIn):
mode='web_section', mode='web_section',
default_pad_group = pad_group) default_pad_group = pad_group)
self.tic() self.tic()
base_websection_pad, websection_pads = \ base_websection_pad, _ = \
websection.ERP5Site_getActiveKnowledgePadForUser(default_pad_group = pad_group) websection.ERP5Site_getActiveKnowledgePadForUser(default_pad_group = pad_group)
# Check stick # Check stick
websection.WebSection_stickKnowledgePad( websection.WebSection_stickKnowledgePad(
base_websection_pad.getRelativeUrl(), '') base_websection_pad.getRelativeUrl(), '')
self.tic() self.tic()
current_websection_pad, websection_pads = \ current_websection_pad, _ = \
websection.ERP5Site_getActiveKnowledgePadForUser(mode='web_section', websection.ERP5Site_getActiveKnowledgePadForUser(mode='web_section',
default_pad_group = pad_group ) default_pad_group = pad_group )
self.assertNotEqual(base_websection_pad.getObject(), self.assertNotEqual(base_websection_pad.getObject(),
...@@ -245,7 +243,7 @@ class TestKM(TestKMMixIn): ...@@ -245,7 +243,7 @@ class TestKM(TestKMMixIn):
# check unstick # check unstick
websection.WebSection_unStickKnowledgePad(current_websection_pad.getRelativeUrl(), '') websection.WebSection_unStickKnowledgePad(current_websection_pad.getRelativeUrl(), '')
current_websection_pad, websection_pads = \ current_websection_pad, _ = \
websection.ERP5Site_getActiveKnowledgePadForUser(default_pad_group = pad_group) websection.ERP5Site_getActiveKnowledgePadForUser(default_pad_group = pad_group)
self.assertEqual(base_websection_pad.getObject(), self.assertEqual(base_websection_pad.getObject(),
current_websection_pad.getObject()) current_websection_pad.getObject())
...@@ -820,7 +818,6 @@ class TestKM(TestKMMixIn): ...@@ -820,7 +818,6 @@ class TestKM(TestKMMixIn):
def test_17AddGadgets(self): def test_17AddGadgets(self):
""" Check Latest Content Gadgets """ """ Check Latest Content Gadgets """
portal = self.getPortal() portal = self.getPortal()
portal_selections = portal.portal_selections
km_my_documents_gadget = portal.portal_gadgets.km_my_documents km_my_documents_gadget = portal.portal_gadgets.km_my_documents
km_my_contacts_gadget = portal.portal_gadgets.km_my_contacts km_my_contacts_gadget = portal.portal_gadgets.km_my_contacts
...@@ -854,7 +851,6 @@ class TestKM(TestKMMixIn): ...@@ -854,7 +851,6 @@ class TestKM(TestKMMixIn):
# change to KM skins which is defined in erp5_km # change to KM skins which is defined in erp5_km
self.changeSkin('KM') self.changeSkin('KM')
assigned_member_list = websection.WebSection_searchAssignmentList(portal_type='Assignment')
self.assertEqual(0, len(websection.WebSection_searchAssignmentList(portal_type='Assignment'))) self.assertEqual(0, len(websection.WebSection_searchAssignmentList(portal_type='Assignment')))
project = portal.project_module.newContent(portal_type='Project', \ project = portal.project_module.newContent(portal_type='Project', \
id='test_project') id='test_project')
...@@ -868,8 +864,8 @@ class TestKM(TestKMMixIn): ...@@ -868,8 +864,8 @@ class TestKM(TestKMMixIn):
person = portal.person_module.newContent(portal_type='Person') person = portal.person_module.newContent(portal_type='Person')
assignment = person.newContent(portal_type= 'Assignment', assignment = person.newContent(portal_type= 'Assignment',
destination_project = project.getRelativeUrl()) destination_project = project.getRelativeUrl())
another_assignment = person.newContent(portal_type= 'Assignment', person.newContent(portal_type= 'Assignment',
destination_project = another_project.getRelativeUrl()) destination_project = another_project.getRelativeUrl())
assignment.open() assignment.open()
self.tic() self.tic()
...@@ -941,7 +937,6 @@ class TestKMSearch(TestKMMixIn): ...@@ -941,7 +937,6 @@ class TestKMSearch(TestKMMixIn):
See http://www.erp5.org/HowToUseSphinxSE See http://www.erp5.org/HowToUseSphinxSE
""" """
self.setupSphinx() self.setupSphinx()
portal = self.portal
website = self.portal.web_site_module.km_test_web_site website = self.portal.web_site_module.km_test_web_site
self.changeSkin('KM') self.changeSkin('KM')
# in search mode we do NOT access a ZODB object # in search mode we do NOT access a ZODB object
...@@ -1006,54 +1001,46 @@ class TestKMSearch(TestKMMixIn): ...@@ -1006,54 +1001,46 @@ class TestKMSearch(TestKMMixIn):
self.setupSphinx() self.setupSphinx()
self.changeSkin('KM') self.changeSkin('KM')
portal = self.portal
website = self.portal.web_site_module.km_test_web_site
web_page = self.web_page
def sqlresult_to_document_list(result): def sqlresult_to_document_list(result):
return [i.getObject() for i in result] return [i.getObject() for i in result]
# create docs to be referenced:
# 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_ = makeFileUpload(filename)
document1 = 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_ = 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_ = 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, 001, en; "I use reference to look up TEST"
filename = 'REF-en-001.odt'
file = makeFileUpload(filename)
document4 = self.portal.portal_contributions.newContent(file=file)
# 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_ = 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 = 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 = 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 = makeFileUpload(filename)
document8 = self.portal.portal_contributions.newContent(file=file) #document8 = self.portal.portal_contributions.newContent(file=file)
self.tic() self.tic()
# the implicit predecessor will find documents by reference. # the implicit predecessor will find documents by reference.
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Test Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testKM</string> </value>
</item>
<item>
<key> <string>default_source_reference</string> </key>
<value> <string>Products.ERP5.tests.testKM</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testKM</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Test Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
test.erp5.testKM
\ No newline at end of file
erp5_full_text_mroonga_catalog
erp5_core_proxy_field_legacy
erp5_jquery
erp5_jquery_ui
erp5_ingestion_mysql_innodb_catalog
erp5_ingestion
erp5_pdm
erp5_simulation
erp5_trade
erp5_project
erp5_crm
\ No newline at end of file
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
import warnings import warnings
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5OOo.tests.testDms import makeFileUpload from erp5.component.test.testDms import makeFileUpload
from Products.ERP5Type import Utils from Products.ERP5Type import Utils
class TestERP5PDFMerge(ERP5TypeTestCase): class TestERP5PDFMerge(ERP5TypeTestCase):
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
############################################################################## ##############################################################################
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5OOo.tests.testDms import makeFileUpload from erp5.component.test.testDms import makeFileUpload
from time import time from time import time
class TestRunMyDoc(ERP5TypeTestCase): class TestRunMyDoc(ERP5TypeTestCase):
......
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