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

ERP5OOo: fix office:include_img on python3

We were applying str() to PData or bytes, resulting on broken image
inserted, something like "b'PNG'" instead of the expected "PNG"
parent 9c3a4c40
...@@ -363,7 +363,7 @@ class OOoTemplate(ZopePageTemplate): ...@@ -363,7 +363,7 @@ class OOoTemplate(ZopePageTemplate):
picture_type = picture.content_type() picture_type = picture.content_type()
else: else:
# "standard" filetype case (Image or File) # "standard" filetype case (Image or File)
picture_data = str(picture_data) picture_data = bytes(picture_data)
if picture_type is None: if picture_type is None:
picture_type = picture.getContentType() picture_type = picture.getContentType()
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
############################################################################## ##############################################################################
import os import os
import unittest
from io import BytesIO from io import BytesIO
from zipfile import ZipFile from zipfile import ZipFile
from Products.ERP5Type.tests.utils import FileUpload from Products.ERP5Type.tests.utils import FileUpload
...@@ -216,6 +215,7 @@ return getattr(context, "%s_%s" % (parameter, current_language)) ...@@ -216,6 +215,7 @@ return getattr(context, "%s_%s" % (parameter, current_language))
file_path = os.path.join(os.path.dirname(__file__), 'test_document', file_path = os.path.join(os.path.dirname(__file__), 'test_document',
filename) filename)
upload_file = FileUpload(file_path) upload_file = FileUpload(file_path)
self.addCleanup(upload_file.close)
document = self.portal.portal_contributions.newContent(file=upload_file) document = self.portal.portal_contributions.newContent(file=upload_file)
addOOoTemplate = self.getPortal().manage_addProduct['ERP5OOo'].addOOoTemplate addOOoTemplate = self.getPortal().manage_addProduct['ERP5OOo'].addOOoTemplate
addOOoTemplate(id='Base_viewIncludeImageAsOdt', title='') addOOoTemplate(id='Base_viewIncludeImageAsOdt', title='')
...@@ -239,17 +239,14 @@ return getattr(context, "%s_%s" % (parameter, current_language)) ...@@ -239,17 +239,14 @@ return getattr(context, "%s_%s" % (parameter, current_language))
cs = BytesIO() cs = BytesIO()
cs.write(body) cs.write(body)
zip_document = ZipFile(cs) zip_document = ZipFile(cs)
picture_list = filter(lambda x: "Pictures" in x.filename, picture_list = [x for x in zip_document.infolist() if "Pictures" in x.filename]
zip_document.infolist()) self.assertTrue(picture_list)
self.assertNotEqual([], picture_list)
manifest = bytes2str(zip_document.read('META-INF/manifest.xml')) manifest = bytes2str(zip_document.read('META-INF/manifest.xml'))
content = bytes2str(zip_document.read('content.xml')) content = bytes2str(zip_document.read('content.xml'))
for picture in picture_list: for picture in picture_list:
self.assertIn(picture.filename, manifest) self.assertIn(picture.filename, manifest)
self.assertIn(picture.filename, content) self.assertIn(picture.filename, content)
with open(file_path, 'rb') as f:
expected_data = f.read()
self.assertTrue([p for p in picture_list if zip_document.read(p) == expected_data])
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestOooDynamicStyle))
return suite
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