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)
===================
- Add getImage for OOGranulate
- Add getImageItemList for OOGranulate
- Add OdfDocument
- Add granulate interface.
......
......@@ -92,9 +92,10 @@ class OOGranulate(object):
image_list.append((id, title))
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."""
raise NotImplementedError
path = 'Pictures/%s' % id
return self.document.getFile(path)
def getParagraphItemList(self, file):
"""Returns the list of paragraphs in the form of (id, class) where class
......
......@@ -48,7 +48,7 @@ class IImageGranulator(Interface):
def getImageItemList():
"""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."""
......
......@@ -27,6 +27,8 @@
##############################################################################
import unittest
from zipfile import ZipFile
from StringIO import StringIO
from cloudoooTestCase import cloudoooTestCase, make_suite
from cloudooo.granulate.oogranulate import OOGranulate
......@@ -47,6 +49,7 @@ class TestOOGranulate(cloudoooTestCase):
self.assertTrue(element.tag.endswith('image'))
def testHasAncertor(self):
"""_hasAncestor() should vefify if the elements has the ancestor or not"""
image_list = self.oogranulate._getElementsByTagName(
self.oogranulate.document.parsed_content,
'draw:image')
......@@ -55,6 +58,7 @@ class TestOOGranulate(cloudoooTestCase):
self.assertTrue(self.oogranulate._hasAncestor(image_list[2], 'text-box'))
def testGetImageTitle(self):
"""_hasAncestor() should vefify if the elements has the ancestor or not"""
image_list = self.oogranulate._getElementsByTagName(
self.oogranulate.document.parsed_content,
'draw:image')
......@@ -92,13 +96,19 @@ class TestOOGranulate(cloudoooTestCase):
'Illustration 2: Again TioLive Logo'),
], image_list)
def testGetImage(self):
"""Test if getImage() returns the right image file"""
self.assertRaises(NotImplementedError, self.oogranulate.getImage,
'file',
'image_id',
'format',
'resolution')
def testGetImageSuccessfully(self):
"""Test if getImage() returns the right image file successfully"""
data = open('./data/granulate_test.odt').read()
zip = ZipFile(StringIO(data))
image_id = '10000000000000C80000009C38276C51.jpg'
original_image = zip.read('Pictures/%s' % image_id)
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):
"""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