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

core: make sure base_data is bytes or Pdata

This was working fine (although not python3 ready), but was not tested
parent 10c68910
......@@ -72,6 +72,7 @@ from Products.ERP5Type import Permissions
from DateTime import DateTime
from ZTUtils import make_query
import PyPDF2
from OFS.Image import Pdata
QUIET = 0
......@@ -2560,6 +2561,24 @@ return 1
self.assertEqual(len(subject_result), 1)
self.assertEqual(subject_result[0].getPath(), document.getPath())
def test_base_convertable_uses_pdata_for_base_data(self):
document = self.portal.document_module.newContent(
portal_type='Spreadsheet',
file=makeFileUpload('import_big_spreadsheet.ods'))
self.tic()
# for large documents base_data is stored as Pdata
self.assertIsInstance(document.base_data, Pdata)
# the accessor unpacks to bytes
self.assertIsInstance(document.getBaseData(), bytes)
# for small documents, it's bytes directly
document = self.portal.document_module.newContent(
portal_type='Text',
file=makeFileUpload('TEST-en-002.odt'))
self.tic()
self.assertIsInstance(document.base_data, bytes)
self.assertIsInstance(document.getBaseData(), bytes)
def test_base_convertable_behaviour_with_successive_updates(self):
"""Check that update content's document (with setData and setFile)
will refresh base_data and content_md5 as expected.
......
......@@ -80,7 +80,7 @@ class BaseConvertableFileMixin:
security.declareProtected(Permissions.AccessContentsInformation,
'getBaseData')
def getBaseData(self, default=_MARKER):
"""Serialise Pdata into string
"""Serialise Pdata into bytes
"""
self._checkConversionFormatPermission(None)
if default is _MARKER:
......@@ -90,7 +90,7 @@ class BaseConvertableFileMixin:
if base_data is None:
return None
else:
return str(base_data)
return bytes(base_data)
security.declareProtected(Permissions.ModifyPortalContent, '_setBaseData')
def _setBaseData(self, data):
......
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