Commit bd9fdd99 authored by Hugo H. Maia Vieira's avatar Hugo H. Maia Vieira

Add parsed_content attribute to OdfDocument


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@41071 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d09ae813
...@@ -34,6 +34,7 @@ from zope.interface import implements ...@@ -34,6 +34,7 @@ from zope.interface import implements
from zipfile import ZipFile, is_zipfile from zipfile import ZipFile, is_zipfile
from shutil import rmtree from shutil import rmtree
from StringIO import StringIO from StringIO import StringIO
from lxml import etree
from interfaces.document import IDocument, IOdfDocument from interfaces.document import IDocument, IOdfDocument
...@@ -154,6 +155,8 @@ class OdfDocument(object): ...@@ -154,6 +155,8 @@ class OdfDocument(object):
""" """
self._zipfile = ZipFile(StringIO(data)) self._zipfile = ZipFile(StringIO(data))
self.source_format = source_format self.source_format = source_format
# XXX - I'm not confortable with this. Maybe it should be on OOGranulate
self.parsed_content = etree.fromstring(self.getContentXml())
def getContentXml(self): def getContentXml(self):
"""Returns the content.xml file as string""" """Returns the content.xml file as string"""
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
import unittest import unittest
from zipfile import ZipFile from zipfile import ZipFile
from lxml import etree
from cloudoooTestCase import cloudoooTestCase, make_suite from cloudoooTestCase import cloudoooTestCase, make_suite
from cloudooo.document import OdfDocument from cloudooo.document import OdfDocument
...@@ -39,12 +40,12 @@ class TestOdfDocument(cloudoooTestCase): ...@@ -39,12 +40,12 @@ class TestOdfDocument(cloudoooTestCase):
def testReceivedGoodFile(self): def testReceivedGoodFile(self):
"""Test if received path is from a good document returing an ZipFile""" """Test if received path is from a good document returing an ZipFile"""
self.assertEquals(isinstance(self.oodocument._zipfile, ZipFile), True) self.assertTrue(isinstance(self.oodocument._zipfile, ZipFile))
def testGetContentXml(self): def testGetContentXml(self):
"""Test if the getContentXml method returns the content.xml file""" """Test if the getContentXml method returns the content.xml file"""
content_xml = self.oodocument.getContentXml() content_xml = self.oodocument.getContentXml()
self.assertEquals('The content of this file is just' in content_xml, True) self.assertTrue('The content of this file is just' in content_xml)
def testGetExistentFile(self): def testGetExistentFile(self):
"""Test if the getFile method returns the requested file""" """Test if the getFile method returns the requested file"""
...@@ -56,6 +57,12 @@ class TestOdfDocument(cloudoooTestCase): ...@@ -56,6 +57,12 @@ class TestOdfDocument(cloudoooTestCase):
requested_file = self.oodocument.getFile('not_present.xml') requested_file = self.oodocument.getFile('not_present.xml')
self.assertEquals(requested_file, None) self.assertEquals(requested_file, None)
def testParseContent(self):
"""Test if the _parsed_content attribute is the parsed content.xml"""
self.assertTrue(isinstance(self.oodocument.parsed_content, etree._Element))
self.assertTrue(self.oodocument.parsed_content.tag.endswith(
'document-content'))
def test_suite(): def test_suite():
return make_suite(TestOdfDocument) return make_suite(TestOdfDocument)
......
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