Commit 1dc53f43 authored by Jérome Perrin's avatar Jérome Perrin

bt: fix export 2files

parent e1fd2d6d
...@@ -795,7 +795,10 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -795,7 +795,10 @@ class ObjectTemplateItem(BaseTemplateItem):
return mime.extensions[0] return mime.extensions[0]
for ext in mime.globs: for ext in mime.globs:
if ext[0] == "*" and ext.count(".") == 1: if ext[0] == "*" and ext.count(".") == 1:
return ext[2:].encode("utf-8") ext = ext[2:]
if six.PY2:
return ext.encode("utf-8")
return ext
# in case we could not read binary flag from mimetypes_registry then return # in case we could not read binary flag from mimetypes_registry then return
# '.bin' for all the Portal Types where exported_property_type is data # '.bin' for all the Portal Types where exported_property_type is data
......
...@@ -121,7 +121,7 @@ class TestBusinessTemplateTwoFileExport(ERP5TypeTestCase): ...@@ -121,7 +121,7 @@ class TestBusinessTemplateTwoFileExport(ERP5TypeTestCase):
pass pass
file_document_path = document_path + extension file_document_path = document_path + extension
self.assertEqual([os.path.basename(file_document_path)], self.assertEqual([os.path.basename(file_document_path)],
map(os.path.basename, exported)) list(map(os.path.basename, exported)))
with open(file_document_path, 'rb') as test_file: with open(file_document_path, 'rb') as test_file:
self.assertEqual(test_file.read(), data) self.assertEqual(test_file.read(), data)
else: else:
...@@ -129,7 +129,7 @@ class TestBusinessTemplateTwoFileExport(ERP5TypeTestCase): ...@@ -129,7 +129,7 @@ class TestBusinessTemplateTwoFileExport(ERP5TypeTestCase):
with open(xml_document_path, 'rb') as xml_file: with open(xml_document_path, 'rb') as xml_file:
xml_file_content = xml_file.read() xml_file_content = xml_file.read()
for exported_property in removed_property_list: for exported_property in removed_property_list:
self.assertNotIn('<string>'+exported_property+'</string>', self.assertNotIn(('<string>%s</string>' % exported_property).encode(),
xml_file_content) xml_file_content)
import_template = self._importBusinessTemplate() import_template = self._importBusinessTemplate()
...@@ -152,7 +152,7 @@ class TestBusinessTemplateTwoFileExport(ERP5TypeTestCase): ...@@ -152,7 +152,7 @@ class TestBusinessTemplateTwoFileExport(ERP5TypeTestCase):
import_template = self._exportAndReImport( import_template = self._exportAndReImport(
test_component_path, test_component_path,
".py", ".py",
test_component_kw["text_content"], test_component_kw["text_content"].encode(),
['text_content']) ['text_content'])
self.portal.portal_components.manage_delObjects([test_component_id]) self.portal.portal_components.manage_delObjects([test_component_id])
...@@ -242,7 +242,7 @@ class TestBusinessTemplateTwoFileExport(ERP5TypeTestCase): ...@@ -242,7 +242,7 @@ class TestBusinessTemplateTwoFileExport(ERP5TypeTestCase):
import_template = self._exportAndReImport( import_template = self._exportAndReImport(
python_script_path, python_script_path,
".py", ".py",
python_script_kw["_body"], python_script_kw["_body"].encode(),
['_body','_code']) ['_body','_code'])
skin_folder.manage_delObjects(python_script_id) skin_folder.manage_delObjects(python_script_id)
...@@ -315,7 +315,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -315,7 +315,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
""" """
self._checkTwoFileImportExportForImageInImageModule(dict( self._checkTwoFileImportExportForImageInImageModule(dict(
title = "foo", title = "foo",
data = "malformed data", data = b"malformed data",
portal_type = "Image", portal_type = "Image",
), '.bin') ), '.bin')
...@@ -332,7 +332,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -332,7 +332,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
file_id) file_id)
try: try:
args = file_document_kw['data'], ('data',) if extension else () args = file_document_kw['data'], (b'data',) if extension else ()
except KeyError: except KeyError:
args = None, ('data',) args = None, ('data',)
import_template = self._exportAndReImport( import_template = self._exportAndReImport(
...@@ -356,7 +356,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -356,7 +356,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
""" """
self._checkTwoFileImportExportForDocumentInDocumentModule(dict( self._checkTwoFileImportExportForDocumentInDocumentModule(dict(
title = "foo", title = "foo",
data = "a test file", data = b"a test file",
content_type = "text/javascript", content_type = "text/javascript",
portal_type = "File", portal_type = "File",
), '.js') ), '.js')
...@@ -454,7 +454,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -454,7 +454,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
where extension (.xml, exported as ._xml to avoid conflict with the meta-data file) where extension (.xml, exported as ._xml to avoid conflict with the meta-data file)
is identified by the title is identified by the title
""" """
file_content = """<person> file_content = b"""<person>
<name>John</name> <name>John</name>
<surname>Doe</surname> <surname>Doe</surname>
</person> </person>
...@@ -563,7 +563,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -563,7 +563,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
import_template = self._exportAndReImport( import_template = self._exportAndReImport(
method_document_path, method_document_path,
".sql", ".sql",
'dummy_method_template', b'dummy_method_template',
['src']) ['src'])
catalog.manage_delObjects([method_id]) catalog.manage_delObjects([method_id])
...@@ -611,7 +611,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -611,7 +611,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
import_template = self._exportAndReImport( import_template = self._exportAndReImport(
method_document_path, method_document_path,
".sql", ".sql",
'dummy_method_template', b'dummy_method_template',
['src']) ['src'])
catalog.manage_delObjects([method_id]) catalog.manage_delObjects([method_id])
...@@ -657,7 +657,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -657,7 +657,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
import_template = self._exportAndReImport( import_template = self._exportAndReImport(
method_document_path, method_document_path,
".sql", ".sql",
'dummy_method_template', b'dummy_method_template',
['src']) ['src'])
self.portal.portal_skins[skin_folder_id].manage_delObjects([method_id]) self.portal.portal_skins[skin_folder_id].manage_delObjects([method_id])
...@@ -696,7 +696,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -696,7 +696,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
import_template = self._exportAndReImport( import_template = self._exportAndReImport(
page_template_path, page_template_path,
".zpt", ".zpt",
page_template_kw['_text'], page_template_kw['_text'].encode(),
['_text']) ['_text'])
self.portal.portal_skins[skin_folder_id].manage_delObjects([page_template_id]) self.portal.portal_skins[skin_folder_id].manage_delObjects([page_template_id])
...@@ -747,7 +747,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -747,7 +747,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
import_template = self._exportAndReImport( import_template = self._exportAndReImport(
dtml_method_path, dtml_method_path,
".js", ".js",
dtml_method_kw['raw'], dtml_method_kw['raw'].encode(),
['raw']) ['raw'])
self.portal.portal_skins[skin_folder_id].manage_delObjects([dtml_method_id]) self.portal.portal_skins[skin_folder_id].manage_delObjects([dtml_method_id])
...@@ -798,7 +798,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -798,7 +798,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
import_template = self._exportAndReImport( import_template = self._exportAndReImport(
dtml_method_path, dtml_method_path,
".txt", ".txt",
dtml_method_kw['raw'], dtml_method_kw['raw'].encode(),
['raw']) ['raw'])
self.portal.portal_skins[skin_folder_id].manage_delObjects([dtml_method_id]) self.portal.portal_skins[skin_folder_id].manage_delObjects([dtml_method_id])
...@@ -862,7 +862,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -862,7 +862,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
""" """
self._checkTwoFileImportExportForDocumentInDocumentModule(dict( self._checkTwoFileImportExportForDocumentInDocumentModule(dict(
title = "foo", title = "foo",
data = "", # XXX a dummy string in data leads to 'NotConvertedError' data = b"", # XXX dummy data in data leads to 'NotConvertedError'
portal_type = "Spreadsheet", portal_type = "Spreadsheet",
), '.bin') ), '.bin')
...@@ -873,7 +873,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -873,7 +873,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
""" """
self._checkTwoFileImportExportForDocumentInDocumentModule(dict( self._checkTwoFileImportExportForDocumentInDocumentModule(dict(
title = "foo", title = "foo",
data = "", # XXX a dummy string in data leads to 'NotConvertedError' data = b"", # XXX dummy data in data leads to 'NotConvertedError'
content_type = "application/vnd.oasis.opendocument.spreadsheet", content_type = "application/vnd.oasis.opendocument.spreadsheet",
portal_type = "Spreadsheet", portal_type = "Spreadsheet",
), '.ods') ), '.ods')
...@@ -885,7 +885,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -885,7 +885,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
""" """
self._checkTwoFileImportExportForDocumentInDocumentModule(dict( self._checkTwoFileImportExportForDocumentInDocumentModule(dict(
title = "foo.xlsx", title = "foo.xlsx",
data = "", # XXX a dummy string in data leads to 'NotConvertedError' data = b"", # XXX dummy data in data leads to 'NotConvertedError'
portal_type = "Spreadsheet", portal_type = "Spreadsheet",
), '.xlsx') ), '.xlsx')
...@@ -910,7 +910,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -910,7 +910,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
import_template = self._exportAndReImport( import_template = self._exportAndReImport(
test_page_document_path, test_page_document_path,
".html", ".html",
test_page_data_kw["text_content"], test_page_data_kw["text_content"].encode(),
["text_content"]) ["text_content"])
self.portal.test_page_module.manage_delObjects([test_page_id]) self.portal.test_page_module.manage_delObjects([test_page_id])
...@@ -954,7 +954,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -954,7 +954,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
import_template = self._exportAndReImport( import_template = self._exportAndReImport(
python_script_path, python_script_path,
".py", ".py",
python_script_kw["_body"], python_script_kw["_body"].encode(),
['_body','_code']) ['_body','_code'])
self.portal.portal_skins[skin_folder_id].manage_delObjects([python_script_id]) self.portal.portal_skins[skin_folder_id].manage_delObjects([python_script_id])
......
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