Commit cfb5bd73 authored by Jérome Perrin's avatar Jérome Perrin Committed by Arnaud Fontaine

tests: makeFileUpload: Use unittest addCleanup() to close files rather than tearDown().

This executes even if setup() encounters an error and the cleanup hook is added
when opening the file, not later on.

Also, unify makeFileUpload() and makeFilePath() to remove duplicated code.
Co-authored-by: Arnaud Fontaine's avatarArnaud Fontaine <arnaud.fontaine@nexedi.com>
parent da6274f6
...@@ -33,7 +33,6 @@ import textwrap ...@@ -33,7 +33,6 @@ import textwrap
from unittest import expectedFailure from unittest import expectedFailure
from Products.CMFCore.WorkflowCore import WorkflowException from Products.CMFCore.WorkflowCore import WorkflowException
from Products.ERP5Type.tests.utils import FileUpload
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5OOo.tests.testIngestion import FILENAME_REGULAR_EXPRESSION from Products.ERP5OOo.tests.testIngestion import FILENAME_REGULAR_EXPRESSION
from Products.ERP5OOo.tests.testIngestion import REFERENCE_REGULAR_EXPRESSION from Products.ERP5OOo.tests.testIngestion import REFERENCE_REGULAR_EXPRESSION
...@@ -46,14 +45,6 @@ from DateTime import DateTime ...@@ -46,14 +45,6 @@ from DateTime import DateTime
import Products.ERP5.tests import Products.ERP5.tests
def makeFilePath(name):
return os.path.join(os.path.dirname(Products.ERP5.tests.__file__),
'test_data', 'crm_emails', name)
def makeFileUpload(name):
path = makeFilePath(name)
return FileUpload(path, name)
clear_module_name_list = """ clear_module_name_list = """
campaign_module campaign_module
event_module event_module
...@@ -80,6 +71,11 @@ class BaseTestCRM(ERP5TypeTestCase): ...@@ -80,6 +71,11 @@ class BaseTestCRM(ERP5TypeTestCase):
self.tic() self.tic()
super(BaseTestCRM, self).beforeTearDown() super(BaseTestCRM, self).beforeTearDown()
def _getTestDataPath(self):
return os.path.join(os.path.dirname(Products.ERP5.tests.__file__),
'test_data',
'crm_emails')
class TestCRM(BaseTestCRM): class TestCRM(BaseTestCRM):
def getTitle(self): def getTitle(self):
return "CRM" return "CRM"
...@@ -709,14 +705,10 @@ class TestCRMMailIngestion(BaseTestCRM): ...@@ -709,14 +705,10 @@ class TestCRMMailIngestion(BaseTestCRM):
# make sure customers are available to catalog # make sure customers are available to catalog
self.tic() self.tic()
def _readTestData(self, filename):
"""read test data from data directory."""
return open(makeFilePath(filename)).read()
def _ingestMail(self, filename=None, data=None): def _ingestMail(self, filename=None, data=None):
"""ingest an email from the mail in data dir named `filename`""" """ingest an email from the mail in data dir named `filename`"""
if data is None: if data is None:
data=self._readTestData(filename) data = self.makeFileUpload(filename).read()
return self.portal.portal_contributions.newContent( return self.portal.portal_contributions.newContent(
container_path='event_module', container_path='event_module',
filename='postfix_mail.eml', filename='postfix_mail.eml',
...@@ -887,7 +879,9 @@ class TestCRMMailIngestion(BaseTestCRM): ...@@ -887,7 +879,9 @@ class TestCRMMailIngestion(BaseTestCRM):
return object_list[-1] return object_list[-1]
portal = self.portal portal = self.portal
message = message_from_string(self._readTestData('simple')) message_string = self.makeFileUpload('simple').read()
message = message_from_string(message_string)
message.replace_header('subject', 'Visit:Company A') message.replace_header('subject', 'Visit:Company A')
data = message.as_string() data = message.as_string()
self._ingestMail(data=data) self._ingestMail(data=data)
...@@ -895,7 +889,7 @@ class TestCRMMailIngestion(BaseTestCRM): ...@@ -895,7 +889,7 @@ class TestCRMMailIngestion(BaseTestCRM):
document = getLastCreatedEvent(portal.event_module) document = getLastCreatedEvent(portal.event_module)
self.assertEqual(document.getPortalType(), 'Visit') self.assertEqual(document.getPortalType(), 'Visit')
message = message_from_string(self._readTestData('simple')) message = message_from_string(message_string)
message.replace_header('subject', 'Fax:Company B') message.replace_header('subject', 'Fax:Company B')
data = message.as_string() data = message.as_string()
self._ingestMail(data=data) self._ingestMail(data=data)
...@@ -903,7 +897,7 @@ class TestCRMMailIngestion(BaseTestCRM): ...@@ -903,7 +897,7 @@ class TestCRMMailIngestion(BaseTestCRM):
document = getLastCreatedEvent(portal.event_module) document = getLastCreatedEvent(portal.event_module)
self.assertEqual(document.getPortalType(), 'Fax Message') self.assertEqual(document.getPortalType(), 'Fax Message')
message = message_from_string(self._readTestData('simple')) message = message_from_string(message_string)
message.replace_header('subject', 'TEST:Company B') message.replace_header('subject', 'TEST:Company B')
data = message.as_string() data = message.as_string()
self._ingestMail(data=data) self._ingestMail(data=data)
...@@ -911,7 +905,7 @@ class TestCRMMailIngestion(BaseTestCRM): ...@@ -911,7 +905,7 @@ class TestCRMMailIngestion(BaseTestCRM):
document = getLastCreatedEvent(portal.event_module) document = getLastCreatedEvent(portal.event_module)
self.assertEqual(document.getPortalType(), 'Mail Message') self.assertEqual(document.getPortalType(), 'Mail Message')
message = message_from_string(self._readTestData('simple')) message = message_from_string(message_string)
message.replace_header('subject', 'visit:Company A') message.replace_header('subject', 'visit:Company A')
data = message.as_string() data = message.as_string()
self._ingestMail(data=data) self._ingestMail(data=data)
...@@ -919,7 +913,7 @@ class TestCRMMailIngestion(BaseTestCRM): ...@@ -919,7 +913,7 @@ class TestCRMMailIngestion(BaseTestCRM):
document = getLastCreatedEvent(portal.event_module) document = getLastCreatedEvent(portal.event_module)
self.assertEqual(document.getPortalType(), 'Visit') self.assertEqual(document.getPortalType(), 'Visit')
message = message_from_string(self._readTestData('simple')) message = message_from_string(message_string)
message.replace_header('subject', 'phone:Company B') message.replace_header('subject', 'phone:Company B')
data = message.as_string() data = message.as_string()
self._ingestMail(data=data) self._ingestMail(data=data)
...@@ -927,7 +921,7 @@ class TestCRMMailIngestion(BaseTestCRM): ...@@ -927,7 +921,7 @@ class TestCRMMailIngestion(BaseTestCRM):
document = portal.event_module[portal.event_module.objectIds()[-1]] document = portal.event_module[portal.event_module.objectIds()[-1]]
self.assertEqual(document.getPortalType(), 'Phone Call') self.assertEqual(document.getPortalType(), 'Phone Call')
message = message_from_string(self._readTestData('simple')) message = message_from_string(message_string)
message.replace_header('subject', 'LETTER:Company C') message.replace_header('subject', 'LETTER:Company C')
data = message.as_string() data = message.as_string()
self._ingestMail(data=data) self._ingestMail(data=data)
...@@ -935,7 +929,7 @@ class TestCRMMailIngestion(BaseTestCRM): ...@@ -935,7 +929,7 @@ class TestCRMMailIngestion(BaseTestCRM):
document = getLastCreatedEvent(portal.event_module) document = getLastCreatedEvent(portal.event_module)
self.assertEqual(document.getPortalType(), 'Letter') self.assertEqual(document.getPortalType(), 'Letter')
message = message_from_string(self._readTestData('simple')) message = message_from_string(message_string)
body = message.get_payload() body = message.get_payload()
message.set_payload('Visit:%s' % body) message.set_payload('Visit:%s' % body)
data = message.as_string() data = message.as_string()
...@@ -944,7 +938,7 @@ class TestCRMMailIngestion(BaseTestCRM): ...@@ -944,7 +938,7 @@ class TestCRMMailIngestion(BaseTestCRM):
document = getLastCreatedEvent(portal.event_module) document = getLastCreatedEvent(portal.event_module)
self.assertEqual(document.getPortalType(), 'Visit') self.assertEqual(document.getPortalType(), 'Visit')
message = message_from_string(self._readTestData('simple')) message = message_from_string(message_string)
body = message.get_payload() body = message.get_payload()
message.set_payload('PHONE CALL:%s' % body) message.set_payload('PHONE CALL:%s' % body)
data = message.as_string() data = message.as_string()
...@@ -1279,7 +1273,7 @@ class TestCRMMailSend(BaseTestCRM): ...@@ -1279,7 +1273,7 @@ class TestCRMMailSend(BaseTestCRM):
# Add a document which will be attached. # Add a document which will be attached.
# pdf # pdf
filename = 'sample_attachment.pdf' filename = 'sample_attachment.pdf'
file_object = makeFileUpload(filename) file_object = self.makeFileUpload(filename)
document = self.portal.portal_contributions.newContent(file=file_object) document = self.portal.portal_contributions.newContent(file=file_object)
self.tic() self.tic()
...@@ -1326,7 +1320,7 @@ class TestCRMMailSend(BaseTestCRM): ...@@ -1326,7 +1320,7 @@ class TestCRMMailSend(BaseTestCRM):
""" """
# Add a document which will be attached. # Add a document which will be attached.
filename = 'sample_attachment.odt' filename = 'sample_attachment.odt'
file_object = makeFileUpload(filename) file_object = self.makeFileUpload(filename)
document = self.portal.portal_contributions.newContent(file=file_object) document = self.portal.portal_contributions.newContent(file=file_object)
self.tic() self.tic()
...@@ -1373,7 +1367,7 @@ class TestCRMMailSend(BaseTestCRM): ...@@ -1373,7 +1367,7 @@ class TestCRMMailSend(BaseTestCRM):
""" """
# Add a document which will be attached. # Add a document which will be attached.
filename = 'sample_attachment.zip' filename = 'sample_attachment.zip'
file_object = makeFileUpload(filename) file_object = self.makeFileUpload(filename)
document = self.portal.portal_contributions.newContent(file=file_object) document = self.portal.portal_contributions.newContent(file=file_object)
self.tic() self.tic()
...@@ -1418,7 +1412,7 @@ class TestCRMMailSend(BaseTestCRM): ...@@ -1418,7 +1412,7 @@ class TestCRMMailSend(BaseTestCRM):
""" """
# Add a document which will be attached. # Add a document which will be attached.
filename = 'sample_attachment.gif' filename = 'sample_attachment.gif'
file_object = makeFileUpload(filename) file_object = self.makeFileUpload(filename)
document = self.portal.portal_contributions.newContent(file=file_object) document = self.portal.portal_contributions.newContent(file=file_object)
self.tic() self.tic()
...@@ -1515,7 +1509,7 @@ class TestCRMMailSend(BaseTestCRM): ...@@ -1515,7 +1509,7 @@ class TestCRMMailSend(BaseTestCRM):
# Add a document which will be attached. # Add a document which will be attached.
# pdf # pdf
filename = 'sample_attachment.pdf' filename = 'sample_attachment.pdf'
file_object = makeFileUpload(filename) file_object = self.makeFileUpload(filename)
# Add a ticket # Add a ticket
ticket = self.portal.campaign_module.newContent(portal_type='Campaign', ticket = self.portal.campaign_module.newContent(portal_type='Campaign',
...@@ -1563,7 +1557,7 @@ class TestCRMMailSend(BaseTestCRM): ...@@ -1563,7 +1557,7 @@ class TestCRMMailSend(BaseTestCRM):
""" """
# Add a document which will be attached. # Add a document which will be attached.
filename = 'sample_attachment.zip' filename = 'sample_attachment.zip'
file_object = makeFileUpload(filename) file_object = self.makeFileUpload(filename)
# Add a ticket # Add a ticket
ticket = self.portal.campaign_module.newContent(portal_type='Campaign', ticket = self.portal.campaign_module.newContent(portal_type='Campaign',
...@@ -1612,7 +1606,7 @@ class TestCRMMailSend(BaseTestCRM): ...@@ -1612,7 +1606,7 @@ class TestCRMMailSend(BaseTestCRM):
""" """
# Add a document which will be attached. # Add a document which will be attached.
filename = 'sample_attachment.zip' filename = 'sample_attachment.zip'
file_object = makeFileUpload(filename) file_object = self.makeFileUpload(filename)
# Add a ticket # Add a ticket
ticket = self.portal.campaign_module.newContent(portal_type='Campaign', ticket = self.portal.campaign_module.newContent(portal_type='Campaign',
...@@ -1689,7 +1683,7 @@ class TestCRMMailSend(BaseTestCRM): ...@@ -1689,7 +1683,7 @@ class TestCRMMailSend(BaseTestCRM):
# Add a document on a person which will be attached. # Add a document on a person which will be attached.
def add_document(filename, container, portal_type): def add_document(filename, container, portal_type):
f = makeFileUpload(filename) f = self.makeFileUpload(filename)
document = container.newContent(portal_type=portal_type) document = container.newContent(portal_type=portal_type)
document.edit(file=f, reference=filename) document.edit(file=f, reference=filename)
return document return document
...@@ -1746,7 +1740,7 @@ class TestCRMMailSend(BaseTestCRM): ...@@ -1746,7 +1740,7 @@ class TestCRMMailSend(BaseTestCRM):
# Add a document on a person which will be attached. # Add a document on a person which will be attached.
def add_document(filename, container, portal_type): def add_document(filename, container, portal_type):
f = makeFileUpload(filename) f = self.makeFileUpload(filename)
document = container.newContent(portal_type=portal_type) document = container.newContent(portal_type=portal_type)
document.edit(file=f, reference=filename) document.edit(file=f, reference=filename)
return document return document
......
...@@ -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.
""" """
def getTitle(self): def getTitle(self):
...@@ -128,7 +127,7 @@ class TestERP5Discussion(ERP5TypeTestCase): ...@@ -128,7 +127,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]
...@@ -225,7 +224,7 @@ class TestERP5Discussion(ERP5TypeTestCase): ...@@ -225,7 +224,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",
......
...@@ -41,7 +41,7 @@ import transaction ...@@ -41,7 +41,7 @@ import transaction
from AccessControl import Unauthorized from AccessControl import Unauthorized
from Testing import ZopeTestCase from Testing import ZopeTestCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.utils import FileUpload, createZODBPythonScript from Products.ERP5Type.tests.utils import createZODBPythonScript
from Products.ERP5Type.Utils import bytes2str, str2bytes from Products.ERP5Type.Utils import bytes2str, str2bytes
from erp5.component.document.Document import ConversionError from erp5.component.document.Document import ConversionError
...@@ -67,17 +67,6 @@ Y5pFvE34AgSXzrOPljMwMCgKWeIPJZxG43fR2UfLIRbAbfJjcERTgz1ASE0PcGsIGE1GOsMK0APk ...@@ -67,17 +67,6 @@ Y5pFvE34AgSXzrOPljMwMCgKWeIPJZxG43fR2UfLIRbAbfJjcERTgz1ASE0PcGsIGE1GOsMK0APk
/6e3ek9E9ERmk2rQv49vGHgkcBotISHBQDbglkDTzjjaCKab0QBziJyFukqO6AAAAABJRU5ErkJg /6e3ek9E9ERmk2rQv49vGHgkcBotISHBQDbglkDTzjjaCKab0QBziJyFukqO6AAAAABJRU5ErkJg
gg==''') gg==''')
def makeFilePath(name):
from Products.ERP5 import tests
return os.path.join(tests.__path__[0], 'test_data', name)
def makeFileUpload(name, as_name=None):
if as_name is None:
as_name = name
path = makeFilePath(name)
return FileUpload(path, as_name)
def process_image(image, size=(40, 40)): def process_image(image, size=(40, 40)):
# open the images to compare, resize them, and convert to grayscale # open the images to compare, resize them, and convert to grayscale
# get the rgb values of the pixels in the image # get the rgb values of the pixels in the image
...@@ -151,6 +140,10 @@ class TestERP5WebWithDms(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -151,6 +140,10 @@ class TestERP5WebWithDms(ERP5TypeTestCase, ZopeTestCase.Functional):
self.clearModule(self.portal.web_site_module) self.clearModule(self.portal.web_site_module)
self.clearModule(self.portal.web_page_module) self.clearModule(self.portal.web_page_module)
def _getTestDataPath(self):
from Products.ERP5 import tests
return os.path.join(tests.__path__[0], 'test_data')
def setupWebSite(self, **kw): def setupWebSite(self, **kw):
""" """
Setup Web Site Setup Web Site
...@@ -472,7 +465,7 @@ class TestERP5WebWithDms(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -472,7 +465,7 @@ class TestERP5WebWithDms(ERP5TypeTestCase, ZopeTestCase.Functional):
self.assertEqual(modification_date, last_modified_header) self.assertEqual(modification_date, last_modified_header)
# Upload a presentation with 3 pages. # Upload a presentation with 3 pages.
upload_file = makeFileUpload('P-DMS-Presentation.3.Pages-001-en.odp') upload_file = self.makeFileUpload('P-DMS-Presentation.3.Pages-001-en.odp')
document = document_module.newContent(portal_type='Presentation', document = document_module.newContent(portal_type='Presentation',
file=upload_file) file=upload_file)
reference = 'P-DMS-Presentation.3.Pages' reference = 'P-DMS-Presentation.3.Pages'
...@@ -529,7 +522,7 @@ class TestERP5WebWithDms(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -529,7 +522,7 @@ class TestERP5WebWithDms(ERP5TypeTestCase, ZopeTestCase.Functional):
document_reference = 'NXD-Presentation' document_reference = 'NXD-Presentation'
document_module = portal.getDefaultModule(portal_type='Presentation') document_module = portal.getDefaultModule(portal_type='Presentation')
upload_file = makeFileUpload('P-DMS-Presentation.3.Pages-001-en.odp') upload_file = self.makeFileUpload('P-DMS-Presentation.3.Pages-001-en.odp')
document = document_module.newContent(portal_type='Presentation', document = document_module.newContent(portal_type='Presentation',
reference=document_reference, reference=document_reference,
file=upload_file) file=upload_file)
...@@ -537,7 +530,7 @@ class TestERP5WebWithDms(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -537,7 +530,7 @@ class TestERP5WebWithDms(ERP5TypeTestCase, ZopeTestCase.Functional):
image_reference = 'NXD-IMAGE' image_reference = 'NXD-IMAGE'
image_module = portal.getDefaultModule(portal_type='Image') image_module = portal.getDefaultModule(portal_type='Image')
upload_file = makeFileUpload('tiolive-ERP5.Freedom.TioLive.Logo-001-en.png') upload_file = self.makeFileUpload('tiolive-ERP5.Freedom.TioLive.Logo-001-en.png')
image = image_module.newContent(portal_type='Image', image = image_module.newContent(portal_type='Image',
file=upload_file, file=upload_file,
reference=image_reference) reference=image_reference)
...@@ -636,7 +629,7 @@ class TestERP5WebWithDms(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -636,7 +629,7 @@ class TestERP5WebWithDms(ERP5TypeTestCase, ZopeTestCase.Functional):
self.assertEqual(modification_date, last_modified_header) self.assertEqual(modification_date, last_modified_header)
# Upload a presentation with 3 pages. # Upload a presentation with 3 pages.
upload_file = makeFileUpload('P-DMS-Presentation.3.Pages-001-en.odp') upload_file = self.makeFileUpload('P-DMS-Presentation.3.Pages-001-en.odp')
document = document_module.newContent(portal_type='Presentation', document = document_module.newContent(portal_type='Presentation',
file=upload_file) file=upload_file)
reference = 'P-DMS-Presentation-001-.3.Pages' reference = 'P-DMS-Presentation-001-.3.Pages'
...@@ -711,7 +704,7 @@ return True ...@@ -711,7 +704,7 @@ return True
website.newContent(portal_type=web_section_portal_type) website.newContent(portal_type=web_section_portal_type)
document_reference = 'tiolive-ERP5.Freedom.TioLive' document_reference = 'tiolive-ERP5.Freedom.TioLive'
upload_file = makeFileUpload('tiolive-ERP5.Freedom.TioLive-001-en.odp') upload_file = self.makeFileUpload('tiolive-ERP5.Freedom.TioLive-001-en.odp')
document = self.portal.document_module.newContent( document = self.portal.document_module.newContent(
portal_type='Presentation', portal_type='Presentation',
reference=document_reference, reference=document_reference,
...@@ -809,7 +802,7 @@ return True ...@@ -809,7 +802,7 @@ return True
image_reference = 'NXD-IMAGE' image_reference = 'NXD-IMAGE'
module = portal.getDefaultModule(portal_type=image_portal_type) module = portal.getDefaultModule(portal_type=image_portal_type)
upload_file = makeFileUpload('tiolive-ERP5.Freedom.TioLive.Logo-001-en.png') upload_file = self.makeFileUpload('tiolive-ERP5.Freedom.TioLive.Logo-001-en.png')
image = module.newContent(portal_type=image_portal_type, image = module.newContent(portal_type=image_portal_type,
file=upload_file, file=upload_file,
reference=image_reference) reference=image_reference)
...@@ -879,7 +872,7 @@ return True ...@@ -879,7 +872,7 @@ return True
""" """
portal = self.portal portal = self.portal
module = portal.getDefaultModule(portal_type=portal_type) module = portal.getDefaultModule(portal_type=portal_type)
upload_file = makeFileUpload('%s.svg' % filename) upload_file = self.makeFileUpload('%s.svg' % filename)
image = module.newContent(portal_type=portal_type, image = module.newContent(portal_type=portal_type,
file=upload_file, file=upload_file,
reference="NXD-DOCUMENT") reference="NXD-DOCUMENT")
...@@ -888,7 +881,7 @@ return True ...@@ -888,7 +881,7 @@ return True
self.assertEqual(image.getContentType(), 'image/svg+xml') self.assertEqual(image.getContentType(), 'image/svg+xml')
mime, converted_data = image.convert("png") mime, converted_data = image.convert("png")
self.assertEqual(mime, 'image/png') self.assertEqual(mime, 'image/png')
expected_image = makeFileUpload('%s.png' % filename) expected_image = self.makeFileUpload('%s.png' % filename)
# Compare images and accept some minimal difference, # Compare images and accept some minimal difference,
difference_value = compare_image(StringIO(converted_data), expected_image) difference_value = compare_image(StringIO(converted_data), expected_image)
...@@ -903,7 +896,7 @@ return True ...@@ -903,7 +896,7 @@ return True
""" """
portal = self.portal portal = self.portal
module = portal.getDefaultModule(portal_type=portal_type) module = portal.getDefaultModule(portal_type=portal_type)
upload_file = makeFileUpload('user-TESTSVG-CASE-URL-TEMPLATE.svg') upload_file = self.makeFileUpload('user-TESTSVG-CASE-URL-TEMPLATE.svg')
svg_content = upload_file.read().replace("REPLACE_THE_URL_HERE", image_url) svg_content = upload_file.read().replace("REPLACE_THE_URL_HERE", image_url)
# Add image using data instead file this time as it is not the goal of # Add image using data instead file this time as it is not the goal of
...@@ -918,7 +911,7 @@ return True ...@@ -918,7 +911,7 @@ return True
self.assertEqual(image.getContentType(), 'image/svg+xml') self.assertEqual(image.getContentType(), 'image/svg+xml')
mime, converted_data = image.convert("png") mime, converted_data = image.convert("png")
self.assertEqual(mime, 'image/png') self.assertEqual(mime, 'image/png')
expected_image = makeFileUpload('user-TESTSVG-CASE-URL.png') expected_image = self.makeFileUpload('user-TESTSVG-CASE-URL.png')
# Compare images and accept some minimal difference, # Compare images and accept some minimal difference,
difference_value = compare_image(StringIO(converted_data), expected_image) difference_value = compare_image(StringIO(converted_data), expected_image)
...@@ -935,7 +928,7 @@ return True ...@@ -935,7 +928,7 @@ return True
This is not used by ERP5 in production, but this is way that This is not used by ERP5 in production, but this is way that
prooves that conversion from SVG to PNG can use external images. prooves that conversion from SVG to PNG can use external images.
""" """
image_url = "file://" + makeFilePath("user-TESTSVG-BACKGROUND-IMAGE.png") image_url = "file://" + self.makeFileUploadPath("user-TESTSVG-BACKGROUND-IMAGE.png")
self._testImageConversionFromSVGToPNG_url(image_url, portal_type) self._testImageConversionFromSVGToPNG_url(image_url, portal_type)
def _testImageConversionFromSVGToPNG_http_url(self, portal_type="Image"): def _testImageConversionFromSVGToPNG_http_url(self, portal_type="Image"):
...@@ -945,7 +938,7 @@ return True ...@@ -945,7 +938,7 @@ return True
""" """
portal = self.portal portal = self.portal
module = portal.getDefaultModule(portal_type=portal_type) module = portal.getDefaultModule(portal_type=portal_type)
upload_file = makeFileUpload('user-TESTSVG-BACKGROUND-IMAGE.png') upload_file = self.makeFileUpload('user-TESTSVG-BACKGROUND-IMAGE.png')
background_image = module.newContent(portal_type=portal_type, background_image = module.newContent(portal_type=portal_type,
file=upload_file, file=upload_file,
reference="NXD-BACKGROUND") reference="NXD-BACKGROUND")
...@@ -966,11 +959,11 @@ return True ...@@ -966,11 +959,11 @@ return True
""" """
portal = self.portal portal = self.portal
module = portal.getDefaultModule(portal_type=portal_type) module = portal.getDefaultModule(portal_type=portal_type)
upload_file = makeFileUpload('user-TESTSVG-CASE-URL-TEMPLATE.svg') upload_file = self.makeFileUpload('user-TESTSVG-CASE-URL-TEMPLATE.svg')
svg_content = upload_file.read().replace("REPLACE_THE_URL_HERE", svg_content = upload_file.read().replace("REPLACE_THE_URL_HERE",
"http://soidjsoidjqsoijdqsoidjqsdoijsqd.idjsijds/../user-XXX-XXX") "http://soidjsoidjqsoijdqsoidjqsdoijsqd.idjsijds/../user-XXX-XXX")
upload_file = makeFileUpload('user-TESTSVG-CASE-URL-TEMPLATE.svg') upload_file = self.makeFileUpload('user-TESTSVG-CASE-URL-TEMPLATE.svg')
svg2_content = upload_file.read().replace("REPLACE_THE_URL_HERE", svg2_content = upload_file.read().replace("REPLACE_THE_URL_HERE",
"https://www.erp5.com/usXXX-XXX") "https://www.erp5.com/usXXX-XXX")
......
...@@ -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()
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
import unittest import unittest
import os import os
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.utils import FileUpload
from unittest import expectedFailure from unittest import expectedFailure
import httplib import httplib
...@@ -40,20 +39,13 @@ from DateTime import DateTime ...@@ -40,20 +39,13 @@ from DateTime import DateTime
from lxml import etree from lxml import etree
def makeFilePath(name):
import Products.ERP5.tests
return os.path.join(os.path.dirname(Products.ERP5.tests.__file__),
'test_data', name)
def makeFileUpload(name, as_name=None):
if as_name is None:
as_name = name
path = makeFilePath(name)
return FileUpload(path, as_name)
class TestWebDavSupport(ERP5TypeTestCase): class TestWebDavSupport(ERP5TypeTestCase):
"""Test for WEBDAV access. """Test for WEBDAV access.
""" """
def _getTestDataPath(self):
import Products.ERP5.tests
return os.path.join(os.path.dirname(Products.ERP5.tests.__file__), 'test_data')
def getTitle(self): def getTitle(self):
return "Test WebDav Support" return "Test WebDav Support"
...@@ -90,7 +82,7 @@ class TestWebDavSupport(ERP5TypeTestCase): ...@@ -90,7 +82,7 @@ class TestWebDavSupport(ERP5TypeTestCase):
""" """
person = self.portal.person_module.newContent() person = self.portal.person_module.newContent()
self.tic() self.tic()
file_object = makeFileUpload('images/erp5_logo.png') file_object = self.makeFileUpload('images/erp5_logo.png')
response = self.publish(person.getPath() + '/erp5_logo.png', response = self.publish(person.getPath() + '/erp5_logo.png',
request_method='PUT', request_method='PUT',
stdin=file_object, stdin=file_object,
...@@ -109,7 +101,7 @@ class TestWebDavSupport(ERP5TypeTestCase): ...@@ -109,7 +101,7 @@ class TestWebDavSupport(ERP5TypeTestCase):
# Create a new document via FTP/DAV # Create a new document via FTP/DAV
path = self.portal.portal_contributions.getPath() path = self.portal.portal_contributions.getPath()
filename = 'P-DMS-Presentation.3.Pages-001-en.odp' filename = 'P-DMS-Presentation.3.Pages-001-en.odp'
file_object = makeFileUpload(filename) file_object = self.makeFileUpload(filename)
response = self.publish('%s/%s' % (path, filename), response = self.publish('%s/%s' % (path, filename),
request_method='PUT', request_method='PUT',
stdin=file_object, stdin=file_object,
...@@ -131,7 +123,7 @@ class TestWebDavSupport(ERP5TypeTestCase): ...@@ -131,7 +123,7 @@ class TestWebDavSupport(ERP5TypeTestCase):
# Create a new document via FTP/DAV # Create a new document via FTP/DAV
path = self.portal.portal_contributions.getPath() path = self.portal.portal_contributions.getPath()
filename = 'P-DMS-Presentation.3.Pages-001-en.odp' filename = 'P-DMS-Presentation.3.Pages-001-en.odp'
file_object = makeFileUpload(filename) file_object = self.makeFileUpload(filename)
response = self.publish('%s/%s' % (path, filename), response = self.publish('%s/%s' % (path, filename),
request_method='PUT', request_method='PUT',
stdin=file_object, stdin=file_object,
...@@ -202,7 +194,7 @@ class TestWebDavSupport(ERP5TypeTestCase): ...@@ -202,7 +194,7 @@ class TestWebDavSupport(ERP5TypeTestCase):
""" """
path = self.portal.portal_contributions.getPath() path = self.portal.portal_contributions.getPath()
filename = 'P-DMS-Presentation.3.Pages-001-en.odp' filename = 'P-DMS-Presentation.3.Pages-001-en.odp'
file_object = makeFileUpload(filename) file_object = self.makeFileUpload(filename)
response = self.publish('%s/%s' % (path, filename), response = self.publish('%s/%s' % (path, filename),
request_method='PUT', request_method='PUT',
stdin=file_object, stdin=file_object,
...@@ -229,7 +221,7 @@ class TestWebDavSupport(ERP5TypeTestCase): ...@@ -229,7 +221,7 @@ class TestWebDavSupport(ERP5TypeTestCase):
""" """
path = self.portal.portal_contributions.getPath() path = self.portal.portal_contributions.getPath()
filename = 'P-DMS-Presentation.3.Pages-001-en.odp' filename = 'P-DMS-Presentation.3.Pages-001-en.odp'
file_object = makeFileUpload(filename) file_object = self.makeFileUpload(filename)
response = self.publish('%s/%s' % (path, filename), response = self.publish('%s/%s' % (path, filename),
request_method='PUT', request_method='PUT',
stdin=file_object, stdin=file_object,
...@@ -267,7 +259,7 @@ class TestWebDavSupport(ERP5TypeTestCase): ...@@ -267,7 +259,7 @@ class TestWebDavSupport(ERP5TypeTestCase):
""" """
path = self.portal.portal_contributions.getPath() path = self.portal.portal_contributions.getPath()
filename = 'P-DMS-Presentation.3.Pages-001-en.odp' filename = 'P-DMS-Presentation.3.Pages-001-en.odp'
file_object = makeFileUpload(filename) file_object = self.makeFileUpload(filename)
response = self.publish('%s/%s' % (path, filename), response = self.publish('%s/%s' % (path, filename),
request_method='PUT', request_method='PUT',
stdin=file_object, stdin=file_object,
......
...@@ -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())
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
import unittest import unittest
from unittest import expectedFailure from unittest import expectedFailure
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."""
...@@ -998,38 +998,38 @@ class TestKMSearch(TestKMMixIn): ...@@ -998,38 +998,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
......
...@@ -3,16 +3,7 @@ import PIL.Image as PIL_Image ...@@ -3,16 +3,7 @@ import PIL.Image as PIL_Image
import os import os
import transaction import transaction
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.utils import FileUpload
class FileUpload(file):
"""Act as an uploaded file.
"""
__allow_access_to_unprotected_subobjects__ = 1
def __init__(self, path, name):
self.filename = name
file.__init__(self, path)
self.headers = {}
def makeFilePath(name): def makeFilePath(name):
# return os.path.join(os.path.dirname(__file__), 'tmp', name) # return os.path.join(os.path.dirname(__file__), 'tmp', name)
......
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
import transaction import transaction
from io import FileIO
import os import os
class FileUpload(FileIO):
"""Act as an uploaded file.
"""
__allow_access_to_unprotected_subobjects__ = 1
def __init__(self, path, name):
self.filename = name
super(FileUpload, self).__init__(path)
self.headers = {}
def makeFilePath(name):
#return os.path.join(os.path.dirname(__file__), 'tmp', name)
return name
def makeFileUpload(name, as_name=None):
if as_name is None:
as_name = name
path = makeFilePath(name)
return FileUpload(path, as_name)
class TestSafeImage(ERP5TypeTestCase): class TestSafeImage(ERP5TypeTestCase):
def afterSetUp(self): def afterSetUp(self):
portal = self.getPortalObject() portal = self.getPortalObject()
...@@ -45,7 +23,7 @@ class TestSafeImage(ERP5TypeTestCase): ...@@ -45,7 +23,7 @@ class TestSafeImage(ERP5TypeTestCase):
fd = os.open(path_image, os.O_CREAT | os.O_RDWR) fd = os.open(path_image, os.O_CREAT | os.O_RDWR)
os.write(fd,str(image.data)) os.write(fd,str(image.data))
os.close(fd) os.close(fd)
_image = makeFileUpload(path_image) _image = self.makeFileUpload(path_image)
image = self.image_module.newContent(portal_type='Image',title='testImage', image = self.image_module.newContent(portal_type='Image',title='testImage',
id='testImage',file=_image,filename='testImage') id='testImage',file=_image,filename='testImage')
return image return image
...@@ -57,7 +35,7 @@ class TestSafeImage(ERP5TypeTestCase): ...@@ -57,7 +35,7 @@ class TestSafeImage(ERP5TypeTestCase):
fd = os.open(path_image, os.O_CREAT | os.O_RDWR) fd = os.open(path_image, os.O_CREAT | os.O_RDWR)
os.write(fd,str(image.data)) os.write(fd,str(image.data))
os.close(fd) os.close(fd)
tile_image = makeFileUpload(path_image) tile_image = self.makeFileUpload(path_image)
tile = self.image_module.newContent(portal_type='Image Tile',title='testTile', tile = self.image_module.newContent(portal_type='Image Tile',title='testTile',
id='testTile',file=tile_image,filename='testTile') id='testTile',file=tile_image,filename='testTile')
return tile return tile
...@@ -69,7 +47,7 @@ class TestSafeImage(ERP5TypeTestCase): ...@@ -69,7 +47,7 @@ class TestSafeImage(ERP5TypeTestCase):
fd = os.open(path_image, os.O_CREAT | os.O_RDWR) fd = os.open(path_image, os.O_CREAT | os.O_RDWR)
os.write(fd,str(image.data)) os.write(fd,str(image.data))
os.close(fd) os.close(fd)
tile_image_transformed = makeFileUpload(path_image) tile_image_transformed = self.makeFileUpload(path_image)
tile_transformed = self.image_module.newContent(portal_type='Image Tile Transformed', tile_transformed = self.image_module.newContent(portal_type='Image Tile Transformed',
title='testTileTransformed',id='testTileTransformed', title='testTileTransformed',id='testTileTransformed',
file=tile_image_transformed,filename='testTileTransformed') file=tile_image_transformed,filename='testTileTransformed')
......
...@@ -35,22 +35,15 @@ import unittest ...@@ -35,22 +35,15 @@ import unittest
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from Products.ERP5Type.tests.runUnitTest import tests_home from Products.ERP5Type.tests.runUnitTest import tests_home
from Products.ERP5Type.tests.utils import FileUpload
from erp5.component.tool import SynchronizationTool from erp5.component.tool import SynchronizationTool
from erp5.component.test.testERP5SyncML import TestERP5SyncMLMixin from erp5.component.test.testERP5SyncML import TestERP5SyncMLMixin
from erp5.component.document import SyncMLSubscription from erp5.component.document import SyncMLSubscription
import Products.ERP5.tests
test_files = os.path.join(os.path.dirname(Products.ERP5.tests.__file__), 'test_data')
FILENAME_REGULAR_EXPRESSION = "(?P<reference>[A-Z]{3,10})-\ FILENAME_REGULAR_EXPRESSION = "(?P<reference>[A-Z]{3,10})-\
(?P<language>[a-z]{2})-(?P<version>[0-9]{3})" (?P<language>[a-z]{2})-(?P<version>[0-9]{3})"
REFERENCE_REGULAR_EXPRESSION = "(?P<reference>[A-Z]{3,10})(-\ REFERENCE_REGULAR_EXPRESSION = "(?P<reference>[A-Z]{3,10})(-\
(?P<language>[a-z]{2}))?(-(?P<version>[0-9]{3}))?" (?P<language>[a-z]{2}))?(-(?P<version>[0-9]{3}))?"
def makeFileUpload(name):
path = os.path.join(test_files, name)
return FileUpload(path, name)
class TestERP5DocumentSyncMLMixin(TestERP5SyncMLMixin): class TestERP5DocumentSyncMLMixin(TestERP5SyncMLMixin):
nb_objects = 10 nb_objects = 10
...@@ -63,13 +56,21 @@ class TestERP5DocumentSyncMLMixin(TestERP5SyncMLMixin): ...@@ -63,13 +56,21 @@ class TestERP5DocumentSyncMLMixin(TestERP5SyncMLMixin):
#for documents (encoding in unicode for utf-8) #for documents (encoding in unicode for utf-8)
#files #files
filename_text = 'TEST-en-002.txt' filename_text = 'TEST-en-002.txt'
size_filename_text = len(makeFileUpload(filename_text).read()) @property
def size_filename_text(self):
return len(self.makeFileUpload(self.filename_text).read())
filename_odt = 'TEST-en-002.odt' filename_odt = 'TEST-en-002.odt'
size_filename_odt = len(makeFileUpload(filename_odt).read()) @property
def size_filename_odt(self):
return len(self.makeFileUpload(self.filename_odt).read())
filename_ppt = 'TEST-en-002.ppt' filename_ppt = 'TEST-en-002.ppt'
size_filename_ppt = len(makeFileUpload(filename_ppt).read()) @property
def size_filename_ppt(self):
return len(self.makeFileUpload(self.filename_ppt).read())
filename_pdf = 'TEST-en-002.pdf' filename_pdf = 'TEST-en-002.pdf'
size_filename_pdf = len(makeFileUpload(filename_pdf).read()) @property
def size_filename_pdf(self):
return len(self.makeFileUpload(self.filename_pdf).read())
#properties #properties
reference1 = 'P-SYNCML.Text' reference1 = 'P-SYNCML.Text'
version1 = '001' version1 = '001'
...@@ -135,6 +136,9 @@ class TestERP5DocumentSyncMLMixin(TestERP5SyncMLMixin): ...@@ -135,6 +136,9 @@ class TestERP5DocumentSyncMLMixin(TestERP5SyncMLMixin):
self.clearDocumentModules() self.clearDocumentModules()
self.clearPublicationsAndSubscriptions() self.clearPublicationsAndSubscriptions()
def _getTestDataPath(self):
import Products.ERP5.tests
return os.path.join(os.path.dirname(Products.ERP5.tests.__file__), 'test_data')
def clearFiles(self): def clearFiles(self):
# reset files, because we do sync by files # reset files, because we do sync by files
...@@ -280,7 +284,7 @@ class TestERP5DocumentSyncMLMixin(TestERP5SyncMLMixin): ...@@ -280,7 +284,7 @@ class TestERP5DocumentSyncMLMixin(TestERP5SyncMLMixin):
kw = {'reference': self.reference1, 'Version': self.version1, kw = {'reference': self.reference1, 'Version': self.version1,
'Language': self.language1, 'Description': self.description1} 'Language': self.language1, 'Description': self.description1}
document_text.edit(**kw) document_text.edit(**kw)
file_ = makeFileUpload(self.filename_text) file_ = self.makeFileUpload(self.filename_text)
document_text.edit(file=file_) document_text.edit(file=file_)
self.tic() self.tic()
document_pdf = document_server.newContent(id=self.id2, document_pdf = document_server.newContent(id=self.id2,
...@@ -288,7 +292,7 @@ class TestERP5DocumentSyncMLMixin(TestERP5SyncMLMixin): ...@@ -288,7 +292,7 @@ class TestERP5DocumentSyncMLMixin(TestERP5SyncMLMixin):
kw = {'reference': self.reference2, 'Version': self.version2, kw = {'reference': self.reference2, 'Version': self.version2,
'Language': self.language2, 'Description': self.description2} 'Language': self.language2, 'Description': self.description2}
document_pdf.edit(**kw) document_pdf.edit(**kw)
file_ = makeFileUpload(self.filename_pdf) file_ = self.makeFileUpload(self.filename_pdf)
document_pdf.edit(file=file_) document_pdf.edit(file=file_)
self.tic() self.tic()
nb_document = len(document_server) nb_document = len(document_server)
...@@ -305,7 +309,7 @@ class TestERP5DocumentSyncMLMixin(TestERP5SyncMLMixin): ...@@ -305,7 +309,7 @@ class TestERP5DocumentSyncMLMixin(TestERP5SyncMLMixin):
kw = {'reference': reference, 'version': version, 'language': language} kw = {'reference': reference, 'version': version, 'language': language}
doc_text.edit(**kw) doc_text.edit(**kw)
if file_name is not None: if file_name is not None:
file_ = makeFileUpload(file_name) file_ = self.makeFileUpload(file_name)
doc_text.edit(file=file_) doc_text.edit(file=file_)
return doc_text return doc_text
...@@ -480,7 +484,7 @@ class TestERP5DocumentSyncML(TestERP5DocumentSyncMLMixin): ...@@ -480,7 +484,7 @@ class TestERP5DocumentSyncML(TestERP5DocumentSyncMLMixin):
# Then we do only modification on a client (the gid) of client => add a object # Then we do only modification on a client (the gid) of client => add a object
kw = {'reference':self.reference1,'version':self.version3} kw = {'reference':self.reference1,'version':self.version3}
document_c.edit(**kw) document_c.edit(**kw)
file_ = makeFileUpload(self.filename_odt) file_ = self.makeFileUpload(self.filename_odt)
document_c.edit(file=file_) document_c.edit(file=file_)
self.tic() self.tic()
self.synchronize(self.sub_id1) self.synchronize(self.sub_id1)
...@@ -591,14 +595,14 @@ class TestERP5DocumentSyncML(TestERP5DocumentSyncMLMixin): ...@@ -591,14 +595,14 @@ class TestERP5DocumentSyncML(TestERP5DocumentSyncMLMixin):
doc_s = document_server._getOb(id_text) doc_s = document_server._getOb(id_text)
kw = {'description':self.description1} kw = {'description':self.description1}
doc_s.edit(**kw) doc_s.edit(**kw)
file_ = makeFileUpload(self.filename_odt) file_ = self.makeFileUpload(self.filename_odt)
doc_s.edit(file=file_) doc_s.edit(file=file_)
# Side client modification gid of a odt document # Side client modification gid of a odt document
id_odt = str(self.ids[self.id_max_text+1]) id_odt = str(self.ids[self.id_max_text+1])
doc_c = document_client1._getOb(id_odt) doc_c = document_client1._getOb(id_odt)
kw = {'description':self.description3} kw = {'description':self.description3}
doc_c.edit(**kw) doc_c.edit(**kw)
file_ = makeFileUpload(self.filename_text) file_ = self.makeFileUpload(self.filename_text)
doc_c.edit(file=file_) doc_c.edit(file=file_)
self.tic() self.tic()
self.synchronize(self.sub_id1) self.synchronize(self.sub_id1)
...@@ -692,7 +696,7 @@ class TestERP5DocumentSyncML(TestERP5DocumentSyncMLMixin): ...@@ -692,7 +696,7 @@ class TestERP5DocumentSyncML(TestERP5DocumentSyncMLMixin):
document_s = document_server._getOb(self.id1) document_s = document_server._getOb(self.id1)
kw = {'description': self.description2, 'short_title': self.short_title2 } kw = {'description': self.description2, 'short_title': self.short_title2 }
document_s.edit(**kw) document_s.edit(**kw)
file_ = makeFileUpload(self.filename_ppt) file_ = self.makeFileUpload(self.filename_ppt)
document_s.edit(file=file_) document_s.edit(file=file_)
self.tic() self.tic()
...@@ -701,7 +705,7 @@ class TestERP5DocumentSyncML(TestERP5DocumentSyncMLMixin): ...@@ -701,7 +705,7 @@ class TestERP5DocumentSyncML(TestERP5DocumentSyncMLMixin):
document_c1 = document_client1._getOb(self.id1) document_c1 = document_client1._getOb(self.id1)
kw = {'description': self.description3, 'short_title': self.short_title3 } kw = {'description': self.description3, 'short_title': self.short_title3 }
document_c1.edit(**kw) document_c1.edit(**kw)
file_ = makeFileUpload(self.filename_odt) file_ = self.makeFileUpload(self.filename_odt)
document_c1.edit(file=file_) document_c1.edit(file=file_)
self.tic() self.tic()
...@@ -822,7 +826,7 @@ class TestERP5DocumentSyncML(TestERP5DocumentSyncMLMixin): ...@@ -822,7 +826,7 @@ class TestERP5DocumentSyncML(TestERP5DocumentSyncMLMixin):
self.assertXMLViewIsEqual(self.sub_id_from_server, document_s, document_c, force=1) self.assertXMLViewIsEqual(self.sub_id_from_server, document_s, document_c, force=1)
# Then we change things on both sides and we look if there # Then we change things on both sides and we look if there
# is synchronization from only one way # is synchronization from only one way
file_ = makeFileUpload(self.filename_odt) file_ = self.makeFileUpload(self.filename_odt)
document_c.edit(file=file_) document_c.edit(file=file_)
kw = {'short_title' : self.short_title2} kw = {'short_title' : self.short_title2}
......
This diff is collapsed.
This diff is collapsed.
...@@ -52,6 +52,7 @@ from Products.ERP5Type.tests.backportUnittest import SetupSiteError ...@@ -52,6 +52,7 @@ from Products.ERP5Type.tests.backportUnittest import SetupSiteError
from Products.ERP5Type.tests.utils import addUserToDeveloperRole from Products.ERP5Type.tests.utils import addUserToDeveloperRole
from Products.ERP5Type.tests.utils import parseListeningAddress from Products.ERP5Type.tests.utils import parseListeningAddress
from Products.ERP5Type.tests.utils import timeZoneContext from Products.ERP5Type.tests.utils import timeZoneContext
from Products.ERP5Type.tests.utils import FileUpload
# Quiet messages when installing business templates # Quiet messages when installing business templates
install_bt5_quiet = 0 install_bt5_quiet = 0
...@@ -928,6 +929,28 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase, functional.F ...@@ -928,6 +929,28 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase, functional.F
), ),
) )
def _getTestDataPath(self):
"""
Where the tests data resides, to be overriden in children classes. By
default returns the current directory.
"""
return ''
def makeFileUploadPath(self, filename):
return os.path.join(self._getTestDataPath(), filename)
def makeFileUpload(self, filename, as_filename=None, path=None):
"""
Upload the given `filename` as `as_filename
"""
if as_filename is None:
as_filename = filename
if path is None:
path = self._getTestDataPath()
file_upload = FileUpload(os.path.join(path, filename), as_filename)
self.addCleanup(file_upload.close)
return file_upload
class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin): class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin):
__original_ZMySQLDA_connect = None __original_ZMySQLDA_connect = None
......
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