Commit 0bc2407f authored by Pere Cortes's avatar Pere Cortes Committed by Sebastien Robin

image_unit_test added and testSafeImage fixed

parent 8bc8ccc3
#from Products.ERP5.Document.Image import Image
#from Products.ERP5Type.tests.utils import FileUpload
import Image import Image
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
import transaction import transaction
...@@ -20,7 +18,8 @@ class FileUpload(file): ...@@ -20,7 +18,8 @@ class FileUpload(file):
def makeFilePath(name): def makeFilePath(name):
return os.path.join(os.path.dirname(__file__), 'tmp', name) #return os.path.join(os.path.dirname(__file__), 'tmp', name)
return name
def makeFileUpload(name, as_name=None): def makeFileUpload(name, as_name=None):
if as_name is None: if as_name is None:
...@@ -51,21 +50,36 @@ class TestSafeImage(ERP5TypeTestCase): ...@@ -51,21 +50,36 @@ class TestSafeImage(ERP5TypeTestCase):
def _createImage(self): def _createImage(self):
portal = self.getPortalObject() portal = self.getPortalObject()
_image = makeFileUpload('image_test.jpg') image = portal.restrictedTraverse('portal_skins/erp5_safeimage/img/image_unit_test.jpg')
path_image = "tmp/image_unit_test.jpg"
fd = os.open(path_image, os.O_CREAT | os.O_RDWR)
os.write(fd,str(image.data))
os.close(fd)
_image = makeFileUpload(path_image)
image = self.image_module.newContent(portal_type='Image',title='testImage', image = self.image_module.newContent(portal_type='Image',title='testImage',
id='testImage',file=_image,filename='testImage') id='testImage',file=_image,filename='testImage')
return image return image
def _createTileImage(self): def _createTileImage(self):
portal = self.getPortalObject() portal = self.getPortalObject()
tile_image = makeFileUpload('image_test.jpg') image = portal.restrictedTraverse('portal_skins/erp5_safeimage/img/image_unit_test.jpg')
path_image = "tmp/image_unit_test.jpg"
fd = os.open(path_image, os.O_CREAT | os.O_RDWR)
os.write(fd,str(image.data))
os.close(fd)
tile_image = makeFileUpload(path_image)
tile = self.image_module.newContent(portal_type='Image Tile',title='testTile', tile = self.image_module.newContent(portal_type='Image Tile',title='testTile',
id='testTile',file=tile_image,filename='testTile') id='testTile',file=tile_image,filename='testTile')
return tile return tile
def _createTileImageTransformed(self): def _createTileImageTransformed(self):
portal = self.getPortalObject() portal = self.getPortalObject()
tile_image_transformed = makeFileUpload('image_test.jpg') image = portal.restrictedTraverse('portal_skins/erp5_safeimage/img/image_unit_test.jpg')
path_image = "tmp/image_unit_test.jpg"
fd = os.open(path_image, os.O_CREAT | os.O_RDWR)
os.write(fd,str(image.data))
os.close(fd)
tile_image_transformed = makeFileUpload(path_image)
tile_transformed = self.image_module.newContent(portal_type='Image Tile Transformed', tile_transformed = self.image_module.newContent(portal_type='Image Tile Transformed',
title='testTileTransformed',id='testTileTransformed', title='testTileTransformed',id='testTileTransformed',
file=tile_image_transformed,filename='testTileTransformed') file=tile_image_transformed,filename='testTileTransformed')
...@@ -123,7 +137,7 @@ class TestSafeImage(ERP5TypeTestCase): ...@@ -123,7 +137,7 @@ class TestSafeImage(ERP5TypeTestCase):
self.assertNotEqual(tile_transformed,None) self.assertNotEqual(tile_transformed,None)
image_property = getattr(tile_transformed, "ImageProperties.xml", None) image_property = getattr(tile_transformed, "ImageProperties.xml", None)
self.assertEquals(image_property.getData(), self.assertEquals(image_property.getData(),
"""<IMAGE_PROPERTIES WIDTH="660" HEIGHT="495" NUMTILES="9" NUMIMAGES="1" VERSION="1.8" TILESIZE="256" />""") """<IMAGE_PROPERTIES WIDTH="660" HEIGHT="495" NUMTILES="52" NUMIMAGES="1" VERSION="1.8" TILESIZE="256" />""")
self.assertNotEqual(image_property, None) self.assertNotEqual(image_property, None)
self.assertEquals("Embedded File", image_property.getPortalType()) self.assertEquals("Embedded File", image_property.getPortalType())
image_transform = getattr(tile_transformed, "TransformFile.txt", None) image_transform = getattr(tile_transformed, "TransformFile.txt", None)
......
6 7
\ No newline at end of file \ No newline at end of file
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