Commit 625eb2cc authored by Jérome Perrin's avatar Jérome Perrin

data_notebook: fix testERP5ImageProcessor

use a valid image in testERP5ImageProcessor, this test evolved and
became a test for ERP5 behavior with broken images.

This indirectly solves a failure with testERP5ImageProcessor
and PYTHONHASHSEED: 805
parent bd4eebcf
...@@ -392,39 +392,37 @@ import sys ...@@ -392,39 +392,37 @@ import sys
Test the fucntioning of the ERP5ImageProcessor and the custom system Test the fucntioning of the ERP5ImageProcessor and the custom system
display hook too. display hook too.
""" """
self.image_module = self.portal.getDefaultModule('Image')
self.assertTrue(self.image_module is not None)
# Create a new ERP5 image object # Create a new ERP5 image object
reference = 'testBase_displayImageReference5' reference = 'testBase_displayImageReference5'
data_template = '<img src="data:application/unknown;base64,%s" /><br />' data_template = '<img src="data:image/png;base64,%s"'
data = 'qwertyuiopasdfghjklzxcvbnm<somerandomcharacterstosaveasimagedata>' data = bytes(self.portal.restrictedTraverse('images/erp5_logo.png').data)
if getattr(self.image_module, 'testBase_displayImageID5', None) is not None: img = self.portal.image_module.newContent(
self.image_module.manage_delObjects(ids=['testBase_displayImageID5'])
self.image_module.newContent(
portal_type='Image', portal_type='Image',
id='testBase_displayImageID5', id=self.id(),
reference=reference, reference=reference,
data=data, data=data,
filename='test.png' filename='test.png'
) )
def cleanup():
self.portal.image_module.manage_delObjects(ids=[img.getId()])
self.tic()
self.addCleanup(cleanup)
self.tic() self.tic()
# Call Base_displayImage from inside of Base_runJupyter # Call Base_displayImage from inside of Base_runJupyter
jupyter_code = """ jupyter_code = """
image = context.portal_catalog.getResultValue(portal_type='Image',reference='%s') image = context.portal_catalog.getResultValue(portal_type='Image',reference='%s')
context.Base_renderAsHtml(image) context.Base_renderAsHtml(image)
"""%reference """ % reference
notebook_context = {'setup' : {}, 'variables' : {}} notebook_context = {'setup': {}, 'variables': {}}
result = self.portal.Base_runJupyter( result = self.portal.Base_runJupyter(
jupyter_code=jupyter_code, jupyter_code=jupyter_code,
old_notebook_context=notebook_context old_notebook_context=notebook_context
) )
self.assertIn((data_template % base64.b64encode(data).decode()), result['result_string'])
self.assertIn((data_template % base64.b64encode(data)), result['result_string']) self.assertEqual(result['mime_type'], 'text/html')
# Mime_type shouldn't be image/png just because of filename, instead it is self.assertEqual(result['status'], 'ok')
# dependent on file and file data
self.assertNotEqual(result['mime_type'], 'image/png')
def testImportSameModuleDifferentNamespace(self): def testImportSameModuleDifferentNamespace(self):
""" """
...@@ -436,7 +434,7 @@ context.Base_renderAsHtml(image) ...@@ -436,7 +434,7 @@ context.Base_renderAsHtml(image)
# First we execute a jupyter_code which imports sys module as 'ss' namespace # First we execute a jupyter_code which imports sys module as 'ss' namespace
jupyter_code = "import sys as ss" jupyter_code = "import sys as ss"
reference = 'Test.Notebook.MutlipleImports %s' %time.time() reference = 'Test.Notebook.MutlipleImports %s' % time.time()
portal.Base_executeJupyter( portal.Base_executeJupyter(
reference=reference, reference=reference,
python_expression=jupyter_code python_expression=jupyter_code
......
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