Exemplo n.º 1
0
class TestOdfDocument(HandlerTestCase):

  def setUp(self):
    data = open('./data/granulate_test.odt').read()
    self.oodocument = OdfDocument(data, 'odt')

  def testReceivedGoodFile(self):
    """Test if received path is from a good document returing an ZipFile"""
    self.assertTrue(isinstance(self.oodocument._zipfile, ZipFile))

  def testGetContentXml(self):
    """Test if the getContentXml method returns the content.xml file"""
    content_xml = self.oodocument.getContentXml()
    self.assertTrue('The content of this file is just' in content_xml)

  def testGetExistentFile(self):
    """Test if the getFile method returns the requested file"""
    requested_file = self.oodocument.getFile('content.xml')
    self.assertEquals(requested_file, self.oodocument.getContentXml())

  def testGetNotPresentFile(self):
    """Test if the getFile method returns None for not present file request"""
    requested_file = self.oodocument.getFile('not_present.xml')
    self.assertEquals(requested_file, '')

  def testParseContent(self):
    """Test if the _parsed_content attribute is the parsed content.xml"""
    # XXX not sure it is good to store parsed document everytime
    self.assertTrue(isinstance(self.oodocument.parsed_content, etree._Element))
    self.assertTrue(self.oodocument.parsed_content.tag.endswith(
                    'document-content'))
Exemplo n.º 2
0
class TestOdfDocument(HandlerTestCase):
    def setUp(self):
        data = open('./data/granulate_test.odt').read()
        self.oodocument = OdfDocument(data, 'odt')

    def testReceivedGoodFile(self):
        """Test if received path is from a good document returing an ZipFile"""
        self.assertTrue(isinstance(self.oodocument._zipfile, ZipFile))

    def testGetContentXml(self):
        """Test if the getContentXml method returns the content.xml file"""
        content_xml = self.oodocument.getContentXml()
        self.assertTrue('The content of this file is just' in content_xml)

    def testGetExistentFile(self):
        """Test if the getFile method returns the requested file"""
        requested_file = self.oodocument.getFile('content.xml')
        self.assertEquals(requested_file, self.oodocument.getContentXml())

    def testGetNotPresentFile(self):
        """Test if the getFile method returns None for not present file request"""
        requested_file = self.oodocument.getFile('not_present.xml')
        self.assertEquals(requested_file, '')

    def testParseContent(self):
        """Test if the _parsed_content attribute is the parsed content.xml"""
        # XXX not sure it is good to store parsed document everytime
        self.assertTrue(
            isinstance(self.oodocument.parsed_content, etree._Element))
        self.assertTrue(
            self.oodocument.parsed_content.tag.endswith('document-content'))