Beispiel #1
0
    def test_odf_to_sqlite(self):
        sqlite = None
        try:
            from sqlite3 import dbapi2 as sqlite    # Python25
        except ImportError:
            from pysqlite2 import dbapi2 as sqlite  # Python24 and pysqlite
        except ImportError:
            print 'Warning: SQLite not available'
            return

        doc = odf.load(self.file)
        fd, name = tempfile.mkstemp()
        odf.dump(doc, name)

        f = os.fdopen(fd, 'rb')
        s = f.read()
        f.close()
        blob1 = sqlite.Binary(s)

        blob2 = odf.OdfToSqlite(name)

        os.remove(name)

        self.assertEqual(blob1, blob2, 'Previously encoded data is not equal to OdfToSqlite() data')

        con = sqlite.connect(':memory:')
        cur = con.cursor()
        cur.execute("CREATE TABLE odf(document BLOB)")

        cur.execute("INSERT INTO odf VALUES (?)",(blob1,))
        con.commit()
        cur.execute("SELECT document FROM odf")
        blob3 = cur.fetchone()[0]

        self.assertEqual(blob1, blob3, 'Stored SQLite data is not equal to previously encoded data')
Beispiel #2
0
 def test_replace(self):
     doc = odf.load(self.file)
     s = self._random_string()
     doc.replace(simple_text, s)
     text = doc.totext()
     self.assertFalse(simple_text in text)
     self.assertTrue(s in text)
Beispiel #3
0
    def test_images(self):
        doc = odf.load(self.file)

        self.assertEqual(len(doc.get_embedded()), 2)
        self.assertEqual(len(doc.get_embedded('1')), 2)
        self.assertEqual(len(doc.get_embedded('10*F.gif')), 1)
        self.assertEqual(len(doc.get_embedded('*?.gif')), 1)
        self.assertRaises(document.ReCompileError, doc.get_embedded, r'*\.png')
        self.assertEqual(len(doc.get_embedded(r'10.*D.*\.png')), 1)
Beispiel #4
0
 def test_dump(self):
     doc = odf.load(self.file)
     s1 = odf.dumps(doc)
     fd, name = tempfile.mkstemp()
     odf.dump(doc, name)
     f = os.fdopen(fd, 'rb')
     s2 = f.read()
     f.close()
     os.remove(name)
     self.assertEqual(s1, s2, 'File dump is not equal to string dumps')
Beispiel #5
0
    def test_sql_to_odf(self):
        doc = odf.load(self.file)
        s1 = odf.dumps(doc)
        s2 = odf.dumps(odf.SqlToOdf(s1))
        self.assertEqual(s1, s2, 'SqlToOdf data is not equal to previously dumped data')

        fd, name = tempfile.mkstemp()
        odf.SqlToOdf(s1, name)
        f = os.fdopen(fd, 'rb')
        s3 = f.read()
        f.close()
        self.assertEqual(s1, s3, 'SqlToOdf file dump is not equal to previously dumped data')
Beispiel #6
0
 def test_html(self):
     doc = odf.load(self.file)
     html = doc.tohtml()
     self.assertTrue(simple_html in html)
Beispiel #7
0
 def test_text(self):
     doc = odf.load(self.file)
     text = doc.totext()
     self.assertTrue(simple_text in text)
Beispiel #8
0
 def test_dumps(self):
     doc = odf.load(self.file)
     s = odf.dumps(doc)
     self.assertTrue(isinstance(odf.loads(s), document.Document))
Beispiel #9
0
 def test_load(self):
     self.assertTrue(isinstance(odf.load(self.file), document.Document))
Beispiel #10
0
 def test_html(self):
     doc = odf.load(self.file)
     html = doc.tohtml()
     self.assertTrue(formatted_html in html)
Beispiel #11
0
 def test_text(self):
     doc = odf.load(self.file)
     text = doc.totext()
     self.assertTrue(formatted_text in text)