Commit 3b9b7308 authored by Jérome Perrin's avatar Jérome Perrin

patches from Klaus Wölfel for portability:

  open files in correct binary or text mode
  use os.path join
  use __file__ instead of looking in instance/software home



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@16066 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d0b9094e
...@@ -96,13 +96,13 @@ class PDFTk: ...@@ -96,13 +96,13 @@ class PDFTk:
if hasattr(pdfFile, "read") : if hasattr(pdfFile, "read") :
pdfFile = pdfFile.read() pdfFile = pdfFile.read()
tmpPdfFile = open(pdfFormFileName, "w") tmpPdfFile = open(pdfFormFileName, "wb")
tmpPdfFile.write(pdfFile) tmpPdfFile.write(pdfFile)
tmpPdfFile.close() tmpPdfFile.close()
if hasattr(fdfFile, "read") : if hasattr(fdfFile, "read") :
fdfFile = fdfFile.read() fdfFile = fdfFile.read()
tmpFdfFile = open(fdfFormFileName, "w") tmpFdfFile = open(fdfFormFileName, "wb")
tmpFdfFile.write(fdfFile) tmpFdfFile.write(fdfFile)
tmpFdfFile.close() tmpFdfFile.close()
......
...@@ -41,7 +41,7 @@ class TestPDFForm(unittest.TestCase): ...@@ -41,7 +41,7 @@ class TestPDFForm(unittest.TestCase):
""" """
self.document = Document('doc_id') self.document = Document('doc_id')
pdf_file = open(os.path.join(os.path.dirname(__file__), pdf_file = open(os.path.join(os.path.dirname(__file__),
'data', 'test_1.pdf')) 'data', 'test_1.pdf'), 'rb')
self.pdf_form = PDFForm('test_pdf_form').__of__(self.document) self.pdf_form = PDFForm('test_pdf_form').__of__(self.document)
self.pdf_form.manage_upload(pdf_file) self.pdf_form.manage_upload(pdf_file)
......
...@@ -80,7 +80,7 @@ RUN_ALL_TEST = 1 ...@@ -80,7 +80,7 @@ RUN_ALL_TEST = 1
# Define the conversion server host # Define the conversion server host
conversion_server_host = ('127.0.0.1', 8008) conversion_server_host = ('127.0.0.1', 8008)
TEST_FILES_HOME = os.path.join(os.getenv('INSTANCE_HOME'), 'Products', 'ERP5OOo', 'tests', 'test_document') TEST_FILES_HOME = os.path.join(os.path.dirname(__file__), 'test_document')
FILE_NAME_REGULAR_EXPRESSION = "(?P<reference>[A-Z]{3,6})-(?P<language>[a-z]{2})-(?P<version>[0-9]{3})" FILE_NAME_REGULAR_EXPRESSION = "(?P<reference>[A-Z]{3,6})-(?P<language>[a-z]{2})-(?P<version>[0-9]{3})"
REFERENCE_REGULAR_EXPRESSION = "(?P<reference>[A-Z]{3,6})(-(?P<language>[a-z]{2}))?(-(?P<version>[0-9]{3}))?" REFERENCE_REGULAR_EXPRESSION = "(?P<reference>[A-Z]{3,6})(-(?P<language>[a-z]{2}))?(-(?P<version>[0-9]{3}))?"
...@@ -193,7 +193,7 @@ class TestDocument(ERP5TypeTestCase): ...@@ -193,7 +193,7 @@ class TestDocument(ERP5TypeTestCase):
dm=self.getPortal().document_module dm=self.getPortal().document_module
doctext=dm.newContent(portal_type=portal_type) doctext=dm.newContent(portal_type=portal_type)
if file_name is not None: if file_name is not None:
f = open(makeFilePath(file_name)) f = open(makeFilePath(file_name), 'rb')
doctext.setTextContent(f.read()) doctext.setTextContent(f.read())
f.close() f.close()
doctext.setReference(reference) doctext.setReference(reference)
......
...@@ -51,7 +51,7 @@ os.environ['EVENT_LOG_SEVERITY'] = '-300' ...@@ -51,7 +51,7 @@ os.environ['EVENT_LOG_SEVERITY'] = '-300'
conversion_server_host = ('127.0.0.1', 8008) conversion_server_host = ('127.0.0.1', 8008)
# test files' home # test files' home
TEST_FILES_HOME = os.path.join(os.getenv('INSTANCE_HOME'), 'Products', 'ERP5OOo', 'tests', 'test_document') TEST_FILES_HOME = os.path.join(os.path.dirname(__file__), 'test_document')
FILE_NAME_REGULAR_EXPRESSION = "(?P<reference>[A-Z]{3,6})-(?P<language>[a-z]{2})-(?P<version>[0-9]{3})" FILE_NAME_REGULAR_EXPRESSION = "(?P<reference>[A-Z]{3,6})-(?P<language>[a-z]{2})-(?P<version>[0-9]{3})"
REFERENCE_REGULAR_EXPRESSION = "(?P<reference>[A-Z]{3,6})(-(?P<language>[a-z]{2}))?(-(?P<version>[0-9]{3}))?" REFERENCE_REGULAR_EXPRESSION = "(?P<reference>[A-Z]{3,6})(-(?P<language>[a-z]{2}))?(-(?P<version>[0-9]{3}))?"
...@@ -71,7 +71,7 @@ class FileUploadTest(file): ...@@ -71,7 +71,7 @@ class FileUploadTest(file):
def __init__(self, path, name): def __init__(self, path, name):
self.filename = name self.filename = name
file.__init__(self, path) file.__init__(self, path, 'rb')
self.headers = {} self.headers = {}
def makeFilePath(name): def makeFilePath(name):
......
...@@ -60,20 +60,8 @@ class TestOoodResponse(ERP5TypeTestCase): ...@@ -60,20 +60,8 @@ class TestOoodResponse(ERP5TypeTestCase):
self.login() self.login()
portal_skins = self.getSkinsTool() portal_skins = self.getSkinsTool()
portal_skins.custom.REQUEST.RESPONSE.setHeader('content-type', 'text/html') portal_skins.custom.REQUEST.RESPONSE.setHeader('content-type', 'text/html')
try: import_file_path = os.path.join(os.path.dirname(__file__), 'PersonSpreadsheetStylesheet')
import_file_path = os.path.join(getConfiguration().instancehome, import_file = open(import_file_path, 'rb')
'Products',
'ERP5OOo',
'tests',
'PersonSpreadsheetStylesheet' )
except IOError:
import_file_path = os.path.join(getConfiguration().softwarehome,
'Products',
'ERP5OOo',
'tests',
'PersonSpreadsheetStylesheet')
import_file = open(import_file_path)
addStyleSheet = portal_skins.custom.manage_addProduct['OFSP'].manage_addFile addStyleSheet = portal_skins.custom.manage_addProduct['OFSP'].manage_addFile
addStyleSheet(id='Base_getODTStyleSheet', file=import_file, title='', precondition='', content_type='application/vnd.oasis.opendocument.text') addStyleSheet(id='Base_getODTStyleSheet', file=import_file, title='', precondition='', content_type='application/vnd.oasis.opendocument.text')
addOOoTemplate = portal_skins.custom.manage_addProduct['ERP5OOo'].addOOoTemplate addOOoTemplate = portal_skins.custom.manage_addProduct['ERP5OOo'].addOOoTemplate
......
...@@ -81,11 +81,11 @@ class FileUploadTest(file): ...@@ -81,11 +81,11 @@ class FileUploadTest(file):
def __init__(self, path, name): def __init__(self, path, name):
self.filename = name self.filename = name
file.__init__(self, path) file.__init__(self, path, 'rb')
self.headers = {} self.headers = {}
def makeFilePath(name): def makeFilePath(name):
return os.getenv('INSTANCE_HOME') + '/../Products/ERP5OOo/tests/test_document/' + name return os.path.join(os.path.dirname(__file__), 'test_document', name)
def makeFileUpload(name): def makeFileUpload(name):
path = makeFilePath(name) path = makeFilePath(name)
......
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