Commit 3942ddcf authored by Hugo H. Maia Vieira's avatar Hugo H. Maia Vieira

Add getImage for OOGranulate


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@41116 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3efb4935
1.0.10 (unreleased) 1.0.10 (unreleased)
=================== ===================
- Add getImage for OOGranulate
- Add getImageItemList for OOGranulate - Add getImageItemList for OOGranulate
- Add OdfDocument - Add OdfDocument
- Add granulate interface. - Add granulate interface.
......
...@@ -92,9 +92,10 @@ class OOGranulate(object): ...@@ -92,9 +92,10 @@ class OOGranulate(object):
image_list.append((id, title)) image_list.append((id, title))
return image_list return image_list
def getImage(self, file, image_id, format=None, resolution=None, **kw): def getImage(self, id, format=None, resolution=None, **kw):
"""Return the given image.""" """Return the given image."""
raise NotImplementedError path = 'Pictures/%s' % id
return self.document.getFile(path)
def getParagraphItemList(self, file): def getParagraphItemList(self, file):
"""Returns the list of paragraphs in the form of (id, class) where class """Returns the list of paragraphs in the form of (id, class) where class
......
...@@ -48,7 +48,7 @@ class IImageGranulator(Interface): ...@@ -48,7 +48,7 @@ class IImageGranulator(Interface):
def getImageItemList(): def getImageItemList():
"""Return the list of images in the form of (id, title).""" """Return the list of images in the form of (id, title)."""
def getImage(image_id, format=None, resolution=None, **kw): def getImage(id, format=None, resolution=None, **kw):
"""Return the given image.""" """Return the given image."""
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
############################################################################## ##############################################################################
import unittest import unittest
from zipfile import ZipFile
from StringIO import StringIO
from cloudoooTestCase import cloudoooTestCase, make_suite from cloudoooTestCase import cloudoooTestCase, make_suite
from cloudooo.granulate.oogranulate import OOGranulate from cloudooo.granulate.oogranulate import OOGranulate
...@@ -47,6 +49,7 @@ class TestOOGranulate(cloudoooTestCase): ...@@ -47,6 +49,7 @@ class TestOOGranulate(cloudoooTestCase):
self.assertTrue(element.tag.endswith('image')) self.assertTrue(element.tag.endswith('image'))
def testHasAncertor(self): def testHasAncertor(self):
"""_hasAncestor() should vefify if the elements has the ancestor or not"""
image_list = self.oogranulate._getElementsByTagName( image_list = self.oogranulate._getElementsByTagName(
self.oogranulate.document.parsed_content, self.oogranulate.document.parsed_content,
'draw:image') 'draw:image')
...@@ -55,6 +58,7 @@ class TestOOGranulate(cloudoooTestCase): ...@@ -55,6 +58,7 @@ class TestOOGranulate(cloudoooTestCase):
self.assertTrue(self.oogranulate._hasAncestor(image_list[2], 'text-box')) self.assertTrue(self.oogranulate._hasAncestor(image_list[2], 'text-box'))
def testGetImageTitle(self): def testGetImageTitle(self):
"""_hasAncestor() should vefify if the elements has the ancestor or not"""
image_list = self.oogranulate._getElementsByTagName( image_list = self.oogranulate._getElementsByTagName(
self.oogranulate.document.parsed_content, self.oogranulate.document.parsed_content,
'draw:image') 'draw:image')
...@@ -92,13 +96,19 @@ class TestOOGranulate(cloudoooTestCase): ...@@ -92,13 +96,19 @@ class TestOOGranulate(cloudoooTestCase):
'Illustration 2: Again TioLive Logo'), 'Illustration 2: Again TioLive Logo'),
], image_list) ], image_list)
def testGetImage(self): def testGetImageSuccessfully(self):
"""Test if getImage() returns the right image file""" """Test if getImage() returns the right image file successfully"""
self.assertRaises(NotImplementedError, self.oogranulate.getImage, data = open('./data/granulate_test.odt').read()
'file', zip = ZipFile(StringIO(data))
'image_id', image_id = '10000000000000C80000009C38276C51.jpg'
'format', original_image = zip.read('Pictures/%s' % image_id)
'resolution') geted_image = self.oogranulate.getImage(image_id)
self.assertEquals(original_image, geted_image)
def testGetImageWithoutSuccess(self):
"""Test if getImage() returns an empty string for not existent id"""
geted_image = self.oogranulate.getImage('anything.png')
self.assertEquals('', geted_image)
def testGetParagraphItemList(self): def testGetParagraphItemList(self):
"""Test if getParagraphItemList() returns the right paragraphs list""" """Test if getParagraphItemList() returns the right paragraphs list"""
......
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